|
|
|
@ -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());
|
|
|
|
|