fix wechat login

main
wangqing 8 months ago
parent 6e3fb0fd9e
commit 3dfa632fc3

@ -210,7 +210,7 @@ public class UserInfoService {
userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE); userInfo.setSignature(Constants.DEFAULT_USER_SIGNATURE);
} else { } else {
userInfo.setAppleId(loginUserInfo.getAppleId()); // userInfo.setAppleId(loginUserInfo.getAppleId());
userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId()); userInfo.setLastUseDeviceId(loginUserInfo.getLastUseDeviceId());
userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand()); userInfo.setLastUseDeviceBrand(loginUserInfo.getLastUseDeviceBrand());
userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp()); userInfo.setLastLoginIp(loginUserInfo.getLastLoginIp());

@ -14,6 +14,7 @@ import com.luoo.user.pojo.UserInfo;
import constants.Constants; import constants.Constants;
import dto.UserLoginDto; import dto.UserLoginDto;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
import org.apache.http.Consts; import org.apache.http.Consts;
import org.apache.http.HttpEntity; import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -106,6 +107,7 @@ public class WeChatAouth2Service {
UserInfo userInfo = userInfoDao.findUserInfoByWxId(accessToken.getOpenid()); UserInfo userInfo = userInfoDao.findUserInfoByWxId(accessToken.getOpenid());
if(null == userInfo){ if(null == userInfo){
// 当前微信用户是新用户,需要先绑定手机号 // 当前微信用户是新用户,需要先绑定手机号
redisTemplate.opsForValue().set(loginReq.getCode(),accessToken.getOpenid(),10,TimeUnit.MINUTES);
return Result.failed(StatusCode.WECHAT_MOBILE_UNBINDED); return Result.failed(StatusCode.WECHAT_MOBILE_UNBINDED);
} }
UserInfo loginUserInfo = new UserInfo(); UserInfo loginUserInfo = new UserInfo();
@ -121,15 +123,16 @@ public class WeChatAouth2Service {
public Result register(WeChatLoginReq loginReq,String ipAddress){ public Result register(WeChatLoginReq loginReq,String ipAddress){
Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode()); // Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode());
if(accessToken == null || accessToken.getAccess_token() == null){ String openId = (String) redisTemplate.opsForValue().get(loginReq.getCode());
if(StringUtils.isEmpty(openId)){
return Result.failed(StatusCode.WECHAT_lOGIN_FAILED); return Result.failed(StatusCode.WECHAT_lOGIN_FAILED);
} }
// 如果当前手机号在数据库中存在,更新用户信息wxid,返回token // 如果当前手机号在数据库中存在,更新用户信息wxid,返回token
UserInfo userInfo = userInfoDao.findByMobile(loginReq.getMobile()); UserInfo userInfo = userInfoDao.findByMobile(loginReq.getMobile());
if(null != userInfo) { if(null != userInfo) {
userInfo.setWxId(accessToken.getOpenid()); userInfo.setWxId(openId);
String token = userInfoService.wechatRegister(userInfo); String token = userInfoService.wechatRegister(userInfo);
return Result.success(token); return Result.success(token);
} }
@ -137,7 +140,7 @@ public class WeChatAouth2Service {
// 如果当前手机号不存在,那就是新用户 // 如果当前手机号不存在,那就是新用户
UserInfo loginUserInfo = new UserInfo(); UserInfo loginUserInfo = new UserInfo();
loginUserInfo.setWxId(accessToken.getOpenid()); loginUserInfo.setWxId(openId);
loginUserInfo.setMobile(loginReq.getMobile()); loginUserInfo.setMobile(loginReq.getMobile());
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId()); loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand()); loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());

Loading…
Cancel
Save