mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
修复云片短信未能如期创建实现
This commit is contained in:
parent
c21a20467e
commit
d9b5b12a69
@ -13,6 +13,7 @@ import org.dromara.sms4j.huawei.config.HuaweiSmsConfig;
|
||||
import org.dromara.sms4j.jdcloud.config.JdCloudSmsConfig;
|
||||
import org.dromara.sms4j.tencent.config.TencentSmsConfig;
|
||||
import org.dromara.sms4j.unisms.config.UniSmsConfig;
|
||||
import org.dromara.sms4j.yunpian.config.YunPianSmsConfig;
|
||||
|
||||
/**
|
||||
* SmsFactory
|
||||
@ -52,6 +53,8 @@ public abstract class SmsFactory {
|
||||
return EmaySmsConfig.createEmaySms(SupplierFactory.getEmayConfig());
|
||||
case CTYUN:
|
||||
return CtyunSmsConfig.createCtyunSms(SupplierFactory.getCtyunConfig());
|
||||
case YUNPIAN:
|
||||
return YunPianSmsConfig.createTencentSms(SupplierFactory.getYunpianConfig());
|
||||
}
|
||||
throw new SmsBlendException("An attempt to construct a SmsBlend object failed. Please check that the enumeration is valid");
|
||||
}
|
||||
@ -72,6 +75,7 @@ public abstract class SmsFactory {
|
||||
CloopenSmsConfig.refresh(SupplierFactory.getCloopenConfig());
|
||||
EmaySmsConfig.refresh(SupplierFactory.getEmayConfig());
|
||||
CtyunSmsConfig.refresh(SupplierFactory.getCtyunConfig());
|
||||
YunPianSmsConfig.refresh(SupplierFactory.getYunpianConfig());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -107,6 +111,9 @@ public abstract class SmsFactory {
|
||||
case CTYUN:
|
||||
CtyunSmsConfig.refresh(SupplierFactory.getCtyunConfig());
|
||||
break;
|
||||
case YUNPIAN:
|
||||
YunPianSmsConfig.refresh(SupplierFactory.getYunpianConfig());
|
||||
break;
|
||||
default:
|
||||
throw new SmsBlendException("An attempt to construct a SmsBlend object failed. Please check that the enumeration is valid");
|
||||
}
|
||||
|
||||
@ -3,22 +3,43 @@ package org.dromara.sms4j.yunpian.config;
|
||||
import com.dtflys.forest.Forest;
|
||||
import com.dtflys.forest.config.ForestConfiguration;
|
||||
import org.dromara.sms4j.api.SmsBlend;
|
||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||
import org.dromara.sms4j.tencent.config.TencentSmsConfig;
|
||||
import org.dromara.sms4j.yunpian.service.YunPianSmsImpl;
|
||||
|
||||
public class YunPianSmsConfig {
|
||||
|
||||
private static YunPianSmsImpl yunpianSmsImpl;
|
||||
|
||||
public YunpianConfig yunpianConfig(){
|
||||
return YunpianConfig.builder().build();
|
||||
private static YunPianSmsConfig yunPianSmsConfig;
|
||||
|
||||
private YunPianSmsConfig() {
|
||||
}
|
||||
|
||||
|
||||
public ForestConfiguration forestConfiguration(YunpianConfig yunpianConfig) {
|
||||
return Forest.config().setBackendName("httpclient");
|
||||
/**
|
||||
* 建造一个云片短信实现
|
||||
*/
|
||||
public static YunPianSmsImpl createTencentSms(YunpianConfig yunpianConfig){
|
||||
if (yunPianSmsConfig == null) {
|
||||
yunPianSmsConfig = new YunPianSmsConfig();
|
||||
}
|
||||
if (yunpianSmsImpl == null){
|
||||
yunpianSmsImpl = new YunPianSmsImpl(
|
||||
BeanFactory.getExecutor(),
|
||||
BeanFactory.getDelayedTime(),
|
||||
yunpianConfig
|
||||
);
|
||||
}
|
||||
return yunpianSmsImpl;
|
||||
}
|
||||
|
||||
|
||||
public SmsBlend smsBlend() {
|
||||
return new YunPianSmsImpl();
|
||||
/** 刷新对象*/
|
||||
public static YunPianSmsImpl refresh(YunpianConfig yunpianConfig){
|
||||
yunpianSmsImpl = new YunPianSmsImpl(
|
||||
BeanFactory.getExecutor(),
|
||||
BeanFactory.getDelayedTime(),
|
||||
yunpianConfig
|
||||
);
|
||||
return yunpianSmsImpl;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2,25 +2,21 @@ package org.dromara.sms4j.yunpian.config;
|
||||
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
import lombok.EqualsAndHashCode;
|
||||
import lombok.ToString;
|
||||
import lombok.experimental.SuperBuilder;
|
||||
import org.dromara.sms4j.comm.config.BaseConfig;
|
||||
@Data
|
||||
@Builder
|
||||
public class YunpianConfig {
|
||||
/**
|
||||
* 账号唯一标识
|
||||
*/
|
||||
private String apikey;
|
||||
@SuperBuilder
|
||||
@ToString(callSuper = true)
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
public class YunpianConfig extends BaseConfig {
|
||||
|
||||
/**
|
||||
* 短信发送后将向这个地址推送(运营商返回的)发送报告
|
||||
*/
|
||||
private String callbackUrl;
|
||||
|
||||
/**
|
||||
* 模板Id
|
||||
*/
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 模板变量名称
|
||||
*/
|
||||
|
||||
@ -9,6 +9,7 @@ import org.dromara.sms4j.comm.annotation.Restricted;
|
||||
import org.dromara.sms4j.comm.constant.Constant;
|
||||
import org.dromara.sms4j.comm.delayedTime.DelayedTime;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.factory.BeanFactory;
|
||||
import org.dromara.sms4j.yunpian.config.YunpianConfig;
|
||||
|
||||
import java.util.*;
|
||||
@ -20,13 +21,19 @@ import static org.dromara.sms4j.comm.utils.SmsUtil.listToString;
|
||||
|
||||
public class YunPianSmsImpl implements SmsBlend {
|
||||
|
||||
public YunPianSmsImpl(Executor pool, DelayedTime delayed, YunpianConfig config) {
|
||||
this.pool = pool;
|
||||
this.delayed = delayed;
|
||||
this.config = config;
|
||||
}
|
||||
|
||||
private Executor pool;
|
||||
|
||||
private DelayedTime delayed;
|
||||
|
||||
private YunpianConfig config;
|
||||
|
||||
private ForestConfiguration http;
|
||||
private final ForestConfiguration http = BeanFactory.getForestConfiguration();
|
||||
|
||||
private static SmsResponse getSmsResponse(JSONObject execute) {
|
||||
SmsResponse smsResponse = new SmsResponse();
|
||||
@ -165,7 +172,7 @@ public class YunPianSmsImpl implements SmsBlend {
|
||||
message.put(config.getTemplateName(), mes);
|
||||
}
|
||||
Map<String, String> body = new HashMap<>();
|
||||
body.put("apikey", config.getApikey());
|
||||
body.put("apikey", config.getAccessKeyId());
|
||||
body.put("mobile", phone);
|
||||
body.put("tpl_id", tplId);
|
||||
body.put("tpl_value", formattingMap(message));
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user