mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
修改配置文件结构
This commit is contained in:
parent
8965527f6e
commit
8d5e035850
7
pom.xml
7
pom.xml
@ -56,6 +56,7 @@
|
||||
<unisms.version>0.0.4</unisms.version>
|
||||
<tencent.version>3.1.622</tencent.version>
|
||||
<forest.version>1.5.30</forest.version>
|
||||
<hutool.version>5.8.16</hutool.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
@ -181,6 +182,12 @@
|
||||
<version>${tencent.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
<version>${hutool.version}</version>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
|
||||
@ -0,0 +1,20 @@
|
||||
package kim.wind.sms.aliyun.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class AlibabaConfig {
|
||||
|
||||
/** accessKey*/
|
||||
private String accessKeyId;
|
||||
/** 访问键秘钥 */
|
||||
private String accessKeySecret;
|
||||
/** 短信签名*/
|
||||
private String signature;
|
||||
/** 模板Id*/
|
||||
private String templateId;
|
||||
/** 模板变量名称*/
|
||||
private String templateName;
|
||||
/** 请求地址*/
|
||||
private String requestUrl = "dysmsapi.aliyuncs.com";
|
||||
}
|
||||
@ -13,33 +13,26 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms.alibaba") //指定配置文件注入属性前缀
|
||||
@ConditionalOnProperty(name = "sms.supplier", havingValue = "alibaba")
|
||||
public class AlibabaSmsConfig {
|
||||
|
||||
/** accessKey*/
|
||||
private String accessKeyId;
|
||||
/** 访问键秘钥 */
|
||||
private String accessKeySecret;
|
||||
/** 短信签名*/
|
||||
private String signature;
|
||||
/** 模板Id*/
|
||||
private String templateId;
|
||||
/** 模板变量名称*/
|
||||
private String templateName;
|
||||
/** 请求地址*/
|
||||
private String requestUrl = "dysmsapi.aliyuncs.com";
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "sms.alibaba") //指定配置文件注入属性前缀
|
||||
public AlibabaConfig alibabaConfig(){
|
||||
return new AlibabaConfig();
|
||||
}
|
||||
|
||||
|
||||
@Bean
|
||||
public Client client() throws Exception {
|
||||
public Client client(AlibabaConfig alibabaConfig) throws Exception {
|
||||
Config config = new Config()
|
||||
// AccessKey ID
|
||||
.setAccessKeyId(accessKeyId)
|
||||
.setAccessKeyId(alibabaConfig.getAccessKeyId())
|
||||
// AccessKey Secret
|
||||
.setAccessKeySecret(accessKeySecret);
|
||||
.setAccessKeySecret(alibabaConfig.getAccessKeySecret());
|
||||
// 访问的域名
|
||||
config.endpoint = requestUrl;
|
||||
config.endpoint = alibabaConfig.getRequestUrl();
|
||||
return new Client(config);
|
||||
}
|
||||
|
||||
|
||||
@ -8,6 +8,7 @@ import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
|
||||
import com.aliyun.dysmsapi20170525.models.SendSmsResponse;
|
||||
import com.aliyun.tea.TeaException;
|
||||
import com.aliyun.teautil.models.RuntimeOptions;
|
||||
import kim.wind.sms.aliyun.config.AlibabaConfig;
|
||||
import kim.wind.sms.aliyun.config.AlibabaSmsConfig;
|
||||
import kim.wind.sms.api.SmsBlend;
|
||||
import kim.wind.sms.api.callback.CallBack;
|
||||
@ -40,7 +41,7 @@ public class AlibabaSmsImpl implements SmsBlend {
|
||||
@Autowired
|
||||
private Client client;
|
||||
@Autowired
|
||||
private AlibabaSmsConfig alibabaSmsConfig;
|
||||
private AlibabaConfig alibabaSmsConfig;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("smsExecutor")
|
||||
|
||||
@ -1,8 +1,10 @@
|
||||
package kim.wind.sms.autoimmit.config;
|
||||
|
||||
import kim.wind.sms.autoimmit.aop.AopAdvice;
|
||||
import kim.wind.sms.comm.config.SmsBanner;
|
||||
import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.utils.RedisUtils;
|
||||
import kim.wind.sms.comm.utils.SpringUtil;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@ -14,7 +16,13 @@ import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
public class SmsAutowiredConfig {
|
||||
|
||||
@Bean(initMethod = "init")
|
||||
private final SpringUtil springUtil;
|
||||
|
||||
public SmsAutowiredConfig(SpringUtil springUtil) {
|
||||
this.springUtil = springUtil;
|
||||
}
|
||||
|
||||
@Bean("smsConfig")
|
||||
@ConfigurationProperties(prefix = "sms") //指定配置文件注入属性前缀
|
||||
public SmsConfig smsConfig(){
|
||||
return new SmsConfig();
|
||||
@ -55,6 +63,13 @@ public class SmsAutowiredConfig {
|
||||
executor.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
|
||||
//初始化线程池
|
||||
executor.initialize();
|
||||
if (config.getIsPrint()) {
|
||||
SmsBanner.PrintBanner("v1.0.3");
|
||||
}
|
||||
return executor;
|
||||
}
|
||||
|
||||
void init(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
package kim.wind.sms.autoimmit.config;
|
||||
|
||||
import kim.wind.sms.comm.config.SmsBanner;
|
||||
import kim.wind.sms.autoimmit.enumerate.ConfigType;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@ -9,6 +9,10 @@ public class SmsConfig {
|
||||
* 短信服务商
|
||||
*/
|
||||
private String supplier;
|
||||
|
||||
/** 是否使用数据库作为配置源*/
|
||||
private ConfigType configType = ConfigType.CONFIG_FILE;
|
||||
|
||||
/**
|
||||
* 打印banner
|
||||
*/
|
||||
@ -64,9 +68,5 @@ public class SmsConfig {
|
||||
*/
|
||||
private Boolean shutdownStrategy = true;
|
||||
|
||||
void init(){
|
||||
if (isPrint) {
|
||||
SmsBanner.PrintBanner("v1.0.3");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -0,0 +1,28 @@
|
||||
package kim.wind.sms.autoimmit.enumerate;
|
||||
|
||||
/**
|
||||
* ConfigType
|
||||
* <p>配置文件类型
|
||||
* @author :Wind
|
||||
* 2023/4/5 19:08
|
||||
**/
|
||||
public enum ConfigType {
|
||||
/** 配置文件*/
|
||||
CONFIG_FILE("configFile"),
|
||||
|
||||
/** 数据库配置*/
|
||||
SQL_CONFIG("sqlConfig"),
|
||||
|
||||
/** nacos配置*/
|
||||
NACOS_CONFIG("nacosConfig");
|
||||
|
||||
private final String name;
|
||||
|
||||
ConfigType(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
@ -17,10 +17,6 @@
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
@ -32,11 +28,6 @@
|
||||
<artifactId>spring-boot-starter-data-redis</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.dtflys.forest</groupId>
|
||||
<artifactId>forest-core</artifactId>
|
||||
</dependency>
|
||||
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
||||
@ -10,6 +10,7 @@ import org.springframework.context.ApplicationContextAware;
|
||||
/**
|
||||
* <p>类名: SpringUtil
|
||||
* <p>说明:spring bean工具
|
||||
*
|
||||
* @author :Wind
|
||||
* 2023/3/25 0:13
|
||||
**/
|
||||
@ -17,24 +18,27 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
|
||||
private static ApplicationContext applicationContext;
|
||||
|
||||
@Autowired
|
||||
DefaultListableBeanFactory beanFactory;
|
||||
private final DefaultListableBeanFactory beanFactory;
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if(SpringUtil.applicationContext == null) {
|
||||
SpringUtil.applicationContext = applicationContext;
|
||||
}
|
||||
public SpringUtil(DefaultListableBeanFactory beanFactory) {
|
||||
this.beanFactory = beanFactory;
|
||||
}
|
||||
|
||||
public static ApplicationContext getApplicationContext() {
|
||||
return applicationContext;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
||||
if (SpringUtil.applicationContext == null) {
|
||||
SpringUtil.applicationContext = applicationContext;
|
||||
}
|
||||
}
|
||||
|
||||
public static Object getBean(String name) {
|
||||
try {
|
||||
return getApplicationContext().getBean(name);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -43,32 +47,45 @@ public class SpringUtil implements ApplicationContextAware {
|
||||
public static <T> T getBean(Class<T> clazz) {
|
||||
try {
|
||||
return getApplicationContext().getBean(clazz);
|
||||
}catch (Exception e){
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T getBean(String name,Class<T> clazz) {
|
||||
public static <T> T getBean(String name, Class<T> clazz) {
|
||||
try {
|
||||
return getApplicationContext().getBean(name,clazz);
|
||||
}catch (Exception e){
|
||||
return null ;
|
||||
return getApplicationContext().getBean(name, clazz);
|
||||
} catch (Exception e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>说明:创建一个bean
|
||||
* @name: createBean
|
||||
*
|
||||
* @param
|
||||
* @name: createBean
|
||||
* @author :Wind
|
||||
*/
|
||||
public void createBean(Class<?>clazz){
|
||||
public void createBean(Class<?> clazz) {
|
||||
String name = clazz.getName();
|
||||
beanFactory.createBean(clazz);
|
||||
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clazz);
|
||||
beanFactory.registerBeanDefinition(name, beanDefinitionBuilder.getBeanDefinition());
|
||||
}
|
||||
public void createBean(String name,Object o){
|
||||
beanFactory.registerSingleton(name,o);
|
||||
|
||||
public void createBean(String name, Object o) {
|
||||
beanFactory.registerSingleton(name, o);
|
||||
}
|
||||
|
||||
public void replaceBean(String beanName,Class<?> clazz){
|
||||
String name = clazz.getName();
|
||||
beanFactory.removeBeanDefinition(beanName);
|
||||
beanFactory.createBean(clazz);
|
||||
BeanDefinitionBuilder beanDefinitionBuilder = BeanDefinitionBuilder.genericBeanDefinition(clazz);
|
||||
beanFactory.registerBeanDefinition(name, beanDefinitionBuilder.getBeanDefinition());
|
||||
}
|
||||
public void deleteBean(String beanName){
|
||||
beanFactory.removeBeanDefinition(beanName);
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,24 @@
|
||||
package kim.wind.sms.huawei.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class HuaweiConfig {
|
||||
|
||||
/** appKey*/
|
||||
private String appKey ;
|
||||
/** appSecret */
|
||||
private String appSecret ;
|
||||
/** 短信签名*/
|
||||
private String signature;
|
||||
/** 国内短信签名通道号*/
|
||||
private String sender;
|
||||
/** 模板Id*/
|
||||
private String templateId;
|
||||
/** 短信状态报告接收地*/
|
||||
private String statusCallBack;
|
||||
/** APP接入地址*/
|
||||
private String url;
|
||||
/** 是否打印http请求日志*/
|
||||
private Boolean httpLog = false;
|
||||
}
|
||||
@ -12,30 +12,18 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms.huawei") //指定配置文件注入属性前缀
|
||||
@ConditionalOnProperty(name = "sms.supplier", havingValue = "huawei")
|
||||
public class HuaweiSmsConfig {
|
||||
|
||||
/** appKey*/
|
||||
private String appKey ;
|
||||
/** appSecret */
|
||||
private String appSecret ;
|
||||
/** 短信签名*/
|
||||
private String signature;
|
||||
/** 国内短信签名通道号*/
|
||||
private String sender;
|
||||
/** 模板Id*/
|
||||
private String templateId;
|
||||
/** 短信状态报告接收地*/
|
||||
private String statusCallBack;
|
||||
/** APP接入地址*/
|
||||
private String url;
|
||||
/** 是否打印http请求日志*/
|
||||
private Boolean httpLog = false;
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "sms.huawei") //指定配置文件注入属性前缀
|
||||
public HuaweiConfig huaweiConfig(){
|
||||
return new HuaweiConfig();
|
||||
}
|
||||
|
||||
@Bean("forestConfiguration")
|
||||
public ForestConfiguration forestConfiguration(){
|
||||
return Forest.config().setBackendName("httpclient").setLogEnabled(httpLog);
|
||||
public ForestConfiguration forestConfiguration(HuaweiConfig huaweiConfig){
|
||||
return Forest.config().setBackendName("httpclient").setLogEnabled(huaweiConfig.getHttpLog());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@ -7,6 +7,7 @@ import kim.wind.sms.comm.annotation.Restricted;
|
||||
import kim.wind.sms.comm.constant.Constant;
|
||||
import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.entity.SmsResponse;
|
||||
import kim.wind.sms.huawei.config.HuaweiConfig;
|
||||
import kim.wind.sms.huawei.config.HuaweiSmsConfig;
|
||||
import kim.wind.sms.huawei.entity.HuaweiResponse;
|
||||
import kim.wind.sms.huawei.utils.HuaweiBuilder;
|
||||
@ -25,7 +26,7 @@ import static kim.wind.sms.comm.utils.SmsUtil.listToString;
|
||||
public class HuaweiSmsImpl implements SmsBlend {
|
||||
|
||||
@Autowired
|
||||
private HuaweiSmsConfig config;
|
||||
private HuaweiConfig config;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("smsExecutor")
|
||||
|
||||
BIN
sms-aggregation-rule-plugin/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
sms-aggregation-rule-plugin/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
18
sms-aggregation-rule-plugin/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
18
sms-aggregation-rule-plugin/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
|
||||
40
sms-aggregation-rule-plugin/pom.xml
Normal file
40
sms-aggregation-rule-plugin/pom.xml
Normal file
@ -0,0 +1,40 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>kim.wind</groupId>
|
||||
<artifactId>sms_aggregation</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>sms-aggregation-rule-plugin</artifactId>
|
||||
<version>${revision}</version>
|
||||
<name>sms-aggregation-rule-plugin</name>
|
||||
<description>sms-aggregation-rule-plugin</description>
|
||||
<properties>
|
||||
|
||||
</properties>
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</dependencyManagement>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
BIN
sms-aggregation-rule-plugin/sms-aggregation-rule-sql/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
BIN
sms-aggregation-rule-plugin/sms-aggregation-rule-sql/.mvn/wrapper/maven-wrapper.jar
vendored
Normal file
Binary file not shown.
18
sms-aggregation-rule-plugin/sms-aggregation-rule-sql/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
18
sms-aggregation-rule-plugin/sms-aggregation-rule-sql/.mvn/wrapper/maven-wrapper.properties
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
# Licensed to the Apache Software Foundation (ASF) under one
|
||||
# or more contributor license agreements. See the NOTICE file
|
||||
# distributed with this work for additional information
|
||||
# regarding copyright ownership. The ASF licenses this file
|
||||
# to you under the Apache License, Version 2.0 (the
|
||||
# "License"); you may not use this file except in compliance
|
||||
# with the License. You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing,
|
||||
# software distributed under the License is distributed on an
|
||||
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
# KIND, either express or implied. See the License for the
|
||||
# specific language governing permissions and limitations
|
||||
# under the License.
|
||||
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.7/apache-maven-3.8.7-bin.zip
|
||||
wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar
|
||||
47
sms-aggregation-rule-plugin/sms-aggregation-rule-sql/pom.xml
Normal file
47
sms-aggregation-rule-plugin/sms-aggregation-rule-sql/pom.xml
Normal file
@ -0,0 +1,47 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<parent>
|
||||
<groupId>kim.wind</groupId>
|
||||
<artifactId>sms_aggregation</artifactId>
|
||||
<version>${revision}</version>
|
||||
<relativePath>../../pom.xml</relativePath>
|
||||
</parent>
|
||||
<artifactId>sms-aggregation-rule-sql</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>sms-aggregation-rule-sql</name>
|
||||
<description>sms-aggregation-rule-sql</description>
|
||||
<properties>
|
||||
|
||||
</properties>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
<version>${spring.boot.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>cn.hutool</groupId>
|
||||
<artifactId>hutool-all</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>kim.wind</groupId>
|
||||
<artifactId>sms-aggregation-autoimmit</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>com.alibaba</groupId>
|
||||
<artifactId>fastjson</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
</project>
|
||||
@ -0,0 +1,49 @@
|
||||
package kim.wind.sms.sql;
|
||||
|
||||
import cn.hutool.core.bean.BeanUtil;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import jakarta.annotation.PostConstruct;
|
||||
import kim.wind.sms.aliyun.config.AlibabaSmsConfig;
|
||||
import kim.wind.sms.autoimmit.config.SmsConfig;
|
||||
import kim.wind.sms.autoimmit.enumerate.ConfigType;
|
||||
import kim.wind.sms.comm.utils.SpringUtil;
|
||||
import kim.wind.sms.sql.utils.JDBCTool;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
public class LoadConfigReplace {
|
||||
private final SpringUtil springUtil;
|
||||
private final SmsConfig smsConfig;
|
||||
private final JDBCTool jdbcTool;
|
||||
|
||||
public LoadConfigReplace(SpringUtil springUtil, SmsConfig smsConfig, JDBCTool jdbcTool) {
|
||||
this.springUtil = springUtil;
|
||||
this.smsConfig = smsConfig;
|
||||
this.jdbcTool = jdbcTool;
|
||||
}
|
||||
|
||||
@PostConstruct
|
||||
public void init() {
|
||||
if (smsConfig.getConfigType().equals(ConfigType.SQL_CONFIG)) {
|
||||
Map<String, String> select = jdbcTool.select();
|
||||
String key = "";
|
||||
String value = "";
|
||||
for (Map.Entry<String, String> set : select.entrySet()) {
|
||||
key = set.getKey();
|
||||
value = set.getValue();
|
||||
}
|
||||
JSONObject jsonObject = JSONObject.parseObject(value);
|
||||
switch (key){
|
||||
case "alibaba":
|
||||
AlibabaSmsConfig sqlAlibaba = JSONObject.toJavaObject(jsonObject, AlibabaSmsConfig.class);
|
||||
AlibabaSmsConfig alibabaSmsConfig = new AlibabaSmsConfig();
|
||||
BeanUtil.copyProperties(sqlAlibaba,alibabaSmsConfig);
|
||||
springUtil.deleteBean("alibabaSmsConfig");
|
||||
springUtil.createBean(alibabaSmsConfig.getClass().getName(),alibabaSmsConfig);
|
||||
break;
|
||||
}
|
||||
|
||||
springUtil.replaceBean("smsConfig", SmsConfig.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,32 @@
|
||||
package kim.wind.sms.sql.config;
|
||||
|
||||
|
||||
import kim.wind.sms.autoimmit.config.SmsConfig;
|
||||
import kim.wind.sms.comm.utils.SpringUtil;
|
||||
import kim.wind.sms.sql.utils.JDBCTool;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
|
||||
|
||||
public class SmsAutoConfig {
|
||||
|
||||
private SpringUtil springUtil;
|
||||
|
||||
private SmsConfig smsConfig;
|
||||
|
||||
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "sms.database") //指定配置文件注入属性前缀
|
||||
public SmsSqlConfig smsSqlConfig() {
|
||||
return new SmsSqlConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
@ConditionalOnBean(SmsSqlConfig.class)
|
||||
public JDBCTool jdbcTool(SmsSqlConfig smsSqlConfig) {
|
||||
return new JDBCTool(smsSqlConfig);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,66 @@
|
||||
package kim.wind.sms.sql.config;
|
||||
|
||||
|
||||
import kim.wind.sms.sql.err.SmsSqlException;
|
||||
import lombok.Data;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* SmsSqlConfig
|
||||
* <p> sql配置信息
|
||||
*
|
||||
* @author :Wind
|
||||
* 2023/4/5 18:28
|
||||
**/
|
||||
@Data
|
||||
public class SmsSqlConfig {
|
||||
|
||||
/**
|
||||
* 连接地址
|
||||
*/
|
||||
private String url;
|
||||
|
||||
/**
|
||||
* 驱动
|
||||
*/
|
||||
private String driverClassName;
|
||||
|
||||
/**
|
||||
* 账号名
|
||||
*/
|
||||
private String username;
|
||||
|
||||
/**
|
||||
* 密码
|
||||
*/
|
||||
private String password;
|
||||
|
||||
/**
|
||||
* 数据库名
|
||||
*/
|
||||
private String databaseName;
|
||||
|
||||
/**
|
||||
* 配置表 表名
|
||||
*/
|
||||
private String tableName;
|
||||
|
||||
/**
|
||||
* 启用字段名
|
||||
*/
|
||||
private String startName;
|
||||
|
||||
/**
|
||||
* 启用字段标识
|
||||
*/
|
||||
private String isStart;
|
||||
|
||||
/**
|
||||
* 配置字段名
|
||||
*/
|
||||
private String configName;
|
||||
|
||||
/** 厂商配置字段名*/
|
||||
private String supplierFieldName;
|
||||
|
||||
}
|
||||
@ -0,0 +1,20 @@
|
||||
package kim.wind.sms.sql.err;
|
||||
|
||||
public class SmsSqlException extends RuntimeException{
|
||||
private String message;
|
||||
@Override
|
||||
public String getMessage() {
|
||||
return message;
|
||||
}
|
||||
|
||||
public SmsSqlException(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置 message
|
||||
*/
|
||||
public void setMessage(String message) {
|
||||
this.message = message;
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,131 @@
|
||||
package kim.wind.sms.sql.utils;
|
||||
|
||||
import cn.hutool.core.util.StrUtil;
|
||||
import kim.wind.sms.sql.config.SmsSqlConfig;
|
||||
import kim.wind.sms.sql.err.SmsSqlException;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Hashtable;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* JDBCTool
|
||||
* <p> 数据库相关工具
|
||||
*
|
||||
* @author :Wind
|
||||
* 2023/4/4 22:34
|
||||
**/
|
||||
public class JDBCTool {
|
||||
|
||||
private final SmsSqlConfig config;
|
||||
|
||||
public static final String SELECT = "select {},{} from {} where {} = {}";
|
||||
|
||||
private static final String ERR_CONFIG = "One configuration was expected, but {} was found. Please check your database configuration";
|
||||
|
||||
|
||||
public JDBCTool(SmsSqlConfig config) {
|
||||
if (config == null){
|
||||
throw new SmsSqlException("The configuration file failed to be loaded. Procedure");
|
||||
}
|
||||
this.config = config;
|
||||
if (StringUtils.isEmpty(this.config.getDatabaseName())) {
|
||||
throw new SmsSqlException("You did not specify a database driver");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取链接
|
||||
*/
|
||||
public Connection getConn() {
|
||||
Connection connection;
|
||||
try {
|
||||
String url = config.getUrl() + "/" + config.getDatabaseName();
|
||||
connection = DriverManager.getConnection(url, config.getUsername(), config.getPassword());
|
||||
} catch (SQLException e) {
|
||||
throw new SmsSqlException(e.getMessage());
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
/**
|
||||
* select
|
||||
* <p>查询封装
|
||||
* @param sql 要查询的sql语句
|
||||
* @author :Wind
|
||||
*/
|
||||
public Map<String,String> select(String sql) {
|
||||
Connection conn = null;
|
||||
PreparedStatement preparedStatement = null;
|
||||
ResultSet resultSet = null;
|
||||
Map<String,String> map = new Hashtable<>();
|
||||
try {
|
||||
conn = getConn();
|
||||
preparedStatement = conn.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
|
||||
preparedStatement.setFetchSize(1000);
|
||||
resultSet = preparedStatement.executeQuery();
|
||||
|
||||
while (resultSet.next()) {
|
||||
String data = resultSet.getString(config.getConfigName());
|
||||
String supplier = resultSet.getString(config.getSupplierFieldName());
|
||||
map.put(supplier,data);
|
||||
}
|
||||
if (map.size() != 1){
|
||||
throw new SmsSqlException(StrUtil.format(ERR_CONFIG,String.valueOf(map.size())));
|
||||
}
|
||||
} catch (SQLException e) {
|
||||
throw new SmsSqlException(e.getMessage());
|
||||
} finally {
|
||||
close(conn, preparedStatement, resultSet);
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* close
|
||||
* <p>关闭链接方法
|
||||
*
|
||||
* @author :Wind
|
||||
*/
|
||||
private void close(Connection conn, PreparedStatement stmt, ResultSet rs) {
|
||||
// 关闭连接
|
||||
if (conn != null) {
|
||||
try {
|
||||
conn.close();
|
||||
} catch (SQLException e) {
|
||||
throw new SmsSqlException(e.getMessage());
|
||||
}
|
||||
}
|
||||
// 关闭 statement
|
||||
if (stmt != null) {
|
||||
try {
|
||||
stmt.close();
|
||||
} catch (SQLException e) {
|
||||
throw new SmsSqlException(e.getMessage());
|
||||
}
|
||||
}
|
||||
// 关闭结果集
|
||||
if (rs != null) {
|
||||
try {
|
||||
rs.close();
|
||||
} catch (SQLException e) {
|
||||
throw new SmsSqlException(e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String,String> select(){
|
||||
String format = StrUtil.format(SELECT,
|
||||
config.getConfigName(),
|
||||
config.getSupplierFieldName(),
|
||||
config.getDatabaseName(),
|
||||
config.getStartName(),
|
||||
config.getIsStart());
|
||||
return select(format);
|
||||
}
|
||||
|
||||
}
|
||||
@ -0,0 +1 @@
|
||||
|
||||
@ -3,6 +3,7 @@ package kim.wind.sms.starter.config;
|
||||
import kim.wind.sms.autoimmit.config.SmsAutowiredConfig;
|
||||
import kim.wind.sms.comm.utils.SpringUtil;
|
||||
import lombok.Data;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
@ -13,14 +14,14 @@ import org.springframework.scheduling.annotation.EnableAsync;
|
||||
public class SmsMainConfig {
|
||||
|
||||
@Bean
|
||||
public SpringUtil springUtil(){
|
||||
return new SpringUtil();
|
||||
public SpringUtil springUtil(DefaultListableBeanFactory defaultListableBeanFactory){
|
||||
return new SpringUtil(defaultListableBeanFactory);
|
||||
}
|
||||
|
||||
/** 主要配置注入*/
|
||||
@Bean
|
||||
public SmsAutowiredConfig smsAutowiredConfig(){
|
||||
return new SmsAutowiredConfig();
|
||||
public SmsAutowiredConfig smsAutowiredConfig(SpringUtil springUtil){
|
||||
return new SmsAutowiredConfig(springUtil);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
kim.wind.sms.starter.config.SmsMainConfig
|
||||
kim.wind.sms.autoimmit.config.SmsAutowiredConfig
|
||||
kim.wind.sms.starter.config.SmsMainConfig
|
||||
kim.wind.sms.autoimmit.config.SmsAutowiredConfig
|
||||
kim.wind.sms.aliyun.config.AlibabaSmsConfig
|
||||
kim.wind.sms.huawei.config.HuaweiSmsConfig
|
||||
kim.wind.sms.tencent.config.TencentSmsConfig
|
||||
|
||||
@ -0,0 +1,27 @@
|
||||
package kim.wind.sms.tencent.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class TencentConfig {
|
||||
/** 应用accessKey*/
|
||||
private String accessKeyId;
|
||||
/**
|
||||
* 访问键秘钥
|
||||
*/
|
||||
private String accessKeySecret;
|
||||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private String signature;
|
||||
/**
|
||||
* 模板Id
|
||||
*/
|
||||
private String templateId;
|
||||
/** 短信sdkAppId*/
|
||||
private String sdkAppId;
|
||||
/** 地域信息默认为 ap-guangzhou*/
|
||||
private String territory ="ap-guangzhou";
|
||||
/**请求超时时间 */
|
||||
private Integer connTimeout = 60;
|
||||
}
|
||||
@ -14,42 +14,26 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms.tencent") //指定配置文件注入属性前缀
|
||||
@ConditionalOnProperty(name = "sms.supplier", havingValue = "tencent")
|
||||
public class TencentSmsConfig {
|
||||
|
||||
/** 应用accessKey*/
|
||||
private String accessKeyId;
|
||||
/**
|
||||
* 访问键秘钥
|
||||
*/
|
||||
private String accessKeySecret;
|
||||
/**
|
||||
* 短信签名
|
||||
*/
|
||||
private String signature;
|
||||
/**
|
||||
* 模板Id
|
||||
*/
|
||||
private String templateId;
|
||||
/** 短信sdkAppId*/
|
||||
private String sdkAppId;
|
||||
/** 地域信息默认为 ap-guangzhou*/
|
||||
private String territory ="ap-guangzhou";
|
||||
/**请求超时时间 */
|
||||
private Integer connTimeout = 60;
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "sms.tencent") //指定配置文件注入属性前缀
|
||||
public TencentConfig tencentConfig(){
|
||||
return new TencentConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SmsClient tencentBean() {
|
||||
Credential cred = new Credential(accessKeyId, accessKeySecret);
|
||||
public SmsClient tencentBean( TencentConfig tencentConfig) {
|
||||
Credential cred = new Credential(tencentConfig.getAccessKeyId(),tencentConfig.getAccessKeySecret());
|
||||
HttpProfile httpProfile = new HttpProfile();
|
||||
httpProfile.setReqMethod("POST");
|
||||
httpProfile.setConnTimeout(connTimeout);
|
||||
httpProfile.setConnTimeout(tencentConfig.getConnTimeout());
|
||||
httpProfile.setEndpoint("sms.tencentcloudapi.com");
|
||||
ClientProfile clientProfile = new ClientProfile();
|
||||
clientProfile.setSignMethod("HmacSHA256");
|
||||
clientProfile.setHttpProfile(httpProfile);
|
||||
return new SmsClient(cred, territory,clientProfile);
|
||||
return new SmsClient(cred, tencentConfig.getTerritory(),clientProfile);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@ -12,6 +12,7 @@ import kim.wind.sms.comm.annotation.Restricted;
|
||||
import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.entity.SmsResponse;
|
||||
import kim.wind.sms.comm.exception.SmsBlendException;
|
||||
import kim.wind.sms.tencent.config.TencentConfig;
|
||||
import kim.wind.sms.tencent.config.TencentSmsConfig;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@ -22,7 +23,7 @@ import java.util.concurrent.Executor;
|
||||
public class TencentSmsImpl implements SmsBlend {
|
||||
|
||||
@Autowired
|
||||
private TencentSmsConfig tencentSmsConfig;
|
||||
private TencentConfig tencentSmsConfig;
|
||||
|
||||
@Autowired
|
||||
private SmsClient client;
|
||||
|
||||
@ -0,0 +1,19 @@
|
||||
package kim.wind.sms.unisms.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class UniConfig {
|
||||
/** 访问键标识*/
|
||||
private String accessKeyId;
|
||||
/** 访问键秘钥 简易模式不需要配置*/
|
||||
private String accessKeySecret;
|
||||
/** 是否为简易模式*/
|
||||
private String isSimple = "true";
|
||||
/** 短信签名*/
|
||||
private String signature;
|
||||
/** 模板Id*/
|
||||
private String templateId;
|
||||
/** 模板变量名称*/
|
||||
private String templateName;
|
||||
}
|
||||
@ -11,30 +11,22 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms.uni-sms") //指定配置文件注入属性前缀
|
||||
@ConditionalOnProperty(name = "sms.supplier", havingValue = "uniSms")
|
||||
public class UniSmsConfig {
|
||||
|
||||
/** 访问键标识*/
|
||||
private String accessKeyId;
|
||||
/** 访问键秘钥 简易模式不需要配置*/
|
||||
private String accessKeySecret;
|
||||
/** 是否为简易模式*/
|
||||
private String isSimple = "true";
|
||||
/** 短信签名*/
|
||||
private String signature;
|
||||
/** 模板Id*/
|
||||
private String templateId;
|
||||
/** 模板变量名称*/
|
||||
private String templateName;
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = "sms.uni-sms") //指定配置文件注入属性前缀
|
||||
public UniConfig uniConfig(){
|
||||
return new UniConfig();
|
||||
}
|
||||
|
||||
/** 自动注入短信配置*/
|
||||
@Bean
|
||||
public void buildSms(){
|
||||
if ("true".equals(isSimple)){
|
||||
Uni.init(accessKeyId);
|
||||
public void buildSms(UniConfig uniConfig){
|
||||
if ("true".equals(uniConfig.getIsSimple())){
|
||||
Uni.init(uniConfig.getAccessKeyId());
|
||||
}else {
|
||||
Uni.init(accessKeyId,accessKeySecret);
|
||||
Uni.init(uniConfig.getAccessKeyId(),uniConfig.getAccessKeySecret());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.entity.SmsResponse;
|
||||
import kim.wind.sms.comm.exception.SmsBlendException;
|
||||
import kim.wind.sms.comm.utils.http.HttpJsonTool;
|
||||
import kim.wind.sms.unisms.config.UniConfig;
|
||||
import kim.wind.sms.unisms.config.UniSmsConfig;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
@ -34,7 +35,7 @@ import java.util.concurrent.Executor;
|
||||
public class UniSmsImpl implements SmsBlend {
|
||||
|
||||
@Autowired
|
||||
private UniSmsConfig config;
|
||||
private UniConfig config;
|
||||
|
||||
@Autowired
|
||||
@Qualifier("smsExecutor")
|
||||
|
||||
@ -12,37 +12,18 @@ import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Data
|
||||
@Configuration
|
||||
@ConfigurationProperties(prefix = "sms.yunpian") //指定配置文件注入属性前缀
|
||||
@ConditionalOnProperty(name = "sms.supplier", havingValue = "yunpian")
|
||||
public class YunPianSmsConfig {
|
||||
/**
|
||||
* 账号唯一标识
|
||||
*/
|
||||
private String apikey;
|
||||
|
||||
/**
|
||||
* 短信发送后将向这个地址推送(运营商返回的)发送报告
|
||||
*/
|
||||
private String callbackUrl;
|
||||
|
||||
/**
|
||||
* 模板Id
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板变量名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 是否打印http请求日志
|
||||
*/
|
||||
private Boolean httpLog = false;
|
||||
|
||||
@Bean
|
||||
public ForestConfiguration forestConfiguration() {
|
||||
return Forest.config().setBackendName("httpclient").setLogEnabled(httpLog);
|
||||
@ConfigurationProperties(prefix = "sms.yunpian") //指定配置文件注入属性前缀
|
||||
public YunpianConfig yunpianConfig(){
|
||||
return new YunpianConfig();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public ForestConfiguration forestConfiguration(YunpianConfig yunpianConfig) {
|
||||
return Forest.config().setBackendName("httpclient").setLogEnabled(yunpianConfig.getHttpLog());
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@ -0,0 +1,31 @@
|
||||
package kim.wind.sms.yunpian.config;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class YunpianConfig {
|
||||
/**
|
||||
* 账号唯一标识
|
||||
*/
|
||||
private String apikey;
|
||||
|
||||
/**
|
||||
* 短信发送后将向这个地址推送(运营商返回的)发送报告
|
||||
*/
|
||||
private String callbackUrl;
|
||||
|
||||
/**
|
||||
* 模板Id
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板变量名称
|
||||
*/
|
||||
private String templateName;
|
||||
|
||||
/**
|
||||
* 是否打印http请求日志
|
||||
*/
|
||||
private Boolean httpLog = false;
|
||||
}
|
||||
@ -10,6 +10,7 @@ import kim.wind.sms.comm.delayedTime.DelayedTime;
|
||||
import kim.wind.sms.comm.entity.SmsResponse;
|
||||
import kim.wind.sms.comm.exception.SmsBlendException;
|
||||
import kim.wind.sms.yunpian.config.YunPianSmsConfig;
|
||||
import kim.wind.sms.yunpian.config.YunpianConfig;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Qualifier;
|
||||
@ -30,7 +31,7 @@ public class YunPianSmsImpl implements SmsBlend {
|
||||
private DelayedTime delayed;
|
||||
|
||||
@Autowired
|
||||
private YunPianSmsConfig config;
|
||||
private YunpianConfig config;
|
||||
|
||||
@Autowired
|
||||
private ForestConfiguration http;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user