|
|
@ -4,11 +4,13 @@ import com.mashibing.apipassenger.remote.ServicePassengerUserCLient;
|
|
|
|
import com.mashibing.apipassenger.remote.ServiceVerificationcodeClient;
|
|
|
|
import com.mashibing.apipassenger.remote.ServiceVerificationcodeClient;
|
|
|
|
import com.mashibing.internalcommon.constant.CommonStatusEnum;
|
|
|
|
import com.mashibing.internalcommon.constant.CommonStatusEnum;
|
|
|
|
import com.mashibing.internalcommon.constant.IndentinyConstant;
|
|
|
|
import com.mashibing.internalcommon.constant.IndentinyConstant;
|
|
|
|
|
|
|
|
import com.mashibing.internalcommon.constant.TokenConstants;
|
|
|
|
import com.mashibing.internalcommon.dto.ResponseResult;
|
|
|
|
import com.mashibing.internalcommon.dto.ResponseResult;
|
|
|
|
import com.mashibing.internalcommon.request.VerificationCodeDTO;
|
|
|
|
import com.mashibing.internalcommon.request.VerificationCodeDTO;
|
|
|
|
import com.mashibing.internalcommon.response.NumberCodeResponse;
|
|
|
|
import com.mashibing.internalcommon.response.NumberCodeResponse;
|
|
|
|
import com.mashibing.internalcommon.response.TokenResponse;
|
|
|
|
import com.mashibing.internalcommon.response.TokenResponse;
|
|
|
|
import com.mashibing.internalcommon.util.JwtUtils;
|
|
|
|
import com.mashibing.internalcommon.util.JwtUtils;
|
|
|
|
|
|
|
|
import com.mashibing.internalcommon.util.RedisPrefixUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
@ -42,7 +44,7 @@ public class VerificationCodeService {
|
|
|
|
String numberCode = numberCodeResponse.getData().getNumberCode();
|
|
|
|
String numberCode = numberCodeResponse.getData().getNumberCode();
|
|
|
|
|
|
|
|
|
|
|
|
// 存入redis
|
|
|
|
// 存入redis
|
|
|
|
String redisKey = JwtUtils.getRdisVeriCodeKey(passengerPhone);
|
|
|
|
String redisKey = RedisPrefixUtils.getRdisVeriCodeKey(passengerPhone);
|
|
|
|
redisTemplate.opsForValue().set(redisKey,numberCode,2, TimeUnit.MINUTES);
|
|
|
|
redisTemplate.opsForValue().set(redisKey,numberCode,2, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
|
|
// 返回处理结果
|
|
|
|
// 返回处理结果
|
|
|
@ -58,7 +60,7 @@ public class VerificationCodeService {
|
|
|
|
public ResponseResult checkCode(String passengerPhone,String verificationCode){
|
|
|
|
public ResponseResult checkCode(String passengerPhone,String verificationCode){
|
|
|
|
|
|
|
|
|
|
|
|
// 根据 key前缀+号码 从redis取出对应 校验码比较
|
|
|
|
// 根据 key前缀+号码 从redis取出对应 校验码比较
|
|
|
|
String redisVeriCodeKey = JwtUtils.getRdisVeriCodeKey(passengerPhone);
|
|
|
|
String redisVeriCodeKey = RedisPrefixUtils.getRdisVeriCodeKey(passengerPhone);
|
|
|
|
String codeRedis = redisTemplate.opsForValue().get(redisVeriCodeKey);
|
|
|
|
String codeRedis = redisTemplate.opsForValue().get(redisVeriCodeKey);
|
|
|
|
|
|
|
|
|
|
|
|
// 校验 验证码 是否相同
|
|
|
|
// 校验 验证码 是否相同
|
|
|
@ -73,14 +75,20 @@ public class VerificationCodeService {
|
|
|
|
redisTemplate.opsForValue().set(redisVeriCodeKey,"");
|
|
|
|
redisTemplate.opsForValue().set(redisVeriCodeKey,"");
|
|
|
|
Boolean delete = redisTemplate.delete(redisVeriCodeKey);// 使用后删除key
|
|
|
|
Boolean delete = redisTemplate.delete(redisVeriCodeKey);// 使用后删除key
|
|
|
|
|
|
|
|
|
|
|
|
// 颁布 token 令牌
|
|
|
|
// 颁布 accessToken & refreshToken 令牌
|
|
|
|
String token = JwtUtils.gerneratorToken(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY);
|
|
|
|
String accessToken = JwtUtils.gerneratorToken(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY,TokenConstants.ACCESS_TOKEN_TYPE);
|
|
|
|
// 将 token 存入 redis 中
|
|
|
|
String refreshToken = JwtUtils.gerneratorToken(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY,TokenConstants.REFRESH_TOKEN_TYPE);
|
|
|
|
String redisTokenKey = JwtUtils.getRdisTokenKey(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY);
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(redisTokenKey,token,30,TimeUnit.DAYS);
|
|
|
|
// 将 accessToken & refreshToken 存入 redis 中
|
|
|
|
|
|
|
|
String redisAccessTokenKey = RedisPrefixUtils.getRdisTokenKey(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY,TokenConstants.ACCESS_TOKEN_TYPE);
|
|
|
|
|
|
|
|
String redisRefreshTokenKey = RedisPrefixUtils.getRdisTokenKey(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY,TokenConstants.REFRESH_TOKEN_TYPE);
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(redisAccessTokenKey,accessToken,30,TimeUnit.DAYS);
|
|
|
|
|
|
|
|
redisTemplate.opsForValue().set(redisRefreshTokenKey,refreshToken,31,TimeUnit.DAYS);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TokenResponse tokenResponse = new TokenResponse();
|
|
|
|
TokenResponse tokenResponse = new TokenResponse();
|
|
|
|
tokenResponse.setToken(token);
|
|
|
|
tokenResponse.setAccessToken(accessToken);
|
|
|
|
|
|
|
|
tokenResponse.setRefreshToken(refreshToken);
|
|
|
|
|
|
|
|
|
|
|
|
// 返回处理结果
|
|
|
|
// 返回处理结果
|
|
|
|
return ResponseResult.success(tokenResponse);
|
|
|
|
return ResponseResult.success(tokenResponse);
|
|
|
|