Compare commits

..

No commits in common. 'fd788ecf6d2adce4a54e59e4c524cb063bf505f3' and '6070c0e9c66b7381885ddcd4c56a6c385e35e8f2' have entirely different histories.

@ -6,7 +6,6 @@ import com.taxi.apidriver.service.VerficationCodeService;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody; import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@ -23,11 +22,4 @@ public class VerficationCodeController {
log.info("司机的号码"+driverPhone); log.info("司机的号码"+driverPhone);
return verficationCodeService.checkSendVerficationCode(driverPhone); return verficationCodeService.checkSendVerficationCode(driverPhone);
} }
@PostMapping("/verification-code-check")
public ResponseResult verificationCodeCheck(@RequestBody VerificationCodeDTO verificationCodeDTO){
String driverPhone = verificationCodeDTO.getDriverPhone();
String verificationCode = verificationCodeDTO.getVerificationCode();
return verficationCodeService.checkCode(driverPhone,verificationCode);
}
} }

@ -1,10 +1,11 @@
package com.taxi.apidriver.remote; package com.taxi.apidriver.remote;
import com.internal.dto.ResponseResult; import com.internal.dto.ResponseResult;
import com.internal.request.VerificationCodeDTO;
import com.internal.response.NumberResponse; import com.internal.response.NumberResponse;
import org.springframework.cloud.openfeign.FeignClient; import org.springframework.cloud.openfeign.FeignClient;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
@FeignClient("service-verificationcode") @FeignClient("service-verificationcode")
public interface ServiceVerificationcodeClient { public interface ServiceVerificationcodeClient {

@ -2,15 +2,9 @@ package com.taxi.apidriver.service;
import com.internal.contant.CommonStatusEnum; import com.internal.contant.CommonStatusEnum;
import com.internal.contant.DriverCarConstant; import com.internal.contant.DriverCarConstant;
import com.internal.contant.IdentityConstant;
import com.internal.contant.TokenConstant;
import com.internal.dto.ResponseResult; import com.internal.dto.ResponseResult;
import com.internal.request.VerificationCodeDTO;
import com.internal.response.DriverUserExistsResponse; import com.internal.response.DriverUserExistsResponse;
import com.internal.response.NumberResponse; 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.ServiceDriverUserClient;
import com.taxi.apidriver.remote.ServiceVerificationcodeClient; import com.taxi.apidriver.remote.ServiceVerificationcodeClient;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
@ -18,8 +12,6 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import java.util.concurrent.TimeUnit;
@Service @Service
@Slf4j @Slf4j
@ -50,79 +42,10 @@ public class VerficationCodeService {
ResponseResult<NumberResponse> numberResponse = serviceVerificationcodeClient.getVerificationCode(6); ResponseResult<NumberResponse> numberResponse = serviceVerificationcodeClient.getVerificationCode(6);
int numberCode = numberResponse.getData().getNumberCode(); int numberCode = numberResponse.getData().getNumberCode();
log.info("验证码"+numberCode); log.info("验证码"+numberCode);
//调用三方,获取验证码,第三方,阿里服务,腾讯,华信 //调用三方,获取验证码
//存入redis //存入redis
String numberCodeKey = RedisPrefixUtils.getVerificationCodePrefixKey(driverPhone, // stringRedisTemplate.opsForValue().set(key, numberCode + "", 5, TimeUnit.MINUTES);
IdentityConstant.DRIVER_IDENTITY);
stringRedisTemplate.opsForValue().set(numberCodeKey, numberCode + "",
5, TimeUnit.MINUTES);
return ResponseResult.success(); 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);
/**
* tokenredis
*/
TokenResponse tokenResponse = proDoubleTokenAndSaveRedis(stringRedisTemplate,
driverPhone);
return ResponseResult.success(tokenResponse);
}
} else {
CommonStatusEnum.VERIFICATION_CODE_ERROR.setMessage("验证码错误!");
return ResponseResult.fail(CommonStatusEnum.VERIFICATION_CODE_ERROR);
}
}
/**
* tokenredis
*
*/
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;
}
} }

@ -1,6 +1,5 @@
package com.taxi.apipassenger.service; package com.taxi.apipassenger.service;
import com.alibaba.nacos.client.identify.IdentifyConstants;
import com.internal.contant.CommonStatusEnum; import com.internal.contant.CommonStatusEnum;
import com.internal.contant.IdentityConstant; import com.internal.contant.IdentityConstant;
import com.internal.contant.TokenConstant; import com.internal.contant.TokenConstant;
@ -40,8 +39,7 @@ public class VerificationCodeService {
int numberCode = responseResult.getData().getNumberCode(); int numberCode = responseResult.getData().getNumberCode();
System.out.println("访问service-verificationcode服务获取验证码" + numberCode); System.out.println("访问service-verificationcode服务获取验证码" + numberCode);
//key,value,过期时间 //key,value,过期时间
String key = RedisPrefixUtils.getVerificationCodePrefixKey(passenegerPhone, String key = RedisPrefixUtils.getVerificationCodePrefixKey(passenegerPhone);
IdentityConstant.PASSENGER_IDENTITY);
//存入redis //存入redis
stringRedisTemplate.opsForValue().set(key, numberCode + "", 5, TimeUnit.MINUTES); stringRedisTemplate.opsForValue().set(key, numberCode + "", 5, TimeUnit.MINUTES);
@ -57,8 +55,7 @@ public class VerificationCodeService {
*/ */
public ResponseResult checkCode(String passenegerPhone, String verificationCode) { public ResponseResult checkCode(String passenegerPhone, String verificationCode) {
//一、根据手机号reids-key规则查询验证码 //一、根据手机号reids-key规则查询验证码
String key = RedisPrefixUtils.getVerificationCodePrefixKey(passenegerPhone String key = RedisPrefixUtils.getVerificationCodePrefixKey(passenegerPhone);
,IdentityConstant.PASSENGER_IDENTITY);
String codeRedis = stringRedisTemplate.opsForValue().get(key); String codeRedis = stringRedisTemplate.opsForValue().get(key);
System.out.println("redis中的code:" + codeRedis); System.out.println("redis中的code:" + codeRedis);

@ -2,6 +2,6 @@ package com.internal.util;
public class ApiPassengerConstant { public class ApiPassengerConstant {
//乘客验证码的前缀 //乘客验证码的前缀
public final static String verificationCodePrefix = "verificatioin-code-"; public final static String verificationCodePrefix = "passenger-verificatioin-code-";
public final static String TOKEN_PREFIX = "token-"; public final static String TOKEN_PREFIX = "token-";
} }

@ -2,9 +2,8 @@ package com.internal.util;
public class RedisPrefixUtils { public class RedisPrefixUtils {
public static String getVerificationCodePrefixKey(String passenegerPhone public static String getVerificationCodePrefixKey(String passenegerPhone) {
,String identity) { return ApiPassengerConstant.verificationCodePrefix + passenegerPhone;
return ApiPassengerConstant.verificationCodePrefix + identity +"-"+ passenegerPhone;
} }
/** /**

Loading…
Cancel
Save