微信 接入web openId 绑定user

简介:       package cn.hy.weixin.controller; import java.text.SimpleDateFormat; import java.util.

 

 

 

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捐助),没钱捧个人场,谢谢各位。



 
 
 谢谢您的赞助,我会做的更好!

 

 

目录
相关文章
|
6月前
|
移动开发 小程序
微信小程序web-view嵌入uni-app H5页面,通过H5页面跳转企业微信客户聊天窗口如何操作?
微信小程序web-view嵌入uni-app H5页面,通过H5页面跳转企业微信客户聊天窗口如何操作?
|
11月前
|
小程序 前端开发 JavaScript
微信小程序(二十一)小程序登录获取openid和unionid
在微信小程序中,因为各种各样的原因我们会需要获取到用户的openid或者unionid下面就简单来讲一下在小程序中如何获取openid和unionid。 步骤一:微信登录获取登录凭证
959 0
|
6月前
|
移动开发 小程序 JavaScript
Uniapp 中,能够同时兼容H5、web、app、微信小程序的引入高德地图的语法格式
Uniapp 中,能够同时兼容H5、web、app、微信小程序的引入高德地图的语法格式
628 0
|
前端开发 开发者 容器
Web站,前端接入钉钉扫码登录!
Web站,前端接入钉钉扫码登录!
|
1月前
|
JSON 小程序 应用服务中间件
微信的openid是用户的唯一id吗?
【10月更文挑战第4天】微信的openid是用户的唯一id吗?
426 5
|
4月前
|
API 网络架构 C++
SharePoint Online SPFx Web部件绑定数据
【7月更文挑战第6天】在Markdown格式下,以下是关于创建SharePoint Online SPFx Web部件绑定数据步骤的摘要: 1. 创建数据列表。 2. 使用VS Code打开Web部件。 3. 定义列表模型(如`IList`和`IListItem`接口)。 4. 引入`spHttpClient`以执行REST API请求。 5. 实现`_getListData()`方法,调用REST服务获取列表数据。 6. 设计`_renderList()`方法来渲染数据。 7. 在`render()`方法中获取并渲染数据到Web部件。
|
4月前
|
小程序 开发者
uniapp 获取微信的 openid(借助 uniCloud)
uniapp 获取微信的 openid(借助 uniCloud)
524 0
|
4月前
|
小程序 JavaScript
【微信小程序-原生开发】实用教程11 - 用户登录鉴权(含云函数的创建、删除、使用,通过云函数获取用户的openid)
【微信小程序-原生开发】实用教程11 - 用户登录鉴权(含云函数的创建、删除、使用,通过云函数获取用户的openid)
72 0
|
6月前
|
安全 小程序 Java
java实现微信服务(公众)号用户关注时,获取openid,安全模式下的加密解密实现
java实现微信服务(公众)号用户关注时,获取openid,安全模式下的加密解密实现
|
小程序 前端开发
uniapp+node.js(express框架)获取微信小程序的openid
uniapp+node.js(express框架)获取微信小程序的openid
213 0

热门文章

最新文章

下一篇
无影云桌面