From 601e7ddfd4e8e6b51d12708c00783d13c7522e0e Mon Sep 17 00:00:00 2001 From: 张天森 <1292933220@qq.com> Date: 星期六, 24 九月 2022 10:06:06 +0800 Subject: [PATCH] update --- springcloud_k8s_panzhihuazhihuishequ/applets/src/main/java/com/panzhihua/applets/api/LoginApi.java | 94 ++++++++++++++++++++++++++++++++++++++--------- 1 files changed, 76 insertions(+), 18 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 9dbb793..fc52183 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,7 +2,6 @@ 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.GetMapping; @@ -23,19 +22,23 @@ import com.panzhihua.common.model.vos.community.ComActVO; import com.panzhihua.common.model.vos.community.ComMngStructAreaVO; import com.panzhihua.common.model.vos.user.SysUserAgreementVO; +import com.panzhihua.common.model.vos.user.UuLoginVO; 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.validated.PutGroup; +import cn.binarywang.wx.miniapp.api.WxMaQrcodeService; import cn.binarywang.wx.miniapp.api.WxMaService; import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult; import cn.binarywang.wx.miniapp.bean.WxMaPhoneNumberInfo; import cn.binarywang.wx.miniapp.bean.WxMaUserInfo; +import cn.hutool.core.codec.Base64; import io.swagger.annotations.Api; import io.swagger.annotations.ApiImplicitParam; import io.swagger.annotations.ApiOperation; import lombok.extern.slf4j.Slf4j; +import me.chanjar.weixin.common.error.WxErrorException; /** * @program: springcloud_k8s_panzhihuazhihuishequ @@ -64,7 +67,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); @@ -82,19 +85,12 @@ 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); - return tokenService.loginApplets(openid); + userService.addOrUpdate(openid, sessionKey, unionid,this.getAppId()); + return tokenService.loginApplets(openid,this.getAppId()); } @ApiOperation(value = "H5登录", response = LoginReturnVO.class) @@ -134,9 +130,43 @@ 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 tokenService.loginApplets(loginUserInfoVO.getOpenid(),this.getAppId()); } 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,this.getAppId()); + return tokenService.loginApplets(openid,this.getAppId()); } @ApiOperation(value = "维护用户基本信息(昵称、性别、头像)") @@ -170,7 +200,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(); @@ -191,7 +221,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); @@ -270,6 +300,34 @@ @GetMapping("useragreement") public R userAgreement() { int type = 1; - return userService.userAgreement(type); + return userService.userAgreement(type,this.getAppId()); + } + @ApiOperation("uu洗车登录") + @PostMapping("uuLogin") + public R uuLogin(@RequestBody UuLoginVO uuLoginVO){ + return userService.uuLogin(uuLoginVO); + } + + @ApiOperation("uu洗车获取小程序码") + @ApiImplicitParam(name = "couponId", value = "优惠券id", required = true) + @GetMapping("uu/getQRCode") + public R uuLogin(@RequestParam("couponId") String couponId) { + try { + WxMaQrcodeService qrCodeService = wxMaConfiguration.getMaService("wx118de8a734d269f0").getQrcodeService(); + byte[] bytes = qrCodeService.createWxaCodeUnlimitBytes("couponId=" + couponId, + "packageD/pages/user/getCoupon/getCoupon", true, "release", 30, true, null, false); + return R.ok(String.format("data:image/png;base64,%s", Base64.encode(bytes))); + } catch (Exception e) { + log.error("generate QRCode failed:" + e.getMessage()); + return R.fail("generate QRCode failed"); + } + } + + @ApiOperation("天府通办登录") + @PostMapping("tfLogin") + public R tfLogin(@RequestBody UuLoginVO uuLoginVO){ + userService.tfLogin(uuLoginVO); + R r=tokenService.tfLogin(uuLoginVO.getMobile(),"Huacheng@123","wx118de8a734d269f0"); + return r; } } -- Gitblit v1.7.1