Commit 522d39a1 by fanjiaxin

短信限制调整

parent 4532c692
Pipeline #75700 passed with stages
in 1 minute 14 seconds
...@@ -52,10 +52,6 @@ public class SmsServiceImpl implements ISmsService { ...@@ -52,10 +52,6 @@ public class SmsServiceImpl implements ISmsService {
@Override @Override
public void verifySmsCode(String scenes, String phone, String code) { public void verifySmsCode(String scenes, String phone, String code) {
// 检查每日校验次数上限
if (!validateVerifyCodeVerifyCount(scenes, phone)) {
throw new BizException("验证码校验达到次数上限");
}
// 对比验证码 // 对比验证码
String codeKey = String.format(SmsConstant.SMS_CODE_KEY, scenes, phone); String codeKey = String.format(SmsConstant.SMS_CODE_KEY, scenes, phone);
String originCode = redisClient.getStr(codeKey); String originCode = redisClient.getStr(codeKey);
...@@ -77,7 +73,7 @@ public class SmsServiceImpl implements ISmsService { ...@@ -77,7 +73,7 @@ public class SmsServiceImpl implements ISmsService {
private Boolean sendCode(String scenes, String mobilePhone) { private Boolean sendCode(String scenes, String mobilePhone) {
log.info("[op:sendSmsCode] sendCode..."); log.info("[op:sendSmsCode] sendCode...");
SmsCodeScenesConfigBO scenesConfigBO = smsConfig.getScenesConfig(scenes); SmsCodeScenesConfigBO scenesConfigBO = smsConfig.getScenesConfig(scenes);
if(null == scenesConfigBO){ if (null == scenesConfigBO) {
throw new BizException("短信配置错误"); throw new BizException("短信配置错误");
} }
// 生成6位随机数字 // 生成6位随机数字
...@@ -152,21 +148,6 @@ public class SmsServiceImpl implements ISmsService { ...@@ -152,21 +148,6 @@ public class SmsServiceImpl implements ISmsService {
return smsConfig.getScenesConfig(scenes).getSendMaxCount() >= (sendCount == null ? 1 : sendCount); return smsConfig.getScenesConfig(scenes).getSendMaxCount() >= (sendCount == null ? 1 : sendCount);
} }
/**
* 验证码每日校验次数上限
*
* @param scenes 场景
* @param mobilePhone 手机号
* @return true: 未达上限,false: 到了上限
*/
public Boolean validateVerifyCodeVerifyCount(String scenes, String mobilePhone) {
String key = String.format(SmsConstant.SMS_VERIFY_COUNT_KEY, scenes, mobilePhone, getToday());
BoundValueOperations<String, Object> operations = redisClient.boundValueOps(key);
Long verifyCount = operations.increment();
operations.expire(1, TimeUnit.DAYS);
return smsConfig.getScenesConfig(scenes).getVerifyCodeMaxCount() >= (verifyCount == null ? 1 : verifyCount);
}
private String getToday() { private String getToday() {
// 获取当前日期 // 获取当前日期
LocalDate today = LocalDate.now(); LocalDate today = LocalDate.now();
......
...@@ -21,7 +21,7 @@ public class SmsConfig { ...@@ -21,7 +21,7 @@ public class SmsConfig {
* 场景验证码配置 * 场景验证码配置
* key: 业务场景标识 * key: 业务场景标识
*/ */
@ValueMapping("${scenes.config.map:{\"REAL_NAME_AUTHENTICATED\":{\"sendIntervalSeconds\":60,\"codeValidMinutes\":5,\"messageFormat\":\"【网易】验证码:%s,您正在实名认证,%s分钟内输入有效(若非本人操作,请删除本短信)\",\"sendMaxCount\":10,\"verifyCodeMaxCount\":10}}}") @ValueMapping("${scenes.config.map:{\"REAL_NAME_AUTHENTICATED\":{\"sendIntervalSeconds\":60,\"codeValidMinutes\":5,\"messageFormat\":\"【网易】验证码:%s,您正在实名认证,%s分钟内输入有效(若非本人操作,请删除本短信)\",\"sendMaxCount\":10}}}")
private Map<String, SmsCodeScenesConfigBO> scenesConfigMap; private Map<String, SmsCodeScenesConfigBO> scenesConfigMap;
......
...@@ -34,9 +34,4 @@ public class SmsCodeScenesConfigBO implements Serializable { ...@@ -34,9 +34,4 @@ public class SmsCodeScenesConfigBO implements Serializable {
* 验证码发送最大次数 * 验证码发送最大次数
*/ */
private Integer sendMaxCount; private Integer sendMaxCount;
/**
* 验证码每日校验次数上限
*/
private Integer verifyCodeMaxCount;
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment