From b92edf56e7e25440e7c46b967aa5373a7a8b25c2 Mon Sep 17 00:00:00 2001 From: puhanshu <a9236326> Date: 星期一, 14 三月 2022 09:22:02 +0800 Subject: [PATCH] Merge remote-tracking branch 'origin/dev' into dev --- springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java | 91 +++++++++++++++++++++++++++++++++++++++++++-- 1 files changed, 87 insertions(+), 4 deletions(-) diff --git a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java index 67f8aa2..dc72421 100644 --- a/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java +++ b/springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java @@ -2,9 +2,15 @@ import javax.annotation.Resource; +import org.apache.commons.lang3.StringUtils; import org.springframework.util.ObjectUtils; import org.springframework.validation.annotation.Validated; -import org.springframework.web.bind.annotation.*; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PostMapping; +import org.springframework.web.bind.annotation.PutMapping; +import org.springframework.web.bind.annotation.RequestBody; +import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.RestController; import com.alibaba.fastjson.JSONObject; import com.panzhihua.applets.config.WxMaConfiguration; @@ -58,7 +64,7 @@ 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); @@ -73,6 +79,83 @@ } } 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 = "H5登录", response = LoginReturnVO.class) + @PostMapping("loginH5") + public R loginH5(@RequestBody LoginRequest loginRequest) { + 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)) { + LoginUserInfoVO loginUserInfoVO = JSONObject.parseObject(JSONObject.toJSONString(r1.getData()), LoginUserInfoVO.class); + 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(); @@ -114,7 +197,7 @@ 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(); @@ -135,7 +218,7 @@ 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); -- Gitblit v1.7.1