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捐助),没钱捧个人场,谢谢各位。
谢谢您的赞助,我会做的更好!
相关推荐
- **验证签名、user_id及时间**:在绑定微信页面API中,验证请求的签名、user_id的有效性及时间是否过期,确保安全。张晓辉负责,预计工时为2.5小时。 - **调用微信API接口**:构建所需数据,包括appid、secrect,...
企业微信提供了`GET /cgi-bin/user/get`接口,通过access_token和openid可以获取到用户的详细信息,包括姓名、部门、职位等。后端可以调用这个接口,将获取到的用户信息返回给前端。 五、安全考虑 在处理用户信息时...
首先,`getPhoneNumber`是微信小程序提供的一种开放能力,它允许用户在授权的情况下获取其绑定在微信上的手机号。由于微信注重用户体验,调用此API必须由用户主动触发,例如通过点击特定按钮来完成。这个过程通常与...
4. 用户信息更新:当用户修改信息时,通过`wx.updateUser`接口更新微信小程序后台的用户信息。 四、页面跳转与事件处理 1. 页面跳转:`wx.navigateTo`、`wx.redirectTo`、`wx.switchTab`和`wx.navigateBack`等方法...
7. **数据库设计**:数据库设计是系统的核心部分,应包含用户表、菜品表、订单表、支付记录表等,每个表都有其特定的字段,如用户表可能包含用户ID、用户名、密码、微信openid等,菜品表包含菜品ID、名称、价格等。...
例如,用户表中可能包含用户ID、用户名、微信OpenID等字段,活动表则包括活动ID、发起人ID、活动标题、开始结束时间等。 4. **微信小程序开发** 微信小程序部分主要涉及WXML(结构层)、WXSS(样式层)和...
- 用户表(User):存储用户的基本信息,如用户名、密码、电话、微信OpenID等。 - 房产表(Property):记录小区内的房屋信息,关联用户和房屋的关系。 - 公告表(Notice):存储发布的通知公告内容,包括发布者、...
}获得微信用户的openId小程序前端会请求微信服务器得到一个code, 将code发送给自己的服务器,然后自己的服务器给微信服务器发送请求,得到微信用户的唯一标识openIdconst https = require('https'); const ...
5.小程序如果需要做多个小程序的打通,还需要在微信开放平台绑定到开发者账号下面, 如果不需要union_id请忽略 6.服务端准备一个用户授权的接口,假设接口链接为http://test.dev.com/user/authorization,此接口接受...
openid=微信openid access_token=微信access_token inv=邀请人ID markcode=机器码 系统会自动判读这个微信是否已经注册了账号 返回值: 104:机器码为空 106:该IP已注册 107:该机器码已注册 112:禁止登陆 ...
微信小程序云开发是一种集成在微信小程序中的云端能力,它提供了数据存储、云函数执行、文件存储等服务,帮助开发者在不搭建服务器的情况下也能构建完整的小程序应用。在本篇文章中,我们将详细介绍如何利用云开发...
在微信小程序开发中,获取用户绑定的手机号码是一项常见的需求,但这个过程涉及到用户授权、接口调用、数据加密解密等多个步骤。本文将详细解析这个流程,以便开发者能够快速理解并实现。 首先,前端部分的操作是...
- OAuth-微信 - OAuth-Facebook - OAuth-GitHub 4. **账号同步与更新**:当用户在一个平台上更新个人信息时,系统需要能够自动同步到其他关联的子账号上。这涉及到账号信息的实时同步以及数据的一致性问题。 5...
1. 微信登录授权:通过wx.login接口获取用户的OpenID,实现用户身份绑定。 2. 商品数据获取:利用微信小程序的网络请求API(如wx.request),从服务器端获取商品列表、详情等数据。 3. 数据缓存:使用wx....
1004:微信openid有误 1005:邀请人不存在 登入或注册成功后会返回:用户ID、用户账号、用户头像、用户名字、VIP、token 【刷新用户信息】:/api.php?action=getinfo POST提交:token 返回值: 150:token为空 151:...