From ad8f036e3c07cfc32c8a8d65098ae260619af5d7 Mon Sep 17 00:00:00 2001 From: topsun Date: Thu, 13 Apr 2023 11:35:59 +0800 Subject: [PATCH] =?UTF-8?q?=E8=8E=B7=E5=8F=96redis=E4=B8=AD=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/VerificationCodeService.java | 9 ++++++--- .../service/VerificationCodeService.class | Bin 2988 -> 3191 bytes .../internal/util/ApiPassengerConstant.java | 6 ++++++ .../main/java/com/internal/util/Utils.java | 8 ++++++++ .../controller/TestController.java | 18 ------------------ 5 files changed, 20 insertions(+), 21 deletions(-) create mode 100644 online-taxi-public/internal-common/src/main/java/com/internal/util/ApiPassengerConstant.java create mode 100644 online-taxi-public/internal-common/src/main/java/com/internal/util/Utils.java delete mode 100644 online-taxi-public/service-verificationcode/src/main/java/com/spring/serviceverificationcode/controller/TestController.java diff --git a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/VerificationCodeService.java b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/VerificationCodeService.java index e8a0a21..8977f9b 100644 --- a/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/VerificationCodeService.java +++ b/online-taxi-public/api-passenger/src/main/java/com/taxi/apipassenger/service/VerificationCodeService.java @@ -3,6 +3,7 @@ package com.taxi.apipassenger.service; import com.internal.dto.ResponseResult; import com.internal.response.CheckCodeResponse; import com.internal.response.NumberResponse; +import com.internal.util.Utils; import com.taxi.apipassenger.remote.ServiceVerificatoncodeClient; import net.sf.json.JSONObject; import org.springframework.beans.factory.annotation.Autowired; @@ -17,8 +18,7 @@ public class VerificationCodeService { @Autowired private ServiceVerificatoncodeClient serviceVerificatoncodeClient; - //乘客验证码的前缀 - private String verificationCodePrefix = "passenger-verificatioin-code-"; + @Autowired private StringRedisTemplate stringRedisTemplate; @@ -30,7 +30,7 @@ public class VerificationCodeService { int numberCode = responseResult.getData().getNumberCode(); System.out.println("访问service-verificationcode服务,获取验证码:" + numberCode ); //key,value,过期时间 - String key = verificationCodePrefix + passenegerPhone; + String key = Utils.getVerificationCodePrefixKey(passenegerPhone); //存入redis stringRedisTemplate.opsForValue().set(key,numberCode+"",2, TimeUnit.MINUTES); @@ -47,6 +47,9 @@ public class VerificationCodeService { */ public ResponseResult checkCode(String passenegerPhone,String verificationCode) { //一、根据手机号,reids-key规则,查询验证码 + String key = Utils.getVerificationCodePrefixKey(passenegerPhone); + String codeRedis = stringRedisTemplate.opsForValue().get(key); + System.out.println("redis中的code:"+codeRedis); //二、判断验证码是否正确 diff --git a/online-taxi-public/api-passenger/target/classes/com/taxi/apipassenger/service/VerificationCodeService.class b/online-taxi-public/api-passenger/target/classes/com/taxi/apipassenger/service/VerificationCodeService.class index 62e760037b43b540a544dcbf113b5cdad2b93257..fbc0b8fbbafed1b5cd6d4d1c55084652311e83ac 100644 GIT binary patch delta 1070 zcmZ9K*>4k96vlsJdwlKj0KrKKh7k5Ggt{f9i)kJ9Kv=>SwgRnjCds71X&pn8mSXmO z5gH*R#0wISAOS&>1geT>9{3ZGkU;zieXBTki~uo~&heb{o$r3%J#(-2zscq2|3CQ` zSjshvS*(e(mev^SEY{N&XC@mGY-E$gX4(~7EMja`Y_qUf6Jxv1J9OyKVW-6|cI&A< z7JKPC)Bg@C^7Sz~6^=!n=IheATLXF&uA=w)4S#sZXfUdi z8+&s{a_PQYp*y|3RCEj7%ZBfS(uNh!_jfwmoKAPZdl9}JQ~YYv$06@#q;YD&rk~$z zW-~|eyG@Y+MakwcN4%Gjh2bK9c$T@lXOJPALH@M)i=&FaZH`g4na={nahnsIG(d66 z<}_y%XKl`L-sS=qZ7y-ypz3pRQYvaquSf5{y>(hk%oxn~UPUH(_s#mm6|L$5R}GrI ziJ|7KW=ybV* z8=N77d0xAkJN%D2XQ;3sgF^g^2_H4JAMADVUQ2vk&rI2|EJJ>BCm76?x2WWKK~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