mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
修复:java se对于网易云短信的配置支持
添加: 1.增加创建并加入负载器方法 2.SupplierFactory的set方法将自动创建并添加至负载器 3.添加助通短信的se适配 优化: spring不再注入未配置的bean
This commit is contained in:
parent
883f56f348
commit
61336f3145
@ -1,5 +1,6 @@
|
|||||||
package org.dromara.sms4j.comm.config;
|
package org.dromara.sms4j.comm.config;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.NoArgsConstructor;
|
import lombok.NoArgsConstructor;
|
||||||
import lombok.experimental.SuperBuilder;
|
import lombok.experimental.SuperBuilder;
|
||||||
@ -34,4 +35,10 @@ public class BaseConfig {
|
|||||||
* 模板 ID
|
* 模板 ID
|
||||||
*/
|
*/
|
||||||
private String templateId;
|
private String templateId;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 权重
|
||||||
|
* */
|
||||||
|
@Builder.Default
|
||||||
|
private Integer weight = 1;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,36 @@
|
|||||||
|
package org.dromara.sms4j.core;
|
||||||
|
|
||||||
|
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||||
|
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||||
|
|
||||||
|
import java.lang.reflect.Field;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class ReflectUtil {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 反射获取接口对象的原类名
|
||||||
|
*/
|
||||||
|
public static String getObjectName(SupplierConfig parameter) {
|
||||||
|
return parameter.getClass().getTypeName();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 将对象的属性和属性值变为map
|
||||||
|
* */
|
||||||
|
public static Map<String, String> getValues(SupplierConfig parameter) {
|
||||||
|
try {
|
||||||
|
Map<String ,String> map = new HashMap<>();
|
||||||
|
Class<?> clazz = Class.forName(getObjectName(parameter));
|
||||||
|
Field[] declaredFields = clazz.getDeclaredFields();
|
||||||
|
for (Field declaredField : declaredFields) {
|
||||||
|
declaredField.setAccessible(true);
|
||||||
|
map.put(declaredField.getName(), (String) declaredField.get(parameter));
|
||||||
|
}
|
||||||
|
return map;
|
||||||
|
} catch (Exception e) {
|
||||||
|
throw new SmsBlendException(e.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -7,6 +7,7 @@ import org.dromara.sms4j.cloopen.config.CloopenConfig;
|
|||||||
import org.dromara.sms4j.cloopen.config.CloopenFactory;
|
import org.dromara.sms4j.cloopen.config.CloopenFactory;
|
||||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||||
|
import org.dromara.sms4j.core.load.SmsLoad;
|
||||||
import org.dromara.sms4j.ctyun.config.CtyunConfig;
|
import org.dromara.sms4j.ctyun.config.CtyunConfig;
|
||||||
import org.dromara.sms4j.ctyun.config.CtyunFactory;
|
import org.dromara.sms4j.ctyun.config.CtyunFactory;
|
||||||
import org.dromara.sms4j.emay.config.EmayConfig;
|
import org.dromara.sms4j.emay.config.EmayConfig;
|
||||||
@ -141,6 +142,8 @@ public class SupplierFactory {
|
|||||||
setCtyunConfig((CtyunConfig) t);
|
setCtyunConfig((CtyunConfig) t);
|
||||||
} else if (t instanceof NeteaseConfig) {
|
} else if (t instanceof NeteaseConfig) {
|
||||||
setNeteaseConfig((NeteaseConfig) t);
|
setNeteaseConfig((NeteaseConfig) t);
|
||||||
|
} else if (t instanceof ZhutongConfig) {
|
||||||
|
setZhuTongConfig((ZhutongConfig) t);
|
||||||
} else {
|
} else {
|
||||||
throw new SmsBlendException("Loading failure! Please check the configuration type.");
|
throw new SmsBlendException("Loading failure! Please check the configuration type.");
|
||||||
}
|
}
|
||||||
@ -152,6 +155,7 @@ public class SupplierFactory {
|
|||||||
public static void setAlibabaConfig(AlibabaConfig alibabaConfig) {
|
public static void setAlibabaConfig(AlibabaConfig alibabaConfig) {
|
||||||
AlibabaFactory.instance().setConfig(alibabaConfig);
|
AlibabaFactory.instance().setConfig(alibabaConfig);
|
||||||
SmsFactory.refresh(SupplierType.ALIBABA);
|
SmsFactory.refresh(SupplierType.ALIBABA);
|
||||||
|
SmsLoad.starConfig(alibabaConfig,SupplierType.ALIBABA);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -160,6 +164,7 @@ public class SupplierFactory {
|
|||||||
public static void setHuaweiConfig(HuaweiConfig huaweiConfig) {
|
public static void setHuaweiConfig(HuaweiConfig huaweiConfig) {
|
||||||
HuaweiFactory.instance().setConfig(huaweiConfig);
|
HuaweiFactory.instance().setConfig(huaweiConfig);
|
||||||
SmsFactory.refresh(SupplierType.HUAWEI);
|
SmsFactory.refresh(SupplierType.HUAWEI);
|
||||||
|
SmsLoad.starConfig(huaweiConfig,SupplierType.HUAWEI);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -168,6 +173,7 @@ public class SupplierFactory {
|
|||||||
public static void setUniConfig(UniConfig uniConfig) {
|
public static void setUniConfig(UniConfig uniConfig) {
|
||||||
UniFactory.instance().setConfig(uniConfig);
|
UniFactory.instance().setConfig(uniConfig);
|
||||||
SmsFactory.refresh(SupplierType.UNI_SMS);
|
SmsFactory.refresh(SupplierType.UNI_SMS);
|
||||||
|
SmsLoad.starConfig(uniConfig,SupplierType.UNI_SMS);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -176,6 +182,7 @@ public class SupplierFactory {
|
|||||||
public static void setTencentConfig(TencentConfig tencentConfig) {
|
public static void setTencentConfig(TencentConfig tencentConfig) {
|
||||||
TencentFactory.instance().setConfig(tencentConfig);
|
TencentFactory.instance().setConfig(tencentConfig);
|
||||||
SmsFactory.refresh(SupplierType.TENCENT);
|
SmsFactory.refresh(SupplierType.TENCENT);
|
||||||
|
SmsLoad.starConfig(tencentConfig,SupplierType.TENCENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -184,6 +191,7 @@ public class SupplierFactory {
|
|||||||
public static void setYunpianConfig(YunpianConfig yunpianConfig) {
|
public static void setYunpianConfig(YunpianConfig yunpianConfig) {
|
||||||
YunPianFactory.instance().setConfig(yunpianConfig);
|
YunPianFactory.instance().setConfig(yunpianConfig);
|
||||||
SmsFactory.refresh(SupplierType.YUNPIAN);
|
SmsFactory.refresh(SupplierType.YUNPIAN);
|
||||||
|
SmsLoad.starConfig(yunpianConfig,SupplierType.YUNPIAN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -192,6 +200,7 @@ public class SupplierFactory {
|
|||||||
public static void setJdCloudConfig(JdCloudConfig jdCloudConfig) {
|
public static void setJdCloudConfig(JdCloudConfig jdCloudConfig) {
|
||||||
JdCloudFactory.instance().setConfig(jdCloudConfig);
|
JdCloudFactory.instance().setConfig(jdCloudConfig);
|
||||||
SmsFactory.refresh(SupplierType.JD_CLOUD);
|
SmsFactory.refresh(SupplierType.JD_CLOUD);
|
||||||
|
SmsLoad.starConfig(jdCloudConfig,SupplierType.JD_CLOUD);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -200,6 +209,7 @@ public class SupplierFactory {
|
|||||||
public static void setCloopenConfig(CloopenConfig cloopenConfig) {
|
public static void setCloopenConfig(CloopenConfig cloopenConfig) {
|
||||||
CloopenFactory.instance().setConfig(cloopenConfig);
|
CloopenFactory.instance().setConfig(cloopenConfig);
|
||||||
SmsFactory.refresh(SupplierType.CLOOPEN);
|
SmsFactory.refresh(SupplierType.CLOOPEN);
|
||||||
|
SmsLoad.starConfig(cloopenConfig,SupplierType.CLOOPEN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -208,6 +218,7 @@ public class SupplierFactory {
|
|||||||
public static void setEmayConfig(EmayConfig emayConfig) {
|
public static void setEmayConfig(EmayConfig emayConfig) {
|
||||||
EmayFactory.instance().setConfig(emayConfig);
|
EmayFactory.instance().setConfig(emayConfig);
|
||||||
SmsFactory.refresh(SupplierType.EMAY);
|
SmsFactory.refresh(SupplierType.EMAY);
|
||||||
|
SmsLoad.starConfig(emayConfig,SupplierType.EMAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -216,6 +227,7 @@ public class SupplierFactory {
|
|||||||
public static void setCtyunConfig(CtyunConfig ctyunConfig) {
|
public static void setCtyunConfig(CtyunConfig ctyunConfig) {
|
||||||
CtyunFactory.instance().setConfig(ctyunConfig);
|
CtyunFactory.instance().setConfig(ctyunConfig);
|
||||||
SmsFactory.refresh(SupplierType.CTYUN);
|
SmsFactory.refresh(SupplierType.CTYUN);
|
||||||
|
SmsLoad.starConfig(ctyunConfig,SupplierType.CTYUN);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -224,5 +236,12 @@ public class SupplierFactory {
|
|||||||
public static void setNeteaseConfig(NeteaseConfig neteaseConfig) {
|
public static void setNeteaseConfig(NeteaseConfig neteaseConfig) {
|
||||||
NeteaseFactory.instance().setConfig(neteaseConfig);
|
NeteaseFactory.instance().setConfig(neteaseConfig);
|
||||||
SmsFactory.refresh(SupplierType.NETEASE);
|
SmsFactory.refresh(SupplierType.NETEASE);
|
||||||
|
SmsLoad.starConfig(neteaseConfig,SupplierType.NETEASE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setZhuTongConfig(ZhutongConfig zhutongConfig){
|
||||||
|
ZhutongFactory.instance().setConfig(zhutongConfig);
|
||||||
|
SmsFactory.refresh(SupplierType.ZHUTONG);
|
||||||
|
SmsLoad.starConfig(zhutongConfig,SupplierType.ZHUTONG);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,9 +1,17 @@
|
|||||||
package org.dromara.sms4j.core.load;
|
package org.dromara.sms4j.core.load;
|
||||||
|
|
||||||
import org.dromara.sms4j.api.SmsBlend;
|
import org.dromara.sms4j.api.SmsBlend;
|
||||||
|
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||||
|
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||||
|
import org.dromara.sms4j.core.ReflectUtil;
|
||||||
|
import org.dromara.sms4j.core.config.SupplierFactory;
|
||||||
|
import org.dromara.sms4j.provider.base.BaseProviderFactory;
|
||||||
|
import org.dromara.sms4j.provider.enumerate.SupplierType;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* SmsLoad
|
* SmsLoad
|
||||||
@ -15,6 +23,9 @@ public class SmsLoad {
|
|||||||
// 服务器列表,每个服务器有一个权重和当前权重
|
// 服务器列表,每个服务器有一个权重和当前权重
|
||||||
private static final List<LoadServer> LoadServers = new ArrayList<>();
|
private static final List<LoadServer> LoadServers = new ArrayList<>();
|
||||||
|
|
||||||
|
// 实例列表
|
||||||
|
private static final Map<Object, SmsBlend> smsBlendMap = new HashMap<>();
|
||||||
|
|
||||||
private SmsLoad() {
|
private SmsLoad() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -51,7 +62,7 @@ public class SmsLoad {
|
|||||||
* @return SmsBlend 短信实现
|
* @return SmsBlend 短信实现
|
||||||
* @author :Wind
|
* @author :Wind
|
||||||
*/
|
*/
|
||||||
public static SmsBlend getLoadServer() {
|
public synchronized static SmsBlend getLoadServer() {
|
||||||
int totalWeight = 0;
|
int totalWeight = 0;
|
||||||
LoadServer selectedLoadServer = null;
|
LoadServer selectedLoadServer = null;
|
||||||
// 计算所有服务器的权重总和,并选择当前权重最大的服务器
|
// 计算所有服务器的权重总和,并选择当前权重最大的服务器
|
||||||
@ -72,5 +83,18 @@ public class SmsLoad {
|
|||||||
selectedLoadServer.setCurrentWeight(i);
|
selectedLoadServer.setCurrentWeight(i);
|
||||||
return selectedLoadServer.getSmsServer();
|
return selectedLoadServer.getSmsServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* starConfig
|
||||||
|
* <p> 创建smsBlend并加入到负载均衡器
|
||||||
|
* @param supplierConfig 厂商配置
|
||||||
|
* @param supplierType 厂商枚举
|
||||||
|
* @author :Wind
|
||||||
|
*/
|
||||||
|
public static void starConfig(SupplierConfig supplierConfig, SupplierType supplierType){
|
||||||
|
BaseProviderFactory providerFactory = supplierType.getProviderFactory();
|
||||||
|
SmsBlend smsBlend = providerFactory.createMultitonSms(supplierConfig);
|
||||||
|
addLoadServer(smsBlend, Integer.parseInt(ReflectUtil.getValues(supplierConfig).get("weight")));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -17,9 +17,11 @@ import org.dromara.sms4j.emay.config.EmayConfig;
|
|||||||
import org.dromara.sms4j.huawei.config.HuaweiConfig;
|
import org.dromara.sms4j.huawei.config.HuaweiConfig;
|
||||||
import org.dromara.sms4j.javase.util.YamlUtil;
|
import org.dromara.sms4j.javase.util.YamlUtil;
|
||||||
import org.dromara.sms4j.jdcloud.config.JdCloudConfig;
|
import org.dromara.sms4j.jdcloud.config.JdCloudConfig;
|
||||||
|
import org.dromara.sms4j.netease.config.NeteaseConfig;
|
||||||
import org.dromara.sms4j.tencent.config.TencentConfig;
|
import org.dromara.sms4j.tencent.config.TencentConfig;
|
||||||
import org.dromara.sms4j.unisms.config.UniConfig;
|
import org.dromara.sms4j.unisms.config.UniConfig;
|
||||||
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
||||||
|
import org.dromara.sms4j.zhutong.config.ZhutongConfig;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化类
|
* 初始化类
|
||||||
@ -35,6 +37,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化短信公共配置
|
* 初始化短信公共配置
|
||||||
|
*
|
||||||
* @param smsConfig 短信公共配置
|
* @param smsConfig 短信公共配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -45,6 +48,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化阿里配置
|
* 初始化阿里配置
|
||||||
|
*
|
||||||
* @param alibabaConfig 阿里配置
|
* @param alibabaConfig 阿里配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -55,6 +59,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化容连云配置
|
* 初始化容连云配置
|
||||||
|
*
|
||||||
* @param cloopenConfig 容连云配置
|
* @param cloopenConfig 容连云配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -65,6 +70,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化亿美软通配置
|
* 初始化亿美软通配置
|
||||||
|
*
|
||||||
* @param emayConfig 亿美软通配置
|
* @param emayConfig 亿美软通配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -75,6 +81,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化华为配置
|
* 初始化华为配置
|
||||||
|
*
|
||||||
* @param huaweiConfig 华为配置
|
* @param huaweiConfig 华为配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -85,6 +92,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化京东配置
|
* 初始化京东配置
|
||||||
|
*
|
||||||
* @param jdCloudConfig 京东配置
|
* @param jdCloudConfig 京东配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -95,6 +103,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化腾讯配置
|
* 初始化腾讯配置
|
||||||
|
*
|
||||||
* @param tencentConfig 腾讯配置
|
* @param tencentConfig 腾讯配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -105,6 +114,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化合一配置
|
* 初始化合一配置
|
||||||
|
*
|
||||||
* @param uniConfig 合一配置
|
* @param uniConfig 合一配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -115,6 +125,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 初始化云片配置
|
* 初始化云片配置
|
||||||
|
*
|
||||||
* @param yunpianConfig 云片配置
|
* @param yunpianConfig 云片配置
|
||||||
* @return 当前初始化类实例
|
* @return 当前初始化类实例
|
||||||
*/
|
*/
|
||||||
@ -123,8 +134,33 @@ public class SEInitializer {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initializer
|
||||||
|
* <p>初始化网易云短信配置
|
||||||
|
*
|
||||||
|
* @return 当前初始化类实例
|
||||||
|
* @author :Wind
|
||||||
|
*/
|
||||||
|
public SEInitializer initNetase(NeteaseConfig neteaseConfig) {
|
||||||
|
BeanUtil.copyProperties(neteaseConfig, SupplierFactory.getNeteaseConfig());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* initZhuTong
|
||||||
|
* <p>初始化助通短信配置
|
||||||
|
*
|
||||||
|
* @return 当前初始化类实例
|
||||||
|
* @author :Wind
|
||||||
|
*/
|
||||||
|
public SEInitializer initZhuTong(ZhutongConfig zhutongConfig) {
|
||||||
|
BeanUtil.copyProperties(zhutongConfig, SupplierFactory.getZhutongConfig());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 默认从sms-aggregation.yml文件中读取配置
|
* 默认从sms-aggregation.yml文件中读取配置
|
||||||
|
*
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public void fromYaml() {
|
public void fromYaml() {
|
||||||
@ -134,6 +170,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从yaml中读取配置
|
* 从yaml中读取配置
|
||||||
|
*
|
||||||
* @param yaml yaml配置字符串
|
* @param yaml yaml配置字符串
|
||||||
*/
|
*/
|
||||||
public void fromYaml(String yaml) {
|
public void fromYaml(String yaml) {
|
||||||
@ -143,6 +180,7 @@ public class SEInitializer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 从json中读取配置
|
* 从json中读取配置
|
||||||
|
*
|
||||||
* @param json json配置字符串
|
* @param json json配置字符串
|
||||||
*/
|
*/
|
||||||
public void fromJson(String json) {
|
public void fromJson(String json) {
|
||||||
@ -194,6 +232,14 @@ public class SEInitializer {
|
|||||||
if (yunpianConfig != null) {
|
if (yunpianConfig != null) {
|
||||||
this.initYunpian(yunpianConfig);
|
this.initYunpian(yunpianConfig);
|
||||||
}
|
}
|
||||||
|
NeteaseConfig neteaseConfig = smsConfig.getNeteaseConfig();
|
||||||
|
if (neteaseConfig != null){
|
||||||
|
this.initNetase(neteaseConfig);
|
||||||
|
}
|
||||||
|
ZhutongConfig zhutongConfig = smsConfig.getZhutongConfig();
|
||||||
|
if (zhutongConfig != null){
|
||||||
|
this.initZhuTong(zhutongConfig);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -221,6 +267,8 @@ public class SEInitializer {
|
|||||||
private TencentConfig tencent;
|
private TencentConfig tencent;
|
||||||
private UniConfig uni;
|
private UniConfig uni;
|
||||||
private YunpianConfig yunpian;
|
private YunpianConfig yunpian;
|
||||||
|
private NeteaseConfig neteaseConfig;
|
||||||
|
private ZhutongConfig zhutongConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,15 +12,19 @@ import org.dromara.sms4j.tencent.config.TencentConfig;
|
|||||||
import org.dromara.sms4j.unisms.config.UniConfig;
|
import org.dromara.sms4j.unisms.config.UniConfig;
|
||||||
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
||||||
import org.dromara.sms4j.zhutong.config.ZhutongConfig;
|
import org.dromara.sms4j.zhutong.config.ZhutongConfig;
|
||||||
|
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
|
|
||||||
|
import javax.annotation.PostConstruct;
|
||||||
|
|
||||||
public class SupplierConfig {
|
public class SupplierConfig {
|
||||||
|
|
||||||
|
|
||||||
/** 阿里差异化配置*/
|
/** 阿里差异化配置*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.alibaba")
|
@ConfigurationProperties(prefix = "sms.alibaba")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "alibaba")
|
||||||
protected AlibabaConfig alibabaConfig(){
|
protected AlibabaConfig alibabaConfig(){
|
||||||
return SupplierFactory.getAlibabaConfig();
|
return SupplierFactory.getAlibabaConfig();
|
||||||
}
|
}
|
||||||
@ -28,6 +32,7 @@ public class SupplierConfig {
|
|||||||
/** 华为差异化配置*/
|
/** 华为差异化配置*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.huawei")
|
@ConfigurationProperties(prefix = "sms.huawei")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "huawei")
|
||||||
protected HuaweiConfig huaweiConfig(){
|
protected HuaweiConfig huaweiConfig(){
|
||||||
return SupplierFactory.getHuaweiConfig();
|
return SupplierFactory.getHuaweiConfig();
|
||||||
}
|
}
|
||||||
@ -35,6 +40,7 @@ public class SupplierConfig {
|
|||||||
/** 云片短信差异化配置*/
|
/** 云片短信差异化配置*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.yunpian")
|
@ConfigurationProperties(prefix = "sms.yunpian")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "yunpian")
|
||||||
protected YunpianConfig yunpianConfig(){
|
protected YunpianConfig yunpianConfig(){
|
||||||
return SupplierFactory.getYunpianConfig();
|
return SupplierFactory.getYunpianConfig();
|
||||||
}
|
}
|
||||||
@ -42,6 +48,7 @@ public class SupplierConfig {
|
|||||||
/** 合一短信差异化配置*/
|
/** 合一短信差异化配置*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.uni")
|
@ConfigurationProperties(prefix = "sms.uni")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "uni")
|
||||||
protected UniConfig uniConfig(){
|
protected UniConfig uniConfig(){
|
||||||
return SupplierFactory.getUniConfig();
|
return SupplierFactory.getUniConfig();
|
||||||
}
|
}
|
||||||
@ -49,6 +56,7 @@ public class SupplierConfig {
|
|||||||
/** 腾讯短信差异化配置*/
|
/** 腾讯短信差异化配置*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.tencent")
|
@ConfigurationProperties(prefix = "sms.tencent")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "tencent")
|
||||||
protected TencentConfig tencentConfig(){
|
protected TencentConfig tencentConfig(){
|
||||||
return SupplierFactory.getTencentConfig();
|
return SupplierFactory.getTencentConfig();
|
||||||
}
|
}
|
||||||
@ -56,6 +64,7 @@ public class SupplierConfig {
|
|||||||
/** 京东云短信差异化配置 */
|
/** 京东云短信差异化配置 */
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.jdcloud")
|
@ConfigurationProperties(prefix = "sms.jdcloud")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "jdcloud")
|
||||||
protected JdCloudConfig jdCloudConfig(){
|
protected JdCloudConfig jdCloudConfig(){
|
||||||
return SupplierFactory.getJdCloudConfig();
|
return SupplierFactory.getJdCloudConfig();
|
||||||
}
|
}
|
||||||
@ -63,6 +72,7 @@ public class SupplierConfig {
|
|||||||
/** 容联云短信差异化配置 */
|
/** 容联云短信差异化配置 */
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.cloopen")
|
@ConfigurationProperties(prefix = "sms.cloopen")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "cloopen")
|
||||||
protected CloopenConfig cloopenConfig(){
|
protected CloopenConfig cloopenConfig(){
|
||||||
return SupplierFactory.getCloopenConfig();
|
return SupplierFactory.getCloopenConfig();
|
||||||
}
|
}
|
||||||
@ -72,6 +82,7 @@ public class SupplierConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.emay")
|
@ConfigurationProperties(prefix = "sms.emay")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "emay")
|
||||||
protected EmayConfig emayConfig(){
|
protected EmayConfig emayConfig(){
|
||||||
return SupplierFactory.getEmayConfig();
|
return SupplierFactory.getEmayConfig();
|
||||||
}
|
}
|
||||||
@ -81,6 +92,7 @@ public class SupplierConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.ctyun")
|
@ConfigurationProperties(prefix = "sms.ctyun")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "ctyun")
|
||||||
protected CtyunConfig ctyunConfig(){
|
protected CtyunConfig ctyunConfig(){
|
||||||
return SupplierFactory.getCtyunConfig();
|
return SupplierFactory.getCtyunConfig();
|
||||||
}
|
}
|
||||||
@ -91,6 +103,7 @@ public class SupplierConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.netease")
|
@ConfigurationProperties(prefix = "sms.netease")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "netease")
|
||||||
protected NeteaseConfig neteaseConfig(){
|
protected NeteaseConfig neteaseConfig(){
|
||||||
return SupplierFactory.getNeteaseConfig();
|
return SupplierFactory.getNeteaseConfig();
|
||||||
}
|
}
|
||||||
@ -100,7 +113,13 @@ public class SupplierConfig {
|
|||||||
*/
|
*/
|
||||||
@Bean
|
@Bean
|
||||||
@ConfigurationProperties(prefix = "sms.zhutong")
|
@ConfigurationProperties(prefix = "sms.zhutong")
|
||||||
|
@ConditionalOnProperty(prefix = "sms", name = "zhutong")
|
||||||
protected ZhutongConfig zhutongConfig(){
|
protected ZhutongConfig zhutongConfig(){
|
||||||
return SupplierFactory.getZhutongConfig();
|
return SupplierFactory.getZhutongConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@PostConstruct
|
||||||
|
protected void init(){
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,6 +7,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
|||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p>类名: SmsSpringUtil
|
* <p>类名: SmsSpringUtil
|
||||||
* <p>说明:spring bean工具
|
* <p>说明:spring bean工具
|
||||||
@ -99,4 +101,8 @@ public class SmsSpringUtil implements ApplicationContextAware {
|
|||||||
public static boolean interfaceExist(Class<?>interfaceType) {
|
public static boolean interfaceExist(Class<?>interfaceType) {
|
||||||
return !applicationContext.getBeansOfType(interfaceType).isEmpty();
|
return !applicationContext.getBeansOfType(interfaceType).isEmpty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public <T> Map<String, T> getBeansOfType(Class<T> interfaceType) {
|
||||||
|
return applicationContext.getBeansOfType(interfaceType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user