From 0f4ed474226a1c5af99f080c9a4fa8c84aa3319d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=A2=A8=E5=A4=A7=E5=8F=94?= <494979559@qq.com> Date: Mon, 14 Oct 2024 08:38:13 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../framework/web/service/SysLoginService.java | 14 ++++++++------ .../web/controller/app/AppAuthController.java | 2 +- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index 8d4e3c02..a9c1d385 100644 --- a/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/smart-switch-ruoyi/smart-switch-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -262,12 +262,9 @@ public class SysLoginService @Transactional public String wxLogin(WxLoginBody body) { - // 通过登录授权码获取到用户信息 - WxMaJscode2SessionResult wxMaJscode2SessionResult = wxAuthService.wxJsCode2Session(body.getLoginCode()); - ServiceUtil.assertion(wxMaJscode2SessionResult == null, "获取微信openId失败"); - // 通过openId查询用户 - String openId = wxMaJscode2SessionResult.getOpenid(); + String openId = this.getWxOpenId(body.getLoginCode()); + ServiceUtil.assertion(openId == null, "获取微信openId失败"); SmUser user = smUserService.selectSmUserByWxOpenId(openId); // 若用户不存在,则使用openId进行注册 @@ -377,9 +374,14 @@ public class SysLoginService } public String getWxOpenId(String loginCode) { + if (loginCode == null) { + return null; + } // 通过登录授权码获取到用户信息 WxMaJscode2SessionResult wxMaJscode2SessionResult = wxAuthService.wxJsCode2Session(loginCode); - ServiceUtil.assertion(wxMaJscode2SessionResult == null, "获取微信openId失败"); + if (wxMaJscode2SessionResult == null) { + return null; + } return wxMaJscode2SessionResult.getOpenid(); } } diff --git a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAuthController.java b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAuthController.java index c44ee18d..8887a682 100644 --- a/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAuthController.java +++ b/smart-switch-web/src/main/java/com/ruoyi/web/controller/app/AppAuthController.java @@ -55,7 +55,7 @@ public class AppAuthController extends BaseController { // 获取微信openId String wxOpenId = loginService.getWxOpenId(body.getLoginCode()); // 生成令牌 - String token = loginService.wxLogin(wxOpenId); + String token = loginService.wxLogin(body); ajax.put(Constants.TOKEN, token); ajax.put("wxOpenId", wxOpenId); return ajax;