| | |
| | | return R.fail("缺少登录参数"); |
| | | } |
| | | log.info(code); |
| | | WxMaService maService = wxMaConfiguration.getMaService(); |
| | | WxMaService maService = wxMaConfiguration.getMaService(loginRequest.getAppid()); |
| | | WxMaJscode2SessionResult sessionInfo = null; |
| | | try { |
| | | sessionInfo = maService.getUserService().getSessionInfo(code); |
| | |
| | | log.info("loginRequest参数【{}】", JSONObject.toJSONString(loginRequest)); |
| | | String openid = sessionInfo.getOpenid(); |
| | | String sessionKey = sessionInfo.getSessionKey(); |
| | | // 解密用户信息 |
| | | WxMaUserInfo wxUserInfo = maService.getUserService().getUserInfo(sessionKey, |
| | | loginRequest.getEncryptedData(), loginRequest.getIv()); |
| | | log.info("wxUserInfo信息【{}】", JSONObject.toJSONString(wxUserInfo)); |
| | | if (null == wxUserInfo) { |
| | | return R.fail("获取用户信息失败"); |
| | | String unionid = sessionInfo.getUnionid(); |
| | | if (ObjectUtils.isEmpty(unionid)) { |
| | | unionid = "无"; |
| | | } |
| | | String unionId = wxUserInfo.getUnionId(); |
| | | if (ObjectUtils.isEmpty(unionId)) { |
| | | unionId = "无"; |
| | | } |
| | | userService.addOrUpdate(openid, sessionKey, unionId); |
| | | userService.addOrUpdate(openid, sessionKey, unionid); |
| | | return tokenService.loginApplets(openid); |
| | | } |
| | | |
| | | @ApiOperation(value = "H5登录", response = LoginReturnVO.class) |
| | | @PostMapping("loginH5") |
| | | public R loginH5(@RequestBody LoginRequest loginRequest) { |
| | | String unionId = loginRequest.getUnionId(); |
| | | if (StringUtils.isBlank(unionId)) { |
| | | return R.fail("缺少基本信息参数"); |
| | | String code = loginRequest.getCode(); |
| | | if (ObjectUtils.isEmpty(code)) { |
| | | return R.fail("缺少登录参数"); |
| | | } |
| | | log.info(code); |
| | | WxMaService maService = wxMaConfiguration.getMaH5Service(); |
| | | WxMaJscode2SessionResult sessionInfo = null; |
| | | try { |
| | | sessionInfo = maService.getUserService().getSessionInfo(code); |
| | | } catch (Exception e) { |
| | | log.error("微信登录失败【{}】", e.getMessage()); |
| | | if (code.equals("22")) { |
| | | sessionInfo = new WxMaJscode2SessionResult(); |
| | | sessionInfo.setOpenid("88888888"); |
| | | sessionInfo.setSessionKey("9999999"); |
| | | } else { |
| | | return R.fail("微信登录失败"); |
| | | } |
| | | } |
| | | log.info("微信登录成功【{}】", JSONObject.toJSONString(sessionInfo)); |
| | | log.info("loginRequest参数【{}】", JSONObject.toJSONString(loginRequest)); |
| | | // 解密用户信息 |
| | | // WxMaUserInfo wxUserInfo = maService.getUserService().getUserInfo(sessionInfo.getSessionKey(), |
| | | // loginRequest.getEncryptedData(), loginRequest.getIv()); |
| | | // log.info("wxUserInfo信息【{}】", JSONObject.toJSONString(wxUserInfo)); |
| | | // if (null == wxUserInfo) { |
| | | // return R.fail("获取用户信息失败"); |
| | | // } |
| | | // String unionId = wxUserInfo.getUnionId(); |
| | | String unionId = sessionInfo.getUnionid(); |
| | | //通过unionId去匹配user |
| | | R r1 = userService.getUserInfoByUnionId(unionId); |
| | | if (R.isOk(r1)) { |
| | |
| | | return tokenService.loginApplets(loginUserInfoVO.getOpenid()); |
| | | } |
| | | return r1; |
| | | } |
| | | |
| | | @ApiOperation(value = "仁和区登录", response = LoginReturnVO.class) |
| | | @PostMapping("/renHe/login") |
| | | public R renHeLogin(@RequestBody LoginRequest loginRequest) { |
| | | String code = loginRequest.getCode(); |
| | | if (ObjectUtils.isEmpty(code)) { |
| | | return R.fail("缺少登录参数"); |
| | | } |
| | | log.info(code); |
| | | WxMaService maService = wxMaConfiguration.getMaRhService(); |
| | | WxMaJscode2SessionResult sessionInfo = null; |
| | | try { |
| | | sessionInfo = maService.getUserService().getSessionInfo(code); |
| | | } catch (Exception e) { |
| | | log.error("微信登录失败【{}】", e.getMessage()); |
| | | if (code.equals("22")) { |
| | | sessionInfo = new WxMaJscode2SessionResult(); |
| | | sessionInfo.setOpenid("88888888"); |
| | | sessionInfo.setSessionKey("9999999"); |
| | | } else { |
| | | return R.fail("微信登录失败"); |
| | | } |
| | | } |
| | | log.info("微信登录成功【{}】", JSONObject.toJSONString(sessionInfo)); |
| | | log.info("loginRequest参数【{}】", JSONObject.toJSONString(loginRequest)); |
| | | String openid = sessionInfo.getOpenid(); |
| | | String sessionKey = sessionInfo.getSessionKey(); |
| | | String unionid = sessionInfo.getUnionid(); |
| | | if (ObjectUtils.isEmpty(unionid)) { |
| | | unionid = "无"; |
| | | } |
| | | userService.addOrUpdate(openid, sessionKey, unionid); |
| | | return tokenService.loginApplets(openid); |
| | | } |
| | | |
| | | @ApiOperation(value = "维护用户基本信息(昵称、性别、头像)") |
| | |
| | | if (empty || empty1) { |
| | | return R.fail("微信用户参数不全"); |
| | | } |
| | | WxMaService maService = wxMaConfiguration.getMaService(); |
| | | WxMaService maService = wxMaConfiguration.getMaService(this.getAppId()); |
| | | Long userId = this.getUserId(); |
| | | R<LoginUserInfoVO> r = userService.getUserInfoByUserId(userId + ""); |
| | | LoginUserInfoVO loginUserInfoVO = r.getData(); |
| | |
| | | return R.fail("缺少登录参数"); |
| | | } |
| | | log.info(code); |
| | | WxMaService maService = wxMaConfiguration.getMaService(); |
| | | WxMaService maService = wxMaConfiguration.getMaService(this.getAppId()); |
| | | WxMaJscode2SessionResult sessionInfo = null; |
| | | try { |
| | | sessionInfo = maService.getUserService().getSessionInfo(code); |