欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

微信 接入web openId 绑定user

程序员文章站 2022-03-22 18:03:04
...

 

 

 

package cn.hy.weixin.controller;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.nutz.dao.pager.Pager;
import org.nutz.ioc.annotation.InjectName;
import org.nutz.ioc.loader.annotation.Inject;
import org.nutz.ioc.loader.annotation.IocBean;
import org.nutz.json.Json;
import org.nutz.log.Log;
import org.nutz.log.Logs;
import org.nutz.mvc.annotation.At;
import org.nutz.mvc.annotation.Attr;
import org.nutz.mvc.annotation.Ok;
import org.nutz.mvc.annotation.Param;

import cn.hy.activity.data.Activity;
import cn.hy.activity.data.ActivitySearch;
import cn.hy.activity.service.ActivityService;
import cn.hy.common.CommonResult;
import cn.hy.common.Consts;
import cn.hy.company.data.TCompany;
import cn.hy.company.service.TCompanyService;
import cn.hy.companyThing.CompanyThing;
import cn.hy.returnMoney.data.TUserActivityRel;
import cn.hy.returnMoney.service.TUserActivityRelService;
import cn.hy.ringHome.data.TRing;
import cn.hy.ringHome.service.RingHomeService;
import cn.hy.user.data.TUser;
import cn.hy.user.service.UserService;
import cn.hy.weixin.util.CommonUtil;
import javafx.scene.input.DataFormat;
 
@IocBean
@InjectName
@At("/wx")
public class WeichatController {
	private static final Log log = Logs.getLog(WeichatController.class);
	
	private UserService userService;
	private ActivityService activityService;
	private TCompanyService tCompanyService;
	private RingHomeService ringHomeService;
	private TUserActivityRelService tUserActivityRelService;
	@Inject("refer:userService")
	public void setUserService(UserService userService) {
		this.userService = userService;
	}
	@Inject("refer:activityService")
	public void setActivityService(ActivityService activityService) {
		this.activityService = activityService;
	}
	@Inject("refer:tCompanyService")
	public void settCompanyService(TCompanyService tCompanyService) {
		this.tCompanyService = tCompanyService;
	}
	@Inject("refer:ringHomeService")
	public void setRingHomeService(RingHomeService ringHomeService) {
		this.ringHomeService = ringHomeService;
	}
	@Inject("refer:tUserActivityRelService")
	public void settUserActivityRelService(TUserActivityRelService tUserActivityRelService) {
		this.tUserActivityRelService = tUserActivityRelService;
	}
	
	@At("/tdb")
	@Ok("jsp:weichatjsp.discount_bind")
	public void tdb(@Param("code") String code,@Param("openId") String openId, HttpServletRequest request) {
		log.debug("----toDiscountBind start----");
		if( null != openId && "" != openId ){
			
		}else{
			 openId = CommonUtil.getOpenId(code);
		}
		System.out.println("--------------" + openId);
		TUser tuser = userService.findTUserByOpenId(openId);
		int statucode =0;
		if(null != tuser  &&  null != tuser.getId()  && tuser.getId() >0  ){
			statucode =1;
		}
		System.out.println("statucode--------------" + statucode);
		request.setAttribute("statucode", statucode);
		request.setAttribute("openId", openId);
	}
	
	@At("/TobindBussinessJsp")
	public void singalbindBussiness(@Param("code") String code, HttpServletRequest request) {
		String openId = CommonUtil.getOpenId(code);
		System.out.println("--------------" + openId);
		TUser tuser = userService.findTUserByOpenId(openId);
		int isBindMobile =0; 
		if(null != tuser  &&  null != tuser.getId()  && tuser.getId() >0  ){
			isBindMobile =1; //已绑定手机,跳转到业务绑定
		}
		System.out.println("isBindMobile--------------" + isBindMobile);
		int isBindBusiness = 0;
		if(isBindMobile == 0) { //未绑定手机,跳转到手机
			System.out.println("未绑定手机,跳转到手机 --------------");
		} else if(isBindMobile == 1 && tuser.getMode() == null) {
			isBindBusiness = 1;
			toBusinessJsp(openId, isBindBusiness, request);
		}
		
	}
	
	@Ok("jsp:weichatjsp.discount_open")
	public void toBusinessJsp(String openId, int isBindBusiness, HttpServletRequest request) {
		System.out.println("here.....");
		request.setAttribute("isBindBusiness", isBindBusiness);
		request.setAttribute("openId", openId);
		
	}
	
	
	@At("/toActivitylist")
	@Ok("jsp:weichatjsp.list")
	public void toActivitylist(@Param("code") String code,HttpServletRequest request) { 
		String openId = CommonUtil.getOpenId(code);
		request.setAttribute("openId", openId);
	}
	
	
	@At("/activitylist")
	@Ok("raw")
	public String activitylist(@Param("..") Pager pager,HttpServletRequest request) {
		log.debug("----activitylist start----");
		 ActivitySearch as = new ActivitySearch();
		 return activityService.queryWxActivity(pager.getPageNumber(),Consts.wxPageSize,as);
	}
	
	@At("/detailActivity")
	@Ok("jsp:weichatjsp.activity_detail")
	public void detailActivity(@Param("openId") String openId,@Param("id") int id,HttpSession session,HttpServletRequest request){
		Activity activity = activityService.getActivityDetail(id);
		TCompany campany = tCompanyService.getCompany(activity.getCompId());
		TRing ring = ringHomeService.getRing(activity.getRingId());
		
		int flag = 0; // 未绑定用户  跳转绑定用户
		TUser tuser = userService.findTUserByOpenId(openId);
		if(null != tuser  &&  null != tuser.getId()  && tuser.getId() >0  ){ 
			if(tuser.getMode() == null){
				flag =1; // 已绑定 用户 ,为绑定 业务 
			}else{
				flag =2; // 绑定 用户 绑定业务
				TUserActivityRel tUserActivityRel = tUserActivityRelService.getTUserActivityRelById(activity.getId(),tuser.getId());
				if(tUserActivityRel !=null){
					flag =3;
				}
			}
		}
		
		request.setAttribute("flag", flag);
		request.setAttribute("openId", openId);
		request.setAttribute("activity", activity);
		request.setAttribute("campany",ring);
		request.setAttribute("ring",ring);
	}
	
	@At("/toBind")
	@Ok("jsp:weichatjsp.bind")
	public void bind(@Param("openId") String openId,@Param("id") int activityId,@Param("flag") int flag,HttpServletRequest request) { 
       log.info("-------------to bind ------------------");
       request.setAttribute("activityId",activityId);
       request.setAttribute("openId",openId);
       request.setAttribute("flag",flag);
	}

	 

	@At("/bindMobile")
	@Ok("json")
	public CommonResult bindMobile(@Param("mobile") String mobile, @Param("openId") String openId,HttpServletRequest request) { 
		List<TUser> list =  userService.findPhone(mobile);
		CommonResult cr = new CommonResult();
		int statucode =0;
		   TUser tuser = null;
		   try{
		   if(list != null && list.size() >0){
			   tuser = list.get(0);
			   tuser.setOpenId(openId);
			   userService.update(tuser);
			   statucode =1;
			   cr.setResultMsg("success");
		   }else{
			   tuser = new TUser();
			   tuser.setPhone(mobile);
			   tuser.setOpenId(openId);
			   userService.insertTUser(tuser);
			   statucode =1;
			   cr.setResultMsg("success");
		   }
		   }catch(Exception e){ 
			   cr.setResultMsg("error");
			   statucode =0;
		   }
		   cr.setResultCode(statucode);
		   return cr;
	}
	
	@At("/bindBussiness")
	@Ok("json")
	public CommonResult bindBussiness(@Param("openId") String openId ,@Param("openType") int  openType ,HttpServletRequest request) { 
		TUser tuser = userService.findTUserByOpenId(openId);
		CommonResult cr = new CommonResult();
		int statucode =0;
		try{  
			   tuser.setMode(openType);
			   userService.update(tuser);
			   statucode =1;
			   cr.setResultMsg("success");
		   }catch(Exception e){ 
			   cr.setResultMsg("error");
			   statucode =0;
		   }
		   cr.setResultCode(statucode);
		   return cr;
	}
	
	
	@At("/addOrder")
	@Ok("json")
	public CommonResult addOrder(@Param("openId") String openId,@Param("id") int id,HttpServletRequest request) { 
		CommonResult cr = new CommonResult();
		int statucode=0;
		try{
		Activity activity = activityService.getActivityDetail(id);  
		TUser tuser = userService.findTUserByOpenId(openId);
		TUserActivityRel  tUserActivityRel =  new TUserActivityRel();
		tUserActivityRel.setActivityId(activity.getId());
		tUserActivityRel.setUserId(tuser.getId());
		tUserActivityRel.setCompId(activity.getCompId());
		if(activity.getRebateWay() == 1)
			tUserActivityRel.setBill(Float.parseFloat(activity.getRebateMemo()));
		if(activity.getRebateWay() == 0)
		tUserActivityRel.setFlow(Integer.parseInt(activity.getRebateMemo()));
		tUserActivityRel.setOrderTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
		tUserActivityRel.setRebateTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(activity.getEndTime()));
		tUserActivityRel.setOrderState(0);
		tUserActivityRel.setOrderEndTime(new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(activity.getEndTime()));
		tUserActivityRelService.insert(tUserActivityRel);
		statucode =1;
		cr.setResultMsg(" insert success");
		}catch(Exception e){
			statucode =0;
			cr.setResultMsg("insert error");
		}
		cr.setResultCode(statucode);
		return cr;
	}
	
	
	

	@At("/activity")
	@Ok("jsp:weichatjsp.discount_bind")
	public void tdb( HttpServletRequest request) {
		System.out.println("activitylist--------------");
		
	}
	@At("/discountBind")
	@Ok("json")
	public CommonResult discountBind( @Param("mobile") String mobile , @Param("openId") String openId ,HttpServletRequest request) {
		System.out.println("mobile"+mobile+"openId" + openId);
		CommonResult cr = new CommonResult();
		int statucode =0;
	   if(mobile ==null || mobile =="" ){
		   statucode =0;
	   }
	   if(openId ==null || openId =="" ){
		   statucode =0;
	   } 
	   
	   List<TUser> list =  userService.findPhone(mobile);
	   TUser tuser = null;
	   try{
	   if(list != null && list.size() >0){
		   tuser = list.get(0);
		   tuser.setOpenId(openId);
		   userService.update(tuser);
		   statucode =1;
		   cr.setResultMsg("success");
	   }else{
		   tuser = new TUser();
		   tuser.setPhone(mobile);
		   tuser.setOpenId(openId);
		   userService.insertTUser(tuser);
		   cr.setResultMsg("success");
		   statucode =2;
	   }
	   }catch(Exception e){ 
		   cr.setResultMsg("error");
		   statucode =0;
	   }
	   cr.setResultCode(statucode);
	   return cr;
	}
	
	
	
}

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

捐助开发者

在兴趣的驱动下,写一个免费的东西,有欣喜,也还有汗水,希望你喜欢我的作品,同时也能支持一下。 当然,有钱捧个钱场(右上角的爱心标志,支持支付宝和PayPal捐助),没钱捧个人场,谢谢各位。


微信 接入web  openId 绑定user 
            
    
    博客分类: weichat 接入webopenId绑定user 微信 接入web  openId 绑定user 
            
    
    博客分类: weichat 接入webopenId绑定user 微信 接入web  openId 绑定user 
            
    
    博客分类: weichat 接入webopenId绑定user 
 
 
 谢谢您的赞助,我会做的更好!