diff --git a/share-space-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java b/share-space-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java index 9a86107..bc624bd 100644 --- a/share-space-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java +++ b/share-space-admin/src/main/java/com/ruoyi/web/controller/system/SysLoginController.java @@ -182,11 +182,11 @@ public class SysLoginController extends BaseController * 微信登录 */ @PostMapping("/wxlogin") - public AjaxResult wxlogin(String mobileCode,String jsCode) { + public AjaxResult wxlogin(String mobileCode,String jsCode, Long appid) { log.info("【微信登录/wxlogin】areaId参数:【mobileCode={}】", mobileCode); AjaxResult ajax = AjaxResult.success(); // 生成令牌 - String token = loginService.wxloing(mobileCode,jsCode); + String token = loginService.wxloing(mobileCode,jsCode,appid); ajax.put(Constants.TOKEN, token); return ajax; } diff --git a/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java b/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java index a2f8f92..16806a8 100644 --- a/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java +++ b/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysLoginService.java @@ -101,7 +101,7 @@ public class SysLoginService if(!StrUtil.isBlank(jsCode)){ User updatedUser = new User(); updatedUser.setPhonenumber(username); -// updatedUser.setWxopenid(getOpenId(jsCode,app.getConfig().getAppId(),app.getConfig().getAppSecret())); + updatedUser.setWxopenid(getOpenId(jsCode,app.getConfig().getAppId(),app.getConfig().getAppSecret())); int i = eUserService.updateUserByPhone(updatedUser); ServiceUtil.assertion(i == 0, "更新用户openid失败"); } @@ -270,16 +270,17 @@ public class SysLoginService /** * 微信登录 */ - public String wxloing(String mobileCode,String jsCode) { - //根据jsCode换取openid - String openId = getOpenId(jsCode); + public String wxloing(String mobileCode,String jsCode,Long appid) { String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="; String phoneNumber = null; User user = null; /** 根据手机号获取到用户名*/ - - String token = AccessTokenUtil.getToken(appId,appSecret); + AppVO app = appService.selectAppById(appid); + ServiceUtil.assertion(app == null, "ID为%s的APP信息不存在,请联系管理员", appid); + //根据jsCode换取openid + String openId = getOpenId(jsCode,app.getConfig().getAppId(),app.getConfig().getAppSecret()); + String token = AccessTokenUtil.getToken(app.getConfig().getAppId(),app.getConfig().getAppSecret()); url = url+token; JSONObject jsonObject = new JSONObject(); jsonObject.put("code",mobileCode); @@ -355,8 +356,7 @@ public class SysLoginService AppVO app = appService.selectAppById(appid); ServiceUtil.assertion(app == null, "ID为%s的APP信息不存在,请联系管理员", appid); -// String openId = getOpenId(jsCode, app.getConfig().getAppId(),app.getConfig().getAppSecret()); - String openId = null; + String openId = getOpenId(jsCode, app.getConfig().getAppId(),app.getConfig().getAppSecret()); User user = eUserService.selectUserByWxopenid(openId); ServiceUtil.assertion(ObjectUtils.isEmpty(user),"未查询到用户信息"); Authentication authentication = null; // 用户验证 @@ -383,7 +383,7 @@ public class SysLoginService return tokenService.createToken(loginUser); } - public String getOpenId(String jsCode) { + public String getOpenId(String jsCode, String appId, String appSecret) { //根据jsCode换取openid String url = StrUtil.format("https://api.weixin.qq.com/sns/jscode2session?appid={}&secret={}&js_code={}&grant_type=authorization_code", appId, appSecret, jsCode); String s = HttpUtils.sendGet(url); @@ -400,12 +400,11 @@ public class SysLoginService String uuid =loginBody.getUuid(); String jsCode = loginBody.getJsCode(); -// // 查询APP信息 -// AppVO app = appService.selectAppById(loginBody.getAppid()); -// ServiceUtil.assertion(app == null, "ID为%s的APP信息不存在,请联系管理员", loginBody.getAppid()); -// -// String openId = getOpenId(jsCode,app.getConfig().getAppId(),app.getConfig().getAppSecret()); - String openId = null; + // 查询APP信息 + AppVO app = appService.selectAppById(loginBody.getAppid()); + ServiceUtil.assertion(app == null, "ID为%s的APP信息不存在,请联系管理员", loginBody.getAppid()); + + String openId = getOpenId(jsCode,app.getConfig().getAppId(),app.getConfig().getAppSecret()); User user = eUserService.selectUserByPhoneAndAppId(loginBody.getPhone()); if(ObjectUtils.isEmpty(user)){ diff --git a/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java b/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java index 9b353a4..5596968 100644 --- a/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java +++ b/share-space-framework/src/main/java/com/ruoyi/framework/web/service/SysRegisterService.java @@ -94,7 +94,7 @@ public class SysRegisterService { AppVO appVO = appService.selectAppById(registerBody.getAppid()); ServiceUtil.assertion(appVO == null, "ID为%s的APP信息不存在,请联系管理员", registerBody.getAppid()); -// sysUser.setWxopenid(loginService.getOpenId(jsCode,appVO.getConfig().getAppId(),appVO.getConfig().getAppSecret())); + sysUser.setWxopenid(loginService.getOpenId(jsCode,appVO.getConfig().getAppId(),appVO.getConfig().getAppSecret())); sysUser.setPhonenumber(username); sysUser.setPassword(SecurityUtils.encryptPassword(password)); sysUser.setAppId(registerBody.getAppid());