From 9872abf32da64c2273bd4ad83c975a1f7b0e0d89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?niohe=C2=B7erbao?= Date: Thu, 16 Mar 2023 13:43:07 +0800 Subject: [PATCH] send verification --- .../src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java | 2 +- .../java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java | 8 +++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java index 38a2274..2332a00 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java @@ -82,7 +82,7 @@ public class SmsManage { cachePlusOps.set(new CacheKey(cacheKey, Duration.ofMinutes(verificationCodeTypeEnum.getExpireTime())), cache); String limitKey = SmsRedisKeyUtils.smsSendLimitKey(verificationCodeTypeEnum, request.getMobile()); - if (Objects.nonNull(cachePlusOps.get(limitKey))) { + if (StringUtils.isNotBlank(cachePlusOps.get(limitKey))) { long limitCount = cachePlusOps.incr(new CacheKey(limitKey, Duration.ofSeconds(DateUtil.restSecondsFromNowToNoon()))); // 超出单日发送次数之后直接锁定 if (limitCount >= verificationCodeTypeEnum.getSendTimesByDay().longValue()) { diff --git a/pmapi/src/main/java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java b/pmapi/src/main/java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java index 23e3e30..1a5fa44 100644 --- a/pmapi/src/main/java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java +++ b/pmapi/src/main/java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java @@ -16,20 +16,22 @@ public class SmsRedisKeyUtils { private SmsRedisKeyUtils() { } + private static final String PROJECT_NAME = "ls_pm:"; + private static final String SMS_CODE_VERIFY_PREFIX = "sms:verify:"; private static final String SMS_SEND_LIMIT = "sms:limit:"; private static final String SMS_SEND_LOCK = "sms:lock:"; public static String smsCodeVerifyKey(VerificationCodeType type, String mobile) { - return SMS_CODE_VERIFY_PREFIX + StrPool.COLON + type.name() + StrPool.COLON + mobile; + return PROJECT_NAME + SMS_CODE_VERIFY_PREFIX + StrPool.COLON + type.name() + StrPool.COLON + mobile; } public static String smsSendLimitKey(VerificationCodeType type, String mobile) { - return SMS_SEND_LIMIT + StrPool.COLON + type.name() + StrPool.COLON + mobile; + return PROJECT_NAME + SMS_SEND_LIMIT + StrPool.COLON + type.name() + StrPool.COLON + mobile; } public static String smsSendLockKey(VerificationCodeType type, String mobile) { - return SMS_SEND_LOCK + StrPool.COLON + type.name() + StrPool.COLON + mobile; + return PROJECT_NAME + SMS_SEND_LOCK + StrPool.COLON + type.name() + StrPool.COLON + mobile; } }