Browse Source

send verification

tags/24080901
niohe·erbao 1 year ago
parent
commit
9872abf32d
2 changed files with 6 additions and 4 deletions
  1. +1
    -1
      pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java
  2. +5
    -3
      pmapi/src/main/java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java

+ 1
- 1
pmapi/src/main/java/com/ningdatech/pmapi/sms/manage/SmsManage.java View File

@@ -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()) {


+ 5
- 3
pmapi/src/main/java/com/ningdatech/pmapi/sms/utils/SmsRedisKeyUtils.java View File

@@ -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;
}

}

Loading…
Cancel
Save