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;