| | |
| | | import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; |
| | | import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.panzhihua.applets.config.WxMaConfiguration; |
| | | import com.panzhihua.applets.model.vos.LoginRequest; |
| | | import com.panzhihua.common.model.vos.LoginReturnVO; |
| | | import com.panzhihua.common.model.vos.community.ComActVO; |
| | | import com.panzhihua.common.service.auth.TokenService; |
| | | import com.panzhihua.common.service.community.CommunityService; |
| | | import com.panzhihua.common.service.user.UserService; |
| | | import com.panzhihua.common.controller.BaseController; |
| | | import com.panzhihua.common.exceptions.UnAuthenticationException; |
| | |
| | | private WxMaConfiguration wxMaConfiguration; |
| | | @Resource |
| | | private TokenService tokenService; |
| | | @Resource |
| | | private CommunityService communityService; |
| | | |
| | | @ApiOperation(value = "登录" ,response =LoginReturnVO.class ) |
| | | @PostMapping("login") |
| | |
| | | sessionInfo=new WxMaJscode2SessionResult(); |
| | | sessionInfo.setOpenid("88888888"); |
| | | sessionInfo.setSessionKey("9999999"); |
| | | sessionInfo.setUnionid("44444444"); |
| | | } |
| | | log.info("微信登录成功【{}】", JSONObject.toJSONString(sessionInfo)); |
| | | String openid = sessionInfo.getOpenid(); |
| | | String sessionKey = sessionInfo.getSessionKey(); |
| | | String unionid = sessionInfo.getUnionid(); |
| | | if (ObjectUtils.isEmpty(unionid)) { |
| | | unionid="无"; |
| | | } |
| | | userService.addOrUpdate(openid,sessionKey,unionid); |
| | | R r = tokenService.loginApplets(openid); |
| | | return r; |
| | | return tokenService.loginApplets(openid); |
| | | } |
| | | |
| | | @ApiOperation(value = "维护用户基本信息(昵称、性别、头像)") |
| | |
| | | WxMaUserInfo wxUserInfo = maService.getUserService().getUserInfo(loginUserInfoVO.getSessionKey(), |
| | | encryptedData, iv); |
| | | if (null == wxUserInfo) { |
| | | throw new WeiXinException("微信解析基本信息失败"); |
| | | return R.fail("微信解析基本信息失败"); |
| | | } |
| | | String avatarUrl = wxUserInfo.getAvatarUrl(); |
| | | String gender = wxUserInfo.getGender(); |
| | | String nickName = wxUserInfo.getNickName(); |
| | | R r1=userService.updateUserWeiXinInfo(userId,nickName,Integer.parseInt(gender),avatarUrl); |
| | | return r1; |
| | | return userService.updateUserWeiXinInfo(userId,nickName,Integer.parseInt(gender),avatarUrl); |
| | | } |
| | | |
| | | @ApiOperation(value = "维护微信用户手机号") |
| | |
| | | } |
| | | WxMaService maService = wxMaConfiguration.getMaService(); |
| | | Long userId = this.getUserId(); |
| | | boolean empty2 = ObjectUtils.isEmpty(userId); |
| | | if (empty2) { |
| | | throw new UnAuthenticationException(); |
| | | } |
| | | R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId + ""); |
| | | LoginUserInfoVO loginUserInfoVO = r.getData(); |
| | | WxMaPhoneNumberInfo wxMaPhoneNumberInfo = maService.getUserService().getPhoneNoInfo(loginUserInfoVO.getSessionKey(), |
| | | encryptedData, iv); |
| | | if (ObjectUtils.isEmpty(wxMaPhoneNumberInfo) || ObjectUtils.isEmpty(wxMaPhoneNumberInfo.getPhoneNumber())) { |
| | | throw new WeiXinException("微信解析手机号失败"); |
| | | return R.fail("微信解析手机号失败"); |
| | | } |
| | | String purePhoneNumber = wxMaPhoneNumberInfo.getPurePhoneNumber(); |
| | | R r1=userService.updateUserWeiXinPhone(userId,purePhoneNumber); |
| | | return r1; |
| | | return userService.updateUserWeiXinPhone(userId,purePhoneNumber); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户登出") |
| | |
| | | if (empty2) { |
| | | return R.ok(); |
| | | } |
| | | R r=tokenService.logout(token); |
| | | return r; |
| | | return tokenService.logout(token); |
| | | } |
| | | |
| | | @ApiOperation(value = "刷新token",response = LoginReturnVO.class) |
| | | @GetMapping("refreshToken") |
| | | @ApiImplicitParam(name ="refreshToken",value = "登录返回的刷新token") |
| | | public R refreshToken(@RequestParam("refreshToken")String refreshToken){ |
| | | R r=tokenService.refreshToken(refreshToken); |
| | | return r; |
| | | return tokenService.refreshToken(refreshToken); |
| | | } |
| | | |
| | | @ApiOperation(value = "查询社区") |
| | | @GetMapping("listcommunity") |
| | | public R listCommunity(@RequestBody ComActVO comActVO){ |
| | | return communityService.listCommunity(comActVO); |
| | | } |
| | | |
| | | @ApiOperation(value = "用户绑定社区、小区") |
| | | @PutMapping("putusercommunityarea") |
| | | public R putUserCommunityArea(@RequestBody LoginUserInfoVO loginUserInfoVO){ |
| | | Long userId = this.getUserId(); |
| | | Long communityId = loginUserInfoVO.getCommunityId(); |
| | | Long areaId = loginUserInfoVO.getAreaId(); |
| | | if (null==communityId||0==communityId) { |
| | | return R.fail("社区未选择"); |
| | | } |
| | | if (null==areaId||0==areaId) { |
| | | return R.fail("小区未选择"); |
| | | } |
| | | loginUserInfoVO.setUserId(userId); |
| | | return userService.putUserCommunityArea(loginUserInfoVO); |
| | | } |
| | | } |