|
|
|
@ -2,9 +2,15 @@ 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;
|
|
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
@ -12,6 +18,8 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
|
import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Service
|
|
|
|
|
@Slf4j
|
|
|
|
@ -42,10 +50,79 @@ public class VerficationCodeService {
|
|
|
|
|
ResponseResult<NumberResponse> numberResponse = serviceVerificationcodeClient.getVerificationCode(6);
|
|
|
|
|
int numberCode = numberResponse.getData().getNumberCode();
|
|
|
|
|
log.info("验证码"+numberCode);
|
|
|
|
|
//调用三方,获取验证码
|
|
|
|
|
//调用三方,获取验证码,第三方,阿里服务,腾讯,华信
|
|
|
|
|
|
|
|
|
|
//存入redis
|
|
|
|
|
// stringRedisTemplate.opsForValue().set(key, numberCode + "", 5, TimeUnit.MINUTES);
|
|
|
|
|
String numberCodeKey = RedisPrefixUtils.getVerificationCodePrefixKey(driverPhone,
|
|
|
|
|
IdentityConstant.DRIVER_IDENTITY);
|
|
|
|
|
stringRedisTemplate.opsForValue().set(numberCodeKey, numberCode + "",
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|