From 398cee97a7b7a3c0b3aabd88875be1041bda7efd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=88=98=E6=89=8D=E7=A6=8F?= Date: Tue, 11 Jul 2023 19:01:22 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=86=E7=99=BD=E5=90=8D=E5=8D=95=E9=AA=8C?= =?UTF-8?q?=E8=AF=81=E7=A0=81=E4=B9=9F=E5=86=99=E5=85=A5=E5=88=B0redis?= =?UTF-8?q?=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../notices/service/impl/SmsServiceImpl.java | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/msg-notices/msg-notices-service/src/main/java/cn/axzo/msg/center/notices/service/impl/SmsServiceImpl.java b/msg-notices/msg-notices-service/src/main/java/cn/axzo/msg/center/notices/service/impl/SmsServiceImpl.java index 4d7a0cc0..36c7f65b 100644 --- a/msg-notices/msg-notices-service/src/main/java/cn/axzo/msg/center/notices/service/impl/SmsServiceImpl.java +++ b/msg-notices/msg-notices-service/src/main/java/cn/axzo/msg/center/notices/service/impl/SmsServiceImpl.java @@ -2,7 +2,9 @@ package cn.axzo.msg.center.notices.service.impl; import cn.axzo.basics.common.exception.ServiceException; import cn.axzo.basics.common.util.AssertUtil; +import cn.axzo.core.constant.RedisNameConstants; import cn.axzo.framework.auth.domain.TerminalInfo; +import cn.axzo.msg.center.common.redis.IAxzoJedisManager; import cn.axzo.msg.center.domain.enums.InsideSmsCodeEnum; import cn.axzo.msg.center.notices.service.SmsService; import cn.axzo.msg.center.notices.service.manager.SmsManager; @@ -18,6 +20,7 @@ import org.springframework.cloud.context.config.annotation.RefreshScope; import org.springframework.stereotype.Service; import javax.annotation.Resource; +import java.time.Duration; import java.util.List; import java.util.Objects; @@ -32,6 +35,10 @@ public class SmsServiceImpl implements SmsService { private Boolean returnCode; @Resource private SmsManager smsManager; + + @Resource + private IAxzoJedisManager iAxzoJedisManager; + @Override public SendCodeRes sendPhoneCodeV2(SendCodeV2Req req) { if (req.getType() == null) { @@ -59,6 +66,7 @@ public class SmsServiceImpl implements SmsService { if (phoneWrites.contains(req.getPhone())) { //白名单返回个666 result.setCode(666666); + saveValidCode(req.getPhone(),terminalType + "", code); return result; } // // 验证boss看板用户是否存在 @@ -73,6 +81,21 @@ public class SmsServiceImpl implements SmsService { return result; } + public void saveValidCode(String phoneNumber, String type, int code) { + Duration duration = Duration.ofSeconds(60 * 15L); + String key = RedisNameConstants.SMS_CODE.concat(type + ":").concat(phoneNumber); + // 在验证码有效期内(15分钟)重复发送验证码,返回同一验证码 + Integer realCode = iAxzoJedisManager.get(key); + if (realCode == null || realCode == 0) { + realCode = code; + } + if (String.valueOf(realCode).length() != String.valueOf(code).length()) { + realCode = code; + } + iAxzoJedisManager.set(key, realCode, duration.getSeconds()); + } + + @Override public CodeStatusRes getPhoneCodeStatus(CodeStatusReq req) {