|
@ -12,6 +12,7 @@ import com.epmet.constant.PublicUserLoginConstant; |
|
|
import com.epmet.constant.SmsTemplateConstant; |
|
|
import com.epmet.constant.SmsTemplateConstant; |
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
import com.epmet.dto.PaCustomerDTO; |
|
|
import com.epmet.dto.PaUserDTO; |
|
|
import com.epmet.dto.PaUserDTO; |
|
|
|
|
|
import com.epmet.dto.PaUserWechatDTO; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.form.*; |
|
|
import com.epmet.dto.result.CustomerUserResultDTO; |
|
|
import com.epmet.dto.result.CustomerUserResultDTO; |
|
|
import com.epmet.dto.result.SaveUserResultDTO; |
|
|
import com.epmet.dto.result.SaveUserResultDTO; |
|
@ -77,7 +78,9 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
//3.获取用户token
|
|
|
//3.获取用户token
|
|
|
String token = this.generateGovWxmpToken(resultDTO.getUserId()); |
|
|
String token = this.generateGovWxmpToken(resultDTO.getUserId()); |
|
|
//4.保存到redis
|
|
|
//4.保存到redis
|
|
|
this.saveLatestGovTokenDto(resultDTO, wxMpUser, token); |
|
|
String openid = wxMpUser.getOpenId(); |
|
|
|
|
|
String unionId = (null == wxMpUser.getUnionId() ? "" : wxMpUser.getUnionId()); |
|
|
|
|
|
this.saveLatestGovTokenDto("", resultDTO.getUserId(), openid, unionId, token); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
userTokenResultDTO.setToken(token); |
|
|
userTokenResultDTO.setToken(token); |
|
|
return userTokenResultDTO; |
|
|
return userTokenResultDTO; |
|
@ -118,17 +121,17 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//保存tokenDto到redis
|
|
|
//保存tokenDto到redis
|
|
|
private void saveLatestGovTokenDto(SaveUserResultDTO resultDTO, WxMpUser wxMpUser, String token) { |
|
|
private void saveLatestGovTokenDto(String customerId, String userId, String openId, String unionId, String token) { |
|
|
TokenDto tokenDTO = new TokenDto(); |
|
|
TokenDto tokenDTO = new TokenDto(); |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
tokenDTO.setApp(LoginConstant.APP_PUBLIC); |
|
|
tokenDTO.setApp(LoginConstant.APP_PUBLIC); |
|
|
tokenDTO.setClient(LoginConstant.CLIENT_MP); |
|
|
tokenDTO.setClient(LoginConstant.CLIENT_MP); |
|
|
tokenDTO.setOpenId(wxMpUser.getOpenId()); |
|
|
tokenDTO.setOpenId(openId); |
|
|
tokenDTO.setUnionId(null == wxMpUser.getUnionId() ? "" : wxMpUser.getUnionId()); |
|
|
tokenDTO.setUnionId(unionId); |
|
|
tokenDTO.setToken(token); |
|
|
tokenDTO.setToken(token); |
|
|
//首次初始化时还没有客户
|
|
|
//首次初始化时还没有客户
|
|
|
tokenDTO.setCustomerId(""); |
|
|
tokenDTO.setCustomerId(customerId); |
|
|
tokenDTO.setUserId(resultDTO.getUserId()); |
|
|
tokenDTO.setUserId(userId); |
|
|
tokenDTO.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
tokenDTO.setExpireTime(jwtTokenUtils.getExpiration(token).getTime()); |
|
|
tokenDTO.setUpdateTime(System.currentTimeMillis()); |
|
|
tokenDTO.setUpdateTime(System.currentTimeMillis()); |
|
|
cpUserDetailRedis.set(tokenDTO, expire); |
|
|
cpUserDetailRedis.set(tokenDTO, expire); |
|
@ -206,19 +209,27 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
logger.error(String.format("验证码错误code[%s],msg[%s]", EpmetErrorCode.MOBILE_CODE_ERROR.getCode(), EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); |
|
|
logger.error(String.format("验证码错误code[%s],msg[%s]", EpmetErrorCode.MOBILE_CODE_ERROR.getCode(), EpmetErrorCode.MOBILE_CODE_ERROR.getMsg())); |
|
|
throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
throw new RenException(EpmetErrorCode.MOBILE_CODE_ERROR.getCode()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//获取缓存中的token
|
|
|
//获取缓存中的token
|
|
|
TokenDto redisTokenDTO = cpUserDetailRedis.get(LoginConstant.APP_PUBLIC, LoginConstant.CLIENT_MP, userDTO.getId(), TokenDto.class); |
|
|
TokenDto redisTokenDTO = cpUserDetailRedis.get(LoginConstant.APP_PUBLIC, LoginConstant.CLIENT_MP, userDTO.getId(), TokenDto.class); |
|
|
if (redisTokenDTO == null) { |
|
|
if (redisTokenDTO == null) { |
|
|
return null; |
|
|
return null; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
//4.判断是否存在客户信息,是否需要生成新的token
|
|
|
//4.直接生成一个新的token放入缓存中(不管缓存中是否存在旧的token,都重新生成)
|
|
|
|
|
|
//4-1.生成token
|
|
|
|
|
|
String token = this.generateGovWxmpToken(userDTO.getId()); |
|
|
|
|
|
//4-2.判断是否存在信息,给customerId赋值
|
|
|
PaCustomerDTO customerDTO = resultDTO.getPaCustomerResult(); |
|
|
PaCustomerDTO customerDTO = resultDTO.getPaCustomerResult(); |
|
|
|
|
|
String customerId = ""; |
|
|
if (null != customerDTO && !StringUtils.isBlank(customerDTO.getId())) { |
|
|
if (null != customerDTO && !StringUtils.isBlank(customerDTO.getId())) { |
|
|
redisTokenDTO.setCustomerId(customerDTO.getId()); |
|
|
customerId = customerDTO.getId(); |
|
|
int expire = jwtTokenProperties.getExpire(); |
|
|
|
|
|
cpUserDetailRedis.set(redisTokenDTO, expire); |
|
|
|
|
|
} |
|
|
} |
|
|
|
|
|
//4-3.token存入redis
|
|
|
|
|
|
PaUserWechatDTO wechatDTO = resultDTO.getPaUserWechatResult(); |
|
|
|
|
|
String openid = wechatDTO.getWxOpenId(); |
|
|
|
|
|
String unionId = (null == wechatDTO.getUnionId() ? "" : wechatDTO.getUnionId()); |
|
|
|
|
|
this.saveLatestGovTokenDto(customerId, userDTO.getId(), openid, unionId, token); |
|
|
|
|
|
|
|
|
//5.登陆成功,访问记录表新增访问记录(访问记录新增失败不应影响用户登陆)
|
|
|
//5.登陆成功,访问记录表新增访问记录(访问记录新增失败不应影响用户登陆)
|
|
|
SaveUserVisitedFormDTO visited = new SaveUserVisitedFormDTO(); |
|
|
SaveUserVisitedFormDTO visited = new SaveUserVisitedFormDTO(); |
|
@ -232,7 +243,7 @@ public class PublicUserLoginServiceImpl implements PublicUserLoginService { |
|
|
|
|
|
|
|
|
//6.返回token
|
|
|
//6.返回token
|
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
UserTokenResultDTO userTokenResultDTO = new UserTokenResultDTO(); |
|
|
userTokenResultDTO.setToken(redisTokenDTO.getToken()); |
|
|
userTokenResultDTO.setToken(token); |
|
|
return userTokenResultDTO; |
|
|
return userTokenResultDTO; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|