From 3dfa632fc3bd5e4b8b8110d73da4e6327f5d4582 Mon Sep 17 00:00:00 2001 From: wangqing <408564126@qq.com> Date: Wed, 27 Mar 2024 13:30:56 +0800 Subject: [PATCH] fix wechat login --- .../java/com/luoo/user/service/UserInfoService.java | 2 +- .../com/luoo/user/service/WeChatAouth2Service.java | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java index 2fdbdef..bbb51f7 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java +++ b/luoo_user/src/main/java/com/luoo/user/service/UserInfoService.java @@ -210,7 +210,7 @@ public class UserInfoService { userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); } else { - userInfo.setAppleId(loginUserInfo.getAppleId()); +// userInfo.setAppleId(loginUserInfo.getAppleId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp()); diff --git a/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java b/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java index 6d15328..cf96675 100644 --- a/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java +++ b/luoo_user/src/main/java/com/luoo/user/service/WeChatAouth2Service.java @@ -14,6 +14,7 @@ import com.luoo.user.pojo.UserInfo; import constants.Constants; import dto.UserLoginDto; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang.StringUtils; import org.apache.http.Consts; import org.apache.http.HttpEntity; import org.apache.http.HttpResponse; @@ -106,6 +107,7 @@ public class WeChatAouth2Service { UserInfo userInfo = userInfoDao.findUserInfoByWxId(accessToken.getOpenid()); if(null == userInfo){ // 当前微信用户是新用户,需要先绑定手机号 + redisTemplate.opsForValue().set(loginReq.getCode(),accessToken.getOpenid(),10,TimeUnit.MINUTES); return Result.failed(StatusCode.WECHAT_MOBILE_UNBINDED); } UserInfo loginUserInfo = new UserInfo(); @@ -121,15 +123,16 @@ public class WeChatAouth2Service { public Result register(WeChatLoginReq loginReq,String ipAddress){ - Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode()); - if(accessToken == null || accessToken.getAccess_token() == null){ +// Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode()); + String openId = (String) redisTemplate.opsForValue().get(loginReq.getCode()); + if(StringUtils.isEmpty(openId)){ return Result.failed(StatusCode.WECHAT_lOGIN_FAILED); } // 如果当前手机号在数据库中存在,更新用户信息wxid,返回token UserInfo userInfo = userInfoDao.findByMobile(loginReq.getMobile()); if(null != userInfo) { - userInfo.setWxId(accessToken.getOpenid()); + userInfo.setWxId(openId); String token = userInfoService.wechatRegister(userInfo); return Result.success(token); } @@ -137,7 +140,7 @@ public class WeChatAouth2Service { // 如果当前手机号不存在,那就是新用户 UserInfo loginUserInfo = new UserInfo(); - loginUserInfo.setWxId(accessToken.getOpenid()); + loginUserInfo.setWxId(openId); loginUserInfo.setMobile(loginReq.getMobile()); loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId()); loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());