|
|
|
@ -3,9 +3,13 @@ package com.taxi.apidriver.service;
|
|
|
|
|
import com.internal.contant.CommonStatusEnum;
|
|
|
|
|
import com.internal.contant.DriverCarConstant;
|
|
|
|
|
import com.internal.contant.IdentityConstant;
|
|
|
|
|
import com.internal.contant.TokenConstant;
|
|
|
|
|
import com.internal.dto.ResponseResult;
|
|
|
|
|
import com.internal.request.VerificationCodeDTO;
|
|
|
|
|
import com.internal.response.DriverUserExistsResponse;
|
|
|
|
|
import com.internal.response.NumberResponse;
|
|
|
|
|
import com.internal.response.TokenResponse;
|
|
|
|
|
import com.internal.util.JwtUtils;
|
|
|
|
|
import com.internal.util.RedisPrefixUtils;
|
|
|
|
|
import com.taxi.apidriver.remote.ServiceDriverUserClient;
|
|
|
|
|
import com.taxi.apidriver.remote.ServiceVerificationcodeClient;
|
|
|
|
@ -55,4 +59,70 @@ public class VerficationCodeService {
|
|
|
|
|
5, TimeUnit.MINUTES);
|
|
|
|
|
return ResponseResult.success();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param driverPhone
|
|
|
|
|
* @param verificationCode
|
|
|
|
|
* @return
|
|
|
|
|
*/
|
|
|
|
|
public ResponseResult checkCode(String driverPhone, String verificationCode) {
|
|
|
|
|
//一、根据手机号,reids-key规则,查询验证码
|
|
|
|
|
String key = RedisPrefixUtils.getVerificationCodePrefixKey(driverPhone
|
|
|
|
|
,IdentityConstant.DRIVER_IDENTITY);
|
|
|
|
|
String codeRedis = stringRedisTemplate.opsForValue().get(key);
|
|
|
|
|
System.out.println("redis中的code:" + codeRedis);
|
|
|
|
|
|
|
|
|
|
//二、判断验证码是否正确
|
|
|
|
|
if (codeRedis != null && verificationCode != null) {
|
|
|
|
|
verificationCode = verificationCode.trim();
|
|
|
|
|
if (!codeRedis.trim().equals(verificationCode)) {
|
|
|
|
|
CommonStatusEnum.VERIFICATION_CODE_ERROR.setMessage("验证码输入有误!");
|
|
|
|
|
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR);
|
|
|
|
|
} else {
|
|
|
|
|
// //三、判断这个手机号是否存在用户,并进行对应的处理
|
|
|
|
|
// VerificationCodeDTO verificationCodeDTO = new VerificationCodeDTO();
|
|
|
|
|
// verificationCodeDTO.setPassengerPhone(driverPhone);
|
|
|
|
|
// serviceDriverUserClient.getUser(verificationCodeDTO);
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成双token并且保存到redis
|
|
|
|
|
*/
|
|
|
|
|
TokenResponse tokenResponse = proDoubleTokenAndSaveRedis(stringRedisTemplate,
|
|
|
|
|
driverPhone);
|
|
|
|
|
|
|
|
|
|
return ResponseResult.success(tokenResponse);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
CommonStatusEnum.VERIFICATION_CODE_ERROR.setMessage("验证码错误!");
|
|
|
|
|
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 生成双token并且保存到redis
|
|
|
|
|
* 动作一致
|
|
|
|
|
*/
|
|
|
|
|
public TokenResponse proDoubleTokenAndSaveRedis(StringRedisTemplate stringRedisTemplate,
|
|
|
|
|
String passenegerPhone){
|
|
|
|
|
//四、颁发令牌
|
|
|
|
|
String accessToken = JwtUtils.generatorToken(passenegerPhone,
|
|
|
|
|
IdentityConstant.DRIVER_IDENTITY, TokenConstant.ACCESS_TOKEN_TYPE);
|
|
|
|
|
String refreshToken = JwtUtils.generatorToken(passenegerPhone,
|
|
|
|
|
IdentityConstant.DRIVER_IDENTITY,TokenConstant.REFRESH_TOKEN_TYPE);
|
|
|
|
|
|
|
|
|
|
//将accesstoken存入redis
|
|
|
|
|
String accessTokenKey = RedisPrefixUtils.getTokenPrefixKey(passenegerPhone,
|
|
|
|
|
IdentityConstant.DRIVER_IDENTITY,TokenConstant.ACCESS_TOKEN_TYPE);
|
|
|
|
|
stringRedisTemplate.opsForValue().set(accessTokenKey,accessToken,30, TimeUnit.DAYS);
|
|
|
|
|
//将refreshToken存入redis
|
|
|
|
|
String refreshTokenKey = RedisPrefixUtils.getTokenPrefixKey(passenegerPhone,
|
|
|
|
|
IdentityConstant.DRIVER_IDENTITY,TokenConstant.REFRESH_TOKEN_TYPE);
|
|
|
|
|
stringRedisTemplate.opsForValue().set(refreshTokenKey,refreshToken,31,TimeUnit.DAYS);
|
|
|
|
|
|
|
|
|
|
TokenResponse checkCodeResponse = new TokenResponse();
|
|
|
|
|
checkCodeResponse.setAccessToken(accessToken);
|
|
|
|
|
checkCodeResponse.setRefreshToken(refreshToken);
|
|
|
|
|
return checkCodeResponse;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|