Commit b0ee19e7 by fanjiaxin

短信验证码配置调整

parent e231f17b
Pipeline #75486 passed with stages
in 1 minute 28 seconds
......@@ -11,6 +11,7 @@ import com.netease.yanxuan.wx.store.sharer.common.util.RandomUtils;
import com.netease.yanxuan.wx.store.sharer.integration.client.IUasClient;
import com.netease.yanxuan.wx.store.sharer.integration.config.SmsConfig;
import com.netease.yanxuan.wx.store.sharer.integration.constant.SmsConstant;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.SmsCodeScenesConfigBO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang.StringUtils;
......@@ -77,8 +78,9 @@ public class SmsServiceImpl implements ISmsService {
if (!success) {
return false;
}
int sendIntervalSeconds = smsConfig.getSendIntervalSeconds();
int codeValidMinutes = smsConfig.getCodeValidMinutes();
SmsCodeScenesConfigBO smsCodeScenesConfigBO = smsConfig.getScenesConfig(scenes);
int sendIntervalSeconds = smsCodeScenesConfigBO.getSendIntervalSeconds();
int codeValidMinutes = smsCodeScenesConfigBO.getCodeValidMinutes();
// 标记验证码已发送
String sendCodeKey = String.format(SmsConstant.SMS_SEND_INTERVAL_KEY, scenes, mobilePhone);
redisClient.setStr(sendCodeKey, String.valueOf(System.currentTimeMillis()), sendIntervalSeconds);
......@@ -138,7 +140,7 @@ public class SmsServiceImpl implements ISmsService {
BoundValueOperations<String, Object> operations = redisClient.boundValueOps(key);
Long sendCount = operations.increment();
operations.expire(1, TimeUnit.DAYS);
return smsConfig.getSendMaxCount() >= (sendCount == null ? 1 : sendCount);
return smsConfig.getScenesConfig(scenes).getSendMaxCount() >= (sendCount == null ? 1 : sendCount);
}
/**
......@@ -153,7 +155,7 @@ public class SmsServiceImpl implements ISmsService {
BoundValueOperations<String, Object> operations = redisClient.boundValueOps(key);
Long verifyCount = operations.increment();
operations.expire(1, TimeUnit.DAYS);
return smsConfig.getVerifyCodeMaxCount() >= (verifyCount == null ? 1 : verifyCount);
return smsConfig.getScenesConfig(scenes).getVerifyCodeMaxCount() >= (verifyCount == null ? 1 : verifyCount);
}
private String getToday() {
......
......@@ -11,6 +11,7 @@ import com.netease.yanxuan.wx.store.sharer.integration.client.IUasClient;
import com.netease.yanxuan.wx.store.sharer.integration.config.RpcConfig;
import com.netease.yanxuan.wx.store.sharer.integration.config.SmsConfig;
import com.netease.yanxuan.wx.store.sharer.integration.handler.RestTemplateHandler;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.SmsCodeScenesConfigBO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpMethod;
......@@ -59,7 +60,8 @@ public class UasClientImpl implements IUasClient {
private Map<String, Object> assembleSmsArg(String uid, String phone, String code, String scenes) {
Map<String, Object> params = new HashMap<>();
params.put("phone", phone);
params.put("message", String.format(smsConfig.getMessageFormat(), code, smsConfig.getCodeValidMinutes()));
SmsCodeScenesConfigBO scenesConfig = smsConfig.getScenesConfig(scenes);
params.put("message", String.format(scenesConfig.getMessageFormat(), code, scenesConfig.getCodeValidMinutes()));
params.put("level", 1);
params.put("uid", uid);
params.put("topic", String.format(TOPIC_FORMAT, scenes));
......
package com.netease.yanxuan.wx.store.sharer.integration.config;
import com.ctrip.framework.apollo.spring.annotation.EnableAutoUpdateApolloConfig;
import com.ctrip.framework.apollo.spring.annotation.ValueMapping;
import com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo.SmsCodeScenesConfigBO;
import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Map;
/**
* @Description 应用配置
* @Author fanjiaxin
......@@ -15,32 +18,14 @@ import org.springframework.stereotype.Component;
@EnableAutoUpdateApolloConfig
public class SmsConfig {
/**
* 验证码发送最大次数
*/
@Value("${sms.send.max.count:10}")
private Integer sendMaxCount;
/**
* 验证码发送间隔时间,秒
* 场景验证码配置
* key: 业务场景标识
*/
@Value("${sms.send.interval.seconds:60}")
private Integer sendIntervalSeconds;
@ValueMapping("${sms.scenes.config.map:{}}")
private Map<String, SmsCodeScenesConfigBO> scenesConfigMap;
/**
* 验证码有效时间,分钟
*/
@Value("${sms.code.valid.minutes:5}")
private Integer codeValidMinutes;
/**
* 验证码短信格式
*/
@Value("${sms.message.format:}")
private String messageFormat;
/**
* 验证码每日校验次数上限
*/
@Value("${sms.verify.code.max.count:10}")
private Integer verifyCodeMaxCount;
public SmsCodeScenesConfigBO getScenesConfig(String scenes) {
return scenesConfigMap.get(scenes);
}
}
\ No newline at end of file
package com.netease.yanxuan.wx.store.sharer.integration.meta.model.bo;
import lombok.Builder;
import lombok.Data;
import java.io.Serializable;
/**
* @Description 短信验证码-配置-业务对象
* @Author fanjiaxin
* @Date 2025/3/11 18:43
*/
@Data
@Builder
public class SmsCodeScenesConfigBO implements Serializable {
private static final long serialVersionUID = 1L;
/**
* 验证码发送间隔时间,秒
*/
private Integer sendIntervalSeconds;
/**
* 验证码有效时间,分钟
*/
private Integer codeValidMinutes;
/**
* 验证码短信格式
*/
private String messageFormat;
/**
* 验证码发送最大次数
*/
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