mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-07 01:18:33 +08:00
手动通过接口获取配置信息
This commit is contained in:
parent
3f772b070f
commit
e7cbf70fdd
@ -33,6 +33,7 @@ public class MailFactory{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* createMailClient
|
* createMailClient
|
||||||
* <p>从工厂获取一个邮件发送实例,该实例发送短信将依照黑名单中的数据进行过滤
|
* <p>从工厂获取一个邮件发送实例,该实例发送短信将依照黑名单中的数据进行过滤
|
||||||
|
|||||||
@ -16,10 +16,11 @@ public interface SmsReadConfig {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* getSupplierConfig
|
* getSupplierConfig
|
||||||
* <p> 获取一个厂商的配置
|
* <p> 通过配置ID获取一个厂商的配置
|
||||||
|
* @param configId 配置id
|
||||||
* @author :Wind
|
* @author :Wind
|
||||||
*/
|
*/
|
||||||
BaseConfig getSupplierConfig();
|
BaseConfig getSupplierConfig(String configId);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* getSupplierConfigList
|
* getSupplierConfigList
|
||||||
|
|||||||
@ -6,7 +6,9 @@ import org.dromara.sms4j.api.smsProxy.SmsInvocationHandler;
|
|||||||
import org.dromara.sms4j.api.universal.SupplierConfig;
|
import org.dromara.sms4j.api.universal.SupplierConfig;
|
||||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||||
|
import org.dromara.sms4j.core.datainterface.SmsReadConfig;
|
||||||
import org.dromara.sms4j.core.load.SmsLoad;
|
import org.dromara.sms4j.core.load.SmsLoad;
|
||||||
|
import org.dromara.sms4j.provider.config.BaseConfig;
|
||||||
import org.dromara.sms4j.provider.factory.BaseProviderFactory;
|
import org.dromara.sms4j.provider.factory.BaseProviderFactory;
|
||||||
import org.dromara.sms4j.provider.factory.ProviderFactoryHolder;
|
import org.dromara.sms4j.provider.factory.ProviderFactoryHolder;
|
||||||
|
|
||||||
@ -68,6 +70,36 @@ public abstract class SmsFactory {
|
|||||||
SmsLoad.starConfig(sms, config);
|
SmsLoad.starConfig(sms, config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createSmsBlend
|
||||||
|
* <p>通过配置读取接口创建某个短信实例
|
||||||
|
* <p>该方法创建的短信实例将会交给框架进行托管,后续可以通过getSmsBlend获取
|
||||||
|
* <p>该方法会直接调用接口实现
|
||||||
|
* @param smsReadConfig 读取额外配置接口
|
||||||
|
* @param configId 配置ID
|
||||||
|
* @author :Wind
|
||||||
|
*/
|
||||||
|
public static void createSmsBlend(SmsReadConfig smsReadConfig,String configId){
|
||||||
|
BaseConfig supplierConfig = smsReadConfig.getSupplierConfig(configId);
|
||||||
|
SmsBlend smsBlend = create(supplierConfig);
|
||||||
|
register(smsBlend);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* createSmsBlend
|
||||||
|
* <p>通过配置读取接口创建全部短信实例
|
||||||
|
* <p>该方法创建的短信实例将会交给框架进行托管,后续可以通过getSmsBlend获取
|
||||||
|
* <p>该方法会直接调用接口实现
|
||||||
|
* @param smsReadConfig 读取额外配置接口
|
||||||
|
* @author :Wind
|
||||||
|
*/
|
||||||
|
public static void createSmsBlend(SmsReadConfig smsReadConfig){
|
||||||
|
List<BaseConfig> supplierConfigList = smsReadConfig.getSupplierConfigList();
|
||||||
|
supplierConfigList.forEach(f->{
|
||||||
|
register(create(f));
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
private static SmsBlend create(SupplierConfig config) {
|
private static SmsBlend create(SupplierConfig config) {
|
||||||
BaseProviderFactory factory = ProviderFactoryHolder.requireForSupplier(config.getSupplier());
|
BaseProviderFactory factory = ProviderFactoryHolder.requireForSupplier(config.getSupplier());
|
||||||
if (factory == null) {
|
if (factory == null) {
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
package org.dromara.sms4j.test;
|
package org.dromara.sms4j.test;
|
||||||
|
|
||||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||||
import org.dromara.sms4j.core.config.SupplierFactory;
|
|
||||||
import org.dromara.sms4j.core.factory.SmsFactory;
|
import org.dromara.sms4j.core.factory.SmsFactory;
|
||||||
import org.dromara.sms4j.provider.enumerate.SupplierType;
|
|
||||||
import org.dromara.sms4j.unisms.config.UniConfig;
|
import org.dromara.sms4j.unisms.config.UniConfig;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
@ -16,15 +14,15 @@ public class Sms4jTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void uniSmsTest() {
|
public void uniSmsTest() {
|
||||||
UniConfig build = UniConfig.builder()
|
// UniConfig build = UniConfig.builder()
|
||||||
.signature("***")
|
// .signature("***")
|
||||||
.accessKeyId("7Cr1***VJQ11Ap4***Mo7xmFg")
|
// .accessKeyId("7Cr1***VJQ11Ap4***Mo7xmFg")
|
||||||
.templateId("2001")
|
// .templateId("2001")
|
||||||
.templateName("message")
|
// .templateName("message")
|
||||||
.isSimple(true)
|
// .isSimple(true)
|
||||||
.build();
|
// .build();
|
||||||
SupplierFactory.setUniConfig(build);
|
// SupplierFactory.setUniConfig(build);
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.UNI_SMS).sendMessage("175***65952", "123123");
|
// SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.UNI_SMS).sendMessage("175***65952", "123123");
|
||||||
System.out.println(smsResponse);
|
// System.out.println(smsResponse);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user