|
|
@@ -2,8 +2,8 @@ package com.hz.pm.api.sms.manage; |
|
|
|
|
|
|
|
import cn.hutool.core.util.PhoneUtil; |
|
|
|
import cn.hutool.core.util.RandomUtil; |
|
|
|
import com.hz.pm.api.common.exception.ReturnException; |
|
|
|
import com.hz.pm.api.common.helper.MsgCallHelper; |
|
|
|
import com.hz.pm.api.external.sms.MhSmsClient; |
|
|
|
import com.hz.pm.api.sms.constant.VerificationCodeType; |
|
|
|
import com.hz.pm.api.sms.constant.VoiceSmsTemplateConst; |
|
|
|
import com.hz.pm.api.sms.model.dto.VerifyCodeCacheDTO; |
|
|
@@ -11,7 +11,6 @@ import com.hz.pm.api.sms.model.po.ReqVerificationCodePO; |
|
|
|
import com.hz.pm.api.sms.utils.DateUtil; |
|
|
|
import com.hz.pm.api.sms.utils.SmsRedisKeyUtils; |
|
|
|
import com.hz.pm.api.sys.model.enumeration.BizTypeEnum; |
|
|
|
import com.ningdatech.basic.exception.BizException; |
|
|
|
import com.ningdatech.cache.model.cache.CacheKey; |
|
|
|
import com.ningdatech.cache.repository.CachePlusOps; |
|
|
|
import lombok.RequiredArgsConstructor; |
|
|
@@ -22,7 +21,6 @@ import org.springframework.util.Assert; |
|
|
|
|
|
|
|
import java.time.Duration; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.util.Collections; |
|
|
|
import java.util.Objects; |
|
|
|
|
|
|
|
/** |
|
|
@@ -45,14 +43,14 @@ public class VerificationCodeManage { |
|
|
|
// 验证是否被锁定 |
|
|
|
String lockKey = SmsRedisKeyUtils.smsSendLockKey(codeType, req.getMobile()); |
|
|
|
if (StringUtils.isNotBlank(cachePlusOps.get(lockKey))) { |
|
|
|
throw BizException.wrap("今日" + codeType.getDesc() + "的验证码发送次数过多,已被锁定"); |
|
|
|
throw ReturnException.wrap("今日" + codeType.getDesc() + "的验证码发送次数过多,已被锁定"); |
|
|
|
} |
|
|
|
// 验证发送间隔 |
|
|
|
String cacheKey = SmsRedisKeyUtils.smsCodeVerifyKey(codeType, req.getMobile()); |
|
|
|
VerifyCodeCacheDTO preCache = cachePlusOps.get(cacheKey); |
|
|
|
if (preCache != null && (LocalDateTime.now().minusMinutes(codeType.getSendInterval()) |
|
|
|
.isBefore(preCache.getSendTime()))) { |
|
|
|
throw BizException.wrap(codeType.getSendInterval() + "分钟之内已发送过验证码,请稍后重试"); |
|
|
|
throw ReturnException.wrap(codeType.getSendInterval() + "分钟之内已发送过验证码,请稍后重试"); |
|
|
|
} |
|
|
|
String code = RandomUtil.randomNumbers(6); |
|
|
|
VerifyCodeCacheDTO cache = VerifyCodeCacheDTO.builder() |
|
|
@@ -74,7 +72,7 @@ public class VerificationCodeManage { |
|
|
|
} |
|
|
|
break; |
|
|
|
default: |
|
|
|
throw new IllegalArgumentException("非法的短信发送类型"); |
|
|
|
throw ReturnException.wrap("非法的短信发送类型"); |
|
|
|
} |
|
|
|
|
|
|
|
// 发送 短信 |
|
|
|