diff --git a/api/api-passenger/src/main/resources/bootstrap-dev.yaml b/api/api-passenger/src/main/resources/bootstrap-dev.yaml index c57e8ec..727027e 100644 --- a/api/api-passenger/src/main/resources/bootstrap-dev.yaml +++ b/api/api-passenger/src/main/resources/bootstrap-dev.yaml @@ -7,3 +7,4 @@ spring: config: server-addr: 192.168.3.231:8848 namespace: taxi-dev + file-extension: yaml diff --git a/service/service-verification-code/pom.xml b/service/service-verification-code/pom.xml index 64d2a45..fd5b340 100644 --- a/service/service-verification-code/pom.xml +++ b/service/service-verification-code/pom.xml @@ -43,6 +43,12 @@ spring-cloud-starter-alibaba-nacos-discovery + + + org.springframework.boot + spring-boot-starter-data-redis + + com.greateme diff --git a/service/service-verification-code/src/main/java/com/greateme/verification/service/impl/VerificationCodeServiceImpl.java b/service/service-verification-code/src/main/java/com/greateme/verification/service/impl/VerificationCodeServiceImpl.java index b812501..b1d2af8 100644 --- a/service/service-verification-code/src/main/java/com/greateme/verification/service/impl/VerificationCodeServiceImpl.java +++ b/service/service-verification-code/src/main/java/com/greateme/verification/service/impl/VerificationCodeServiceImpl.java @@ -5,9 +5,13 @@ import com.greateme.verification.entity.dto.PassengerVerificationCodeDTO; import com.greateme.verification.entity.dto.PassengerVerificationCodeRedisDTO; import com.greateme.verification.entity.vo.PassengerVerificationCodeVO; import com.greateme.verification.service.VerificationCodeService; +import org.slf4j.Logger; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.data.redis.core.RedisTemplate; import org.springframework.stereotype.Service; import java.util.UUID; +import java.util.concurrent.TimeUnit; /** *

@@ -22,6 +26,17 @@ import java.util.UUID; @Service public class VerificationCodeServiceImpl implements VerificationCodeService { + /** + * redis的操作对象 + */ + @Autowired + private RedisTemplate redisTemplate; + + /** + * 用户手机验证码redis存储的前缀 + */ + private static final String PASSENGER_PHONE_VERIFICATION_CODE_PREFIX = "PASSENGER::PHONE::VERIFICATION::CODE::"; + /** * 生成一个乘客的短信验证码 * @@ -40,7 +55,8 @@ public class VerificationCodeServiceImpl implements VerificationCodeService { verificationCodeRedis.setVerificationCode(code); verificationCodeRedis.setPassengerPhone(verificationCode.getPassengerPhone()); verificationCodeRedis.setToken(token); - // TODO 将 verificationCodeRedis 存入redis + // 将 verificationCodeRedis 存入redis + this.redisTemplate.opsForValue().set(PASSENGER_PHONE_VERIFICATION_CODE_PREFIX + token, verificationCodeRedis, 5, TimeUnit.MINUTES); // 将token和code返回 PassengerVerificationCodeVO result = new PassengerVerificationCodeVO(); result.setVerificationCode(code); diff --git a/service/service-verification-code/src/main/resources/bootstrap-dev.yaml b/service/service-verification-code/src/main/resources/bootstrap-dev.yaml index c57e8ec..727027e 100644 --- a/service/service-verification-code/src/main/resources/bootstrap-dev.yaml +++ b/service/service-verification-code/src/main/resources/bootstrap-dev.yaml @@ -7,3 +7,4 @@ spring: config: server-addr: 192.168.3.231:8848 namespace: taxi-dev + file-extension: yaml