mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
!91 sms4j-solon-plugin 升级 solon 为 2.5.4,并完善适配
Merge pull request !91 from 西东/dev-3.0.x
This commit is contained in:
commit
e59a30dece
2
pom.xml
2
pom.xml
@ -55,7 +55,7 @@
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<spring.boot.version>2.7.12</spring.boot.version>
|
||||
<solon.version>2.2.0</solon.version>
|
||||
<solon.version>2.5.4</solon.version>
|
||||
<redisson.version>3.17.0</redisson.version>
|
||||
<jdcloud.version>1.3.3</jdcloud.version>
|
||||
<hutool.version>5.8.20</hutool.version>
|
||||
|
||||
@ -1,7 +1,8 @@
|
||||
package org.dromara.sms4j.solon;
|
||||
|
||||
import org.dromara.sms4j.solon.config.SmsAutowiredConfig;
|
||||
import org.noear.solon.core.AopContext;
|
||||
import org.dromara.sms4j.solon.config.SupplierConfig;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import org.noear.solon.core.Plugin;
|
||||
|
||||
/**
|
||||
@ -9,8 +10,8 @@ import org.noear.solon.core.Plugin;
|
||||
*/
|
||||
public class XPluginImpl implements Plugin {
|
||||
@Override
|
||||
public void start(AopContext context) {
|
||||
public void start(AppContext context) {
|
||||
context.beanMake(SmsAutowiredConfig.class);
|
||||
SmsAutowiredConfig.aopContext = context;
|
||||
context.beanMake(SupplierConfig.class);
|
||||
}
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtils;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
import org.noear.solon.core.AopContext;
|
||||
import org.noear.solon.core.AppContext;
|
||||
|
||||
@Slf4j
|
||||
public class SolonRestrictedProcess implements RestrictedProcess {
|
||||
@ -17,7 +17,7 @@ public class SolonRestrictedProcess implements RestrictedProcess {
|
||||
private static final String REDIS_KEY = "sms:restricted:";
|
||||
private SmsDao smsDao;
|
||||
|
||||
public SolonRestrictedProcess(AopContext context) {
|
||||
public SolonRestrictedProcess(AppContext context) {
|
||||
context.getBeanAsync(SmsDao.class, bean -> smsDao = bean);
|
||||
}
|
||||
|
||||
@ -26,6 +26,7 @@ public class SolonRestrictedProcess implements RestrictedProcess {
|
||||
SmsConfig config = BeanFactory.getSmsConfig();
|
||||
Integer accountMax = config.getAccountMax(); // 每日最大发送量
|
||||
Integer minuteMax = config.getMinuteMax(); // 每分钟最大发送量
|
||||
|
||||
if (SmsUtils.isNotEmpty(accountMax)) { // 是否配置了每日限制
|
||||
Integer i = (Integer) smsDao.get(REDIS_KEY + phone + "max");
|
||||
if (SmsUtils.isEmpty(i)) {
|
||||
@ -50,6 +51,7 @@ public class SolonRestrictedProcess implements RestrictedProcess {
|
||||
smsDao.set(REDIS_KEY + phone, 1, minTimer / 1000);
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,14 +8,10 @@ import org.dromara.sms4j.provider.config.SmsBanner;
|
||||
import org.dromara.sms4j.provider.config.SmsConfig;
|
||||
import org.dromara.sms4j.provider.factory.BeanFactory;
|
||||
import org.dromara.sms4j.solon.aop.SolonRestrictedProcess;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.Utils;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.AopContext;
|
||||
import org.noear.solon.core.Props;
|
||||
import org.noear.solon.core.AppContext;
|
||||
import org.noear.solon.core.bean.LifecycleBean;
|
||||
|
||||
import java.util.concurrent.Executor;
|
||||
@ -24,12 +20,12 @@ import java.util.concurrent.Executor;
|
||||
@Configuration
|
||||
public class SmsAutowiredConfig implements LifecycleBean {
|
||||
|
||||
public static AopContext aopContext;
|
||||
@Inject
|
||||
AppContext context;
|
||||
|
||||
private <T> T injectObj(String prefix, T obj) {
|
||||
//@Inject 只支持在字段、参数、类型上注入
|
||||
Props props = Solon.cfg().getProp(prefix);
|
||||
Utils.injectProperties(obj, props);
|
||||
context.cfg().getProp(prefix).bindTo(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
@ -55,27 +51,12 @@ public class SmsAutowiredConfig implements LifecycleBean {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* smsConfig参数意义为确保注入时smsConfig已经存在
|
||||
*/
|
||||
@Bean
|
||||
@Condition(onProperty = "${sms.config-type}=config_file")
|
||||
public SupplierConfig supplierConfig(@Inject SmsConfig smsConfig) {
|
||||
return new SupplierConfig();
|
||||
}
|
||||
|
||||
// @Bean
|
||||
// @Condition(onProperty = "${sms.config-type}=sql_config")
|
||||
// public SupplierSqlConfig supplierSqlConfig(@Inject SmsSqlConfig smsSqlConfig) {
|
||||
// return new SupplierSqlConfig();
|
||||
// }
|
||||
|
||||
//是在 solon 容器扫描完成之后执行的
|
||||
@Override
|
||||
public void start() {
|
||||
/* 如果配置中启用了redis,则注入redis工具*/
|
||||
if (BeanFactory.getSmsConfig().getRedisCache()) {
|
||||
SmsInvocationHandler.setRestrictedProcess(new SolonRestrictedProcess(aopContext));
|
||||
SmsInvocationHandler.setRestrictedProcess(new SolonRestrictedProcess(context));
|
||||
log.debug("The redis cache is enabled for sms4j");
|
||||
}
|
||||
|
||||
|
||||
@ -9,18 +9,24 @@ import org.dromara.sms4j.jdcloud.config.JdCloudConfig;
|
||||
import org.dromara.sms4j.tencent.config.TencentConfig;
|
||||
import org.dromara.sms4j.unisms.config.UniConfig;
|
||||
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
||||
import org.noear.solon.Solon;
|
||||
import org.noear.solon.Utils;
|
||||
import org.noear.solon.annotation.Bean;
|
||||
import org.noear.solon.annotation.Condition;
|
||||
import org.noear.solon.annotation.Configuration;
|
||||
import org.noear.solon.core.Props;
|
||||
import org.noear.solon.annotation.Inject;
|
||||
import org.noear.solon.core.AppContext;
|
||||
|
||||
/**
|
||||
* smsConfig参数意义为确保注入时smsConfig已经存在
|
||||
*/
|
||||
@Condition(onProperty = "${sms.configType}=config_file")
|
||||
@Configuration
|
||||
public class SupplierConfig {
|
||||
@Inject
|
||||
AppContext context;
|
||||
|
||||
private <T> T injectObj(String prefix, T obj) {
|
||||
//@Inject 只支持在字段、参数、类型上注入
|
||||
Props props = Solon.cfg().getProp(prefix);
|
||||
Utils.injectProperties(obj, props);
|
||||
context.cfg().getProp(prefix).bindTo(obj);
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user