|
|
|
@ -9,12 +9,12 @@ import com.mashibing.internalcommon.request.VerificationCodeDTO;
|
|
|
|
|
import com.mashibing.internalcommon.response.NumberCodeResponse;
|
|
|
|
|
import com.mashibing.internalcommon.response.TokenResponse;
|
|
|
|
|
import com.mashibing.internalcommon.util.JwtUtils;
|
|
|
|
|
import net.sf.json.JSONObject;
|
|
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.time.Duration;
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
@ -26,13 +26,9 @@ public class VerificationCodeService {
|
|
|
|
|
@Autowired
|
|
|
|
|
private ServicePassengerUserCLient servicePassengerUserCLient;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Autowired
|
|
|
|
|
private StringRedisTemplate redisTemplate;
|
|
|
|
|
|
|
|
|
|
private String prefixKey = "passenger-verification-code-";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 根据 传入手机号 生成验证码并存入redis
|
|
|
|
@ -46,7 +42,7 @@ public class VerificationCodeService {
|
|
|
|
|
String numberCode = numberCodeResponse.getData().getNumberCode();
|
|
|
|
|
|
|
|
|
|
// 存入redis
|
|
|
|
|
String redisKey = getRdisKey(passengerPhone);
|
|
|
|
|
String redisKey = JwtUtils.getRdisVeriCodeKey(passengerPhone);
|
|
|
|
|
redisTemplate.opsForValue().set(redisKey,numberCode,2, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
|
|
// 返回处理结果
|
|
|
|
@ -62,8 +58,8 @@ public class VerificationCodeService {
|
|
|
|
|
public ResponseResult checkCode(String passengerPhone,String verificationCode){
|
|
|
|
|
|
|
|
|
|
// 根据 key前缀+号码 从redis取出对应 校验码比较
|
|
|
|
|
String redisKey = getRdisKey(passengerPhone);
|
|
|
|
|
String codeRedis = redisTemplate.opsForValue().get(redisKey);
|
|
|
|
|
String redisVeriCodeKey = JwtUtils.getRdisVeriCodeKey(passengerPhone);
|
|
|
|
|
String codeRedis = redisTemplate.opsForValue().get(redisVeriCodeKey);
|
|
|
|
|
|
|
|
|
|
// 校验 验证码 是否相同
|
|
|
|
|
if(StringUtils.isBlank(codeRedis) || !StringUtils.equals(codeRedis,verificationCode) ){
|
|
|
|
@ -74,10 +70,15 @@ public class VerificationCodeService {
|
|
|
|
|
VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();
|
|
|
|
|
verificationCodeDTO.setPassengerPhone(passengerPhone);
|
|
|
|
|
servicePassengerUserCLient.loginOrRegister(verificationCodeDTO);
|
|
|
|
|
redisTemplate.delete(redisKey);// 使用后删除key
|
|
|
|
|
redisTemplate.opsForValue().set(redisVeriCodeKey,"");
|
|
|
|
|
Boolean delete = redisTemplate.delete(redisVeriCodeKey);// 使用后删除key
|
|
|
|
|
|
|
|
|
|
// 颁布 token 令牌
|
|
|
|
|
String token = JwtUtils.gerneratorToken(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY);
|
|
|
|
|
// 将 token 存入 redis 中
|
|
|
|
|
String redisTokenKey = JwtUtils.getRdisTokenKey(passengerPhone, IndentinyConstant.PASSENGER_IDENTITY);
|
|
|
|
|
redisTemplate.opsForValue().set(redisTokenKey,token,30,TimeUnit.DAYS);
|
|
|
|
|
|
|
|
|
|
TokenResponse tokenResponse = new TokenResponse();
|
|
|
|
|
tokenResponse.setToken(token);
|
|
|
|
|
|
|
|
|
@ -85,8 +86,5 @@ public class VerificationCodeService {
|
|
|
|
|
return ResponseResult.success(tokenResponse);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private String getRdisKey(String passengerPhone){
|
|
|
|
|
return prefixKey.trim() + passengerPhone.trim();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|