mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-07 01:18:33 +08:00
1. 修改smsDao的注入方式
2. 去掉SmsSqlConfig的相关配置
This commit is contained in:
parent
4a0b9df8ce
commit
fc2003f8fe
@ -0,0 +1,18 @@
|
||||
package org.dromara.sms4j.api.proxy;
|
||||
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
|
||||
/**
|
||||
* 短信拦截处理接口
|
||||
*/
|
||||
public interface RestrictedProcess {
|
||||
|
||||
/**
|
||||
* 拦截校验过程
|
||||
* @param phone
|
||||
* @return
|
||||
* @throws Exception
|
||||
*/
|
||||
SmsBlendException process(String phone) throws Exception;
|
||||
|
||||
}
|
||||
@ -6,7 +6,7 @@ import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.core.datainterface.SmsReadConfig;
|
||||
import org.dromara.sms4j.core.load.SmsLoad;
|
||||
import org.dromara.sms4j.core.smsProxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.core.proxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.provider.config.BaseConfig;
|
||||
import org.dromara.sms4j.provider.factory.BaseProviderFactory;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
@ -149,7 +149,7 @@ public abstract class SmsFactory {
|
||||
* @author :Wind
|
||||
*/
|
||||
private static SmsBlend renderWithRestricted(SmsBlend sms) {
|
||||
SmsInvocationHandler smsInvocationHandler = SmsInvocationHandler.newSmsInvocationHandler(sms, BeanFactory.getSmsConfig());
|
||||
SmsInvocationHandler smsInvocationHandler = SmsInvocationHandler.newSmsInvocationHandler(sms);
|
||||
return (SmsBlend) Proxy.newProxyInstance(sms.getClass().getClassLoader(), new Class[]{SmsBlend.class}, smsInvocationHandler);
|
||||
}
|
||||
|
||||
|
||||
@ -0,0 +1,58 @@
|
||||
package org.dromara.sms4j.core.proxy;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.api.proxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class RestrictedProcessDefaultImpl implements RestrictedProcess {
|
||||
static Long minTimer = 60 * 1000L;
|
||||
static Long accTimer = 24 * 60 * 60 * 1000L;
|
||||
|
||||
/**
|
||||
* 缓存实例
|
||||
*/
|
||||
@Setter
|
||||
private SmsDao smsDao;
|
||||
|
||||
public SmsBlendException process(String phone) throws Exception {
|
||||
if (Objects.isNull(smsDao)) {
|
||||
throw new SmsBlendException("The dao tool could not be found");
|
||||
}
|
||||
SmsConfig config = BeanFactory.getSmsConfig();
|
||||
Integer accountMax = config.getAccountMax(); // 每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax(); // 每分钟最大发送量
|
||||
if (SmsUtil.isNotEmpty(accountMax)) { // 是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(phone + "max");
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
smsDao.set(phone + "max", 1, accTimer);
|
||||
} else if (i >= accountMax) {
|
||||
log.info("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
} else {
|
||||
smsDao.set(phone + "max", i + 1, accTimer);
|
||||
}
|
||||
}
|
||||
if (SmsUtil.isNotEmpty(minuteMax)) { // 是否配置了每分钟最大限制
|
||||
Integer o = (Integer) smsDao.get(phone);
|
||||
if (SmsUtil.isNotEmpty(o)) {
|
||||
if (o < minuteMax) {
|
||||
smsDao.set(phone, o + 1, minTimer);
|
||||
} else {
|
||||
log.info("The phone:" + phone + " Text messages are sent too often!");
|
||||
return new SmsBlendException("The phone:", phone + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
smsDao.set(phone, 1, minTimer);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -1,8 +1,8 @@
|
||||
package org.dromara.sms4j.core.smsProxy;
|
||||
package org.dromara.sms4j.core.proxy;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.api.proxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
@ -12,16 +12,14 @@ import java.util.Objects;
|
||||
@Slf4j
|
||||
public class SmsInvocationHandler implements InvocationHandler {
|
||||
private final SmsBlend smsBlend;
|
||||
private final SmsConfig config;
|
||||
private static RestrictedProcess restrictedProcess = new RestrictedProcess();
|
||||
private static RestrictedProcess restrictedProcess = new RestrictedProcessDefaultImpl();
|
||||
|
||||
private SmsInvocationHandler(SmsBlend smsBlend, SmsConfig config) {
|
||||
private SmsInvocationHandler(SmsBlend smsBlend) {
|
||||
this.smsBlend = smsBlend;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
public static SmsInvocationHandler newSmsInvocationHandler(SmsBlend smsBlend, SmsConfig config){
|
||||
return new SmsInvocationHandler(smsBlend,config);
|
||||
public static SmsInvocationHandler newSmsInvocationHandler(SmsBlend smsBlend) {
|
||||
return new SmsInvocationHandler(smsBlend);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -30,7 +28,7 @@ public class SmsInvocationHandler implements InvocationHandler {
|
||||
if ("sendMessage".equals(method.getName()) || "massTexting".equals(method.getName())) {
|
||||
//取手机号作为参数
|
||||
String phone = (String) objects[0];
|
||||
SmsBlendException smsBlendException = restrictedProcess.process(config,phone);
|
||||
SmsBlendException smsBlendException = restrictedProcess.process(phone);
|
||||
if (!Objects.isNull(smsBlendException)) {
|
||||
throw smsBlendException;
|
||||
}
|
||||
@ -1,49 +0,0 @@
|
||||
package org.dromara.sms4j.core.smsProxy;
|
||||
|
||||
import lombok.Setter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
|
||||
@Slf4j
|
||||
public class RestrictedProcess {
|
||||
static Long minTimer = 60 * 1000L;
|
||||
static Long accTimer = 24 * 60 * 60 * 1000L;
|
||||
/**
|
||||
* 缓存实例
|
||||
*/
|
||||
@Setter
|
||||
private SmsDao smsDao;
|
||||
|
||||
public SmsBlendException process(SmsConfig config, String args) throws Exception {
|
||||
Integer accountMax = config.getAccountMax();//每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax();//每分钟最大发送量
|
||||
if (SmsUtil.isNotEmpty(accountMax)) { //是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(args + "max");
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
smsDao.set(args + "max", 1, accTimer);
|
||||
} else if (i > accountMax) {
|
||||
log.info("The phone:" + args + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:" + args + ",number of short messages reached the maximum today");
|
||||
} else {
|
||||
smsDao.set(args + "max", i + 1, accTimer);
|
||||
}
|
||||
}
|
||||
if (SmsUtil.isNotEmpty(minuteMax)) { //是否配置了每分钟最大限制
|
||||
Integer o = (Integer) smsDao.get(args);
|
||||
if (SmsUtil.isNotEmpty(o)) {
|
||||
if (o < minuteMax) {
|
||||
smsDao.set(args, o + 1, minTimer);
|
||||
} else {
|
||||
log.info("The phone:" + args + " Text messages are sent too often!");
|
||||
return new SmsBlendException("The phone:", args + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
smsDao.set(args, 1, minTimer);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -11,9 +11,12 @@ import lombok.ToString;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.aliyun.config.AlibabaFactory;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.cloopen.config.CloopenFactory;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.dromara.sms4j.core.proxy.RestrictedProcessDefaultImpl;
|
||||
import org.dromara.sms4j.core.proxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.ctyun.config.CtyunFactory;
|
||||
import org.dromara.sms4j.emay.config.EmayFactory;
|
||||
import org.dromara.sms4j.huawei.config.HuaweiFactory;
|
||||
@ -62,9 +65,10 @@ public class SEInitializer {
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public void fromYaml() {
|
||||
public SEInitializer fromYaml() {
|
||||
ClassPathResource yamlResouce = new ClassPathResource("sms4j.yml");
|
||||
this.fromYaml(yamlResouce.readUtf8Str());
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -72,9 +76,10 @@ public class SEInitializer {
|
||||
*
|
||||
* @param yaml yaml配置字符串
|
||||
*/
|
||||
public void fromYaml(String yaml) {
|
||||
public SEInitializer fromYaml(String yaml) {
|
||||
InitConfig config = YamlUtil.toBean(yaml, InitConfig.class);
|
||||
this.initConfig(config);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -82,17 +87,33 @@ public class SEInitializer {
|
||||
*
|
||||
* @param json json配置字符串
|
||||
*/
|
||||
public void fromJson(String json) {
|
||||
public SEInitializer fromJson(String json) {
|
||||
InitConfig config = JSONUtil.toBean(json, InitConfig.class);
|
||||
this.initConfig(config);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册供应商工厂
|
||||
* @param factory
|
||||
*/
|
||||
public void registerFactory(BaseProviderFactory<? extends SmsBlend, ? extends SupplierConfig> factory) {
|
||||
public SEInitializer registerFactory(BaseProviderFactory<? extends SmsBlend, ? extends SupplierConfig> factory) {
|
||||
ProviderFactoryHolder.registerFactory(factory);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 注册DAO实例
|
||||
* @param smsDao
|
||||
*/
|
||||
public SEInitializer registerSmsDao(SmsDao smsDao) {
|
||||
if(smsDao == null) {
|
||||
throw new SmsBlendException("注册DAO实例失败,实例不能为空");
|
||||
}
|
||||
RestrictedProcessDefaultImpl process = new RestrictedProcessDefaultImpl();
|
||||
process.setSmsDao(smsDao);
|
||||
SmsInvocationHandler.setRestrictedProcess(process);
|
||||
return this;
|
||||
}
|
||||
|
||||
private void initConfig(InitConfig config) {
|
||||
|
||||
@ -64,10 +64,4 @@ public class BeanFactory {
|
||||
return smsConfig;
|
||||
}
|
||||
|
||||
// public static JDBCTool getJDBCTool(){
|
||||
// if (jdbcTool == null){
|
||||
// jdbcTool = new JDBCTool(getSmsSqlConfig());
|
||||
// }
|
||||
// return jdbcTool;
|
||||
// }
|
||||
}
|
||||
|
||||
@ -2,52 +2,54 @@ package org.dromara.sms4j.solon.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.core.smsProxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.api.proxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
import org.noear.solon.core.AopContext;
|
||||
|
||||
@Slf4j
|
||||
public class SolonRestrictedProcess extends RestrictedProcess {
|
||||
public class SolonRestrictedProcess implements RestrictedProcess {
|
||||
|
||||
private SmsDao smsDao;
|
||||
private static final Long minTimer = 60 * 1000L;
|
||||
private static final Long accTimer = 24 * 60 * 60 * 1000L;
|
||||
private static final String REDIS_KEY = "sms:restricted:";
|
||||
private SmsDao smsDao;
|
||||
|
||||
public SolonRestrictedProcess(AopContext context){
|
||||
context.getBeanAsync(SmsDao.class, bean->{
|
||||
public SolonRestrictedProcess(AopContext context) {
|
||||
context.getBeanAsync(SmsDao.class, bean -> {
|
||||
smsDao = bean;
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public SmsBlendException process(SmsConfig config, String args) {
|
||||
Integer accountMax = config.getAccountMax();//每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax();//每分钟最大发送量
|
||||
if (SmsUtil.isNotEmpty(accountMax)) { //是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(REDIS_KEY+args + "max");
|
||||
public SmsBlendException process(String phone) {
|
||||
SmsConfig config = BeanFactory.getSmsConfig();
|
||||
Integer accountMax = config.getAccountMax(); // 每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax(); // 每分钟最大发送量
|
||||
if (SmsUtil.isNotEmpty(accountMax)) { // 是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(REDIS_KEY + phone + "max");
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
smsDao.set(REDIS_KEY+args + "max", 1,accTimer/1000);
|
||||
} else if (i > accountMax) {
|
||||
log.info("The phone:"+args +",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:"+args +",number of short messages reached the maximum today");
|
||||
smsDao.set(REDIS_KEY + phone + "max", 1, accTimer / 1000);
|
||||
} else if (i >= accountMax) {
|
||||
log.info("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
} else {
|
||||
smsDao.set(REDIS_KEY+args + "max", i + 1,accTimer/1000);
|
||||
smsDao.set(REDIS_KEY + phone + "max", i + 1, accTimer / 1000);
|
||||
}
|
||||
}
|
||||
if (SmsUtil.isNotEmpty(minuteMax)) { //是否配置了每分钟最大限制
|
||||
Integer o = (Integer) smsDao.get(REDIS_KEY+args);
|
||||
if (SmsUtil.isNotEmpty(minuteMax)) { // 是否配置了每分钟最大限制
|
||||
Integer o = (Integer) smsDao.get(REDIS_KEY + phone);
|
||||
if (SmsUtil.isNotEmpty(o)) {
|
||||
if (o < minuteMax) {
|
||||
smsDao.set(REDIS_KEY+args, o + 1,minTimer/1000);
|
||||
smsDao.set(REDIS_KEY + phone, o + 1, minTimer / 1000);
|
||||
} else {
|
||||
log.info("The phone:"+args +",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:", args + " Text messages are sent too often!");
|
||||
log.info("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:", phone + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
smsDao.set(REDIS_KEY+args, 1,minTimer/1000);
|
||||
smsDao.set(REDIS_KEY + phone, 1, minTimer / 1000);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@ -1,7 +1,7 @@
|
||||
package org.dromara.sms4j.solon.config;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.core.smsProxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.core.proxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.provider.config.SmsBanner;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.constant.Constant;
|
||||
|
||||
@ -1,54 +0,0 @@
|
||||
package org.dromara.sms4j.starter.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.core.smsProxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.starter.utils.SmsSpringUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class RestrictedProcessImpl extends RestrictedProcess {
|
||||
private static final Long minTimer = 60 * 1000L;
|
||||
private static final Long accTimer = 24 * 60 * 60 * 1000L;
|
||||
private static final String REDIS_KEY = "sms:restricted:";
|
||||
|
||||
|
||||
@Override
|
||||
public SmsBlendException process(SmsConfig config,String args) throws Exception {
|
||||
SmsDao smsDao = SmsSpringUtil.getBean(SmsDao.class);
|
||||
if (Objects.isNull(smsDao)){
|
||||
throw new SmsBlendException("The dao tool could not be found");
|
||||
}
|
||||
Integer accountMax = config.getAccountMax();//每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax();//每分钟最大发送量
|
||||
if (SmsUtil.isNotEmpty(accountMax)) { //是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(REDIS_KEY + args + "max");
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
smsDao.set(REDIS_KEY + args + "max", 1, accTimer / 1000);
|
||||
} else if (i > accountMax) {
|
||||
log.info("The phone:" + args + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:" + args + ",number of short messages reached the maximum today");
|
||||
} else {
|
||||
smsDao.set(REDIS_KEY + args + "max", i + 1, accTimer / 1000);
|
||||
}
|
||||
}
|
||||
if (SmsUtil.isNotEmpty(minuteMax)) { //是否配置了每分钟最大限制
|
||||
Integer o = (Integer) smsDao.get(REDIS_KEY + args);
|
||||
if (SmsUtil.isNotEmpty(o)) {
|
||||
if (o < minuteMax) {
|
||||
smsDao.set(REDIS_KEY + args, o + 1, minTimer / 1000);
|
||||
} else {
|
||||
log.info("The phone:" + args + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:", args + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
smsDao.set(REDIS_KEY + args, 1, minTimer / 1000);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,56 @@
|
||||
package org.dromara.sms4j.starter.aop;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.api.proxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
import org.dromara.sms4j.starter.utils.SmsSpringUtil;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
@Slf4j
|
||||
public class SpringRestrictedProcess implements RestrictedProcess {
|
||||
private static final Long minTimer = 60 * 1000L;
|
||||
private static final Long accTimer = 24 * 60 * 60 * 1000L;
|
||||
private static final String REDIS_KEY = "sms:restricted:";
|
||||
|
||||
|
||||
@Override
|
||||
public SmsBlendException process(String phone) throws Exception {
|
||||
SmsConfig config = BeanFactory.getSmsConfig();
|
||||
SmsDao smsDao = SmsSpringUtil.getBean(SmsDao.class);
|
||||
if (Objects.isNull(smsDao)) {
|
||||
throw new SmsBlendException("The dao tool could not be found");
|
||||
}
|
||||
Integer accountMax = config.getAccountMax(); // 每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax(); // 每分钟最大发送量
|
||||
if (SmsUtil.isNotEmpty(accountMax)) { // 是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(REDIS_KEY + phone + "max");
|
||||
if (SmsUtil.isEmpty(i)) {
|
||||
smsDao.set(REDIS_KEY + phone + "max", 1, accTimer / 1000);
|
||||
} else if (i >= accountMax) {
|
||||
log.info("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
} else {
|
||||
smsDao.set(REDIS_KEY + phone + "max", i + 1, accTimer / 1000);
|
||||
}
|
||||
}
|
||||
if (SmsUtil.isNotEmpty(minuteMax)) { // 是否配置了每分钟最大限制
|
||||
Integer o = (Integer) smsDao.get(REDIS_KEY + phone);
|
||||
if (SmsUtil.isNotEmpty(o)) {
|
||||
if (o < minuteMax) {
|
||||
smsDao.set(REDIS_KEY + phone, o + 1, minTimer / 1000);
|
||||
} else {
|
||||
log.info("The phone:" + phone + ",number of short messages reached the maximum today");
|
||||
return new SmsBlendException("The phone:", phone + " Text messages are sent too often!");
|
||||
}
|
||||
} else {
|
||||
smsDao.set(REDIS_KEY + phone, 1, minTimer / 1000);
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@ -6,13 +6,18 @@ import cn.hutool.json.JSONUtil;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.api.dao.SmsDao;
|
||||
import org.dromara.sms4j.api.dao.SmsDaoDefaultImpl;
|
||||
import org.dromara.sms4j.api.proxy.RestrictedProcess;
|
||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||
import org.dromara.sms4j.comm.constant.Constant;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtil;
|
||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||
import org.dromara.sms4j.core.proxy.SmsInvocationHandler;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BaseProviderFactory;
|
||||
import org.dromara.sms4j.provider.factory.ProviderFactoryHolder;
|
||||
import org.dromara.sms4j.starter.aop.SpringRestrictedProcess;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
@ -54,6 +59,9 @@ public class SmsBlendsInitializer {
|
||||
SmsFactory.createSmsBlend(supplierConfig);
|
||||
}
|
||||
}
|
||||
|
||||
//注册短信拦截实现
|
||||
SmsInvocationHandler.setRestrictedProcess(new SpringRestrictedProcess());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -2,5 +2,4 @@ org.springframework.boot.autoconfigure.EnableAutoConfiguration=\
|
||||
org.dromara.sms4j.starter.config.SmsMainConfig,\
|
||||
org.dromara.sms4j.starter.config.SmsAutowiredConfig,\
|
||||
org.dromara.sms4j.starter.config.SupplierConfig,\
|
||||
org.dromara.sms4j.provider.config.SmsConfig,\
|
||||
org.dromara.sms4j.provider.config.SmsSqlConfig
|
||||
org.dromara.sms4j.provider.config.SmsConfig
|
||||
|
||||
@ -2,4 +2,3 @@ org.dromara.sms4j.starter.config.SmsMainConfig
|
||||
org.dromara.sms4j.starter.config.SmsAutowiredConfig
|
||||
org.dromara.sms4j.starter.config.SupplierConfig
|
||||
org.dromara.sms4j.provider.config.SmsConfig
|
||||
org.dromara.sms4j.provider.config.SmsSqlConfig
|
||||
Loading…
x
Reference in New Issue
Block a user