|
|
|
@ -3,6 +3,7 @@ package com.luoo.user.service;
|
|
|
|
|
import api.Result;
|
|
|
|
|
import api.StatusCode;
|
|
|
|
|
import com.alibaba.fastjson.JSON;
|
|
|
|
|
import com.luoo.user.dao.UserInfoDao;
|
|
|
|
|
import com.luoo.user.dto.response.Aouth2WeChatJSAPIResponse;
|
|
|
|
|
import com.luoo.user.dto.request.WeChatBindReq;
|
|
|
|
|
import com.luoo.user.dto.request.WeChatLoginReq;
|
|
|
|
@ -57,6 +58,9 @@ public class WeChatAouth2Service {
|
|
|
|
|
@Autowired
|
|
|
|
|
private RedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private UserInfoDao userInfoDao;
|
|
|
|
|
|
|
|
|
|
public Result getShareToken(WeChatShareReq weChatShareReq){
|
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessToken(weChatShareReq.getCode());
|
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null )
|
|
|
|
@ -69,19 +73,70 @@ public class WeChatAouth2Service {
|
|
|
|
|
return Result.success(aouth2WeChatJSAPIResponse.getTicket());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Result loginOrRegister(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
|
// public Result loginOrRegister(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
|
//
|
|
|
|
|
// Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode());
|
|
|
|
|
// if(accessToken == null || accessToken.getAccess_token() == null){
|
|
|
|
|
// return Result.failed(StatusCode.WECHAT_lOGIN_FAILED);
|
|
|
|
|
// }
|
|
|
|
|
//
|
|
|
|
|
// UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
// loginUserInfo.setWxId(accessToken.getOpenid());
|
|
|
|
|
// loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
|
// loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
|
// loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
|
// loginUserInfo.setLastLoginIp(ipAddress);
|
|
|
|
|
// String token = userInfoService.wechatloginOrRegister(loginUserInfo);
|
|
|
|
|
// return Result.success(token);
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
public Result login(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
|
|
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode());
|
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null){
|
|
|
|
|
return Result.failed(StatusCode.WECHAT_lOGIN_FAILED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserInfo userInfo = userInfoDao.findUserInfoByWxId(accessToken.getOpenid());
|
|
|
|
|
if(null == userInfo){
|
|
|
|
|
// 当前微信用户是新用户,需要先绑定手机号
|
|
|
|
|
return Result.failed(StatusCode.WECHAT_MOBILE_UNBINDED);
|
|
|
|
|
}
|
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
// loginUserInfo.setWxId(accessToken.getOpenid());
|
|
|
|
|
// loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
|
loginUserInfo.setLastLoginIp(ipAddress);
|
|
|
|
|
String token = userInfoService.wechatlogin(loginUserInfo);
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Result register(WeChatLoginReq loginReq,String ipAddress){
|
|
|
|
|
|
|
|
|
|
Aouth2WeChatTokenResponse accessToken = getAccessToken(loginReq.getCode());
|
|
|
|
|
if(accessToken == null || accessToken.getAccess_token() == null){
|
|
|
|
|
return Result.failed(StatusCode.WECHAT_lOGIN_FAILED);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果当前手机号在数据库中存在,更新用户信息wxid,返回token
|
|
|
|
|
UserInfo userInfo = userInfoDao.findByMobile(loginReq.getMobile());
|
|
|
|
|
if(null != userInfo) {
|
|
|
|
|
userInfo.setWxId(accessToken.getOpenid());
|
|
|
|
|
String token = userInfoService.wechatRegister(userInfo);
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 如果当前手机号不存在,那就是新用户
|
|
|
|
|
UserInfo loginUserInfo = new UserInfo();
|
|
|
|
|
|
|
|
|
|
loginUserInfo.setWxId(accessToken.getOpenid());
|
|
|
|
|
loginUserInfo.setMobile(loginReq.getMobile());
|
|
|
|
|
loginUserInfo.setLastUseDeviceId(loginReq.getDeviceId());
|
|
|
|
|
loginUserInfo.setLastUseDeviceBrand(loginReq.getDeviceBrand());
|
|
|
|
|
loginUserInfo.setLastLoginIp(ipAddress);
|
|
|
|
|
String token = userInfoService.wechatloginOrRegister(loginUserInfo);
|
|
|
|
|
String token = userInfoService.wechatRegister(loginUserInfo);
|
|
|
|
|
return Result.success(token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|