mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-06 17:08:40 +08:00
sms4j-solon-plugin-example: springboot 的测试代码
This commit is contained in:
parent
49c5af9f70
commit
44287e62d4
@ -4,6 +4,7 @@ import cn.hutool.json.JSONObject;
|
||||
import cn.hutool.json.JSONUtil;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||
import org.dromara.sms4j.api.utils.SmsRespUtils;
|
||||
import org.dromara.sms4j.comm.delayedTime.DelayedTime;
|
||||
import org.dromara.sms4j.comm.exception.SmsBlendException;
|
||||
import org.dromara.sms4j.comm.utils.SmsUtils;
|
||||
@ -90,9 +91,7 @@ public class ZhangJunSmsImpl extends AbstractSmsBlend<ZhangJunConfig> {
|
||||
try {
|
||||
smsResponse = getResponse(http.postJson(getConfig().getUrl(), null, message));
|
||||
} catch (SmsBlendException e) {
|
||||
smsResponse = new SmsResponse();
|
||||
smsResponse.setSuccess(false);
|
||||
smsResponse.setData(e.getMessage());
|
||||
smsResponse = errorResp(e.message);
|
||||
}
|
||||
if (smsResponse.isSuccess() || retry == getConfig().getMaxRetries()) {
|
||||
retry = 0;
|
||||
@ -109,11 +108,7 @@ public class ZhangJunSmsImpl extends AbstractSmsBlend<ZhangJunConfig> {
|
||||
}
|
||||
|
||||
private SmsResponse getResponse(JSONObject resJson) {
|
||||
SmsResponse smsResponse = new SmsResponse();
|
||||
smsResponse.setSuccess("OK".equals(resJson.getStr("Code")));
|
||||
smsResponse.setData(resJson);
|
||||
smsResponse.setConfigId(getConfigId());
|
||||
return smsResponse;
|
||||
return SmsRespUtils.resp(resJson, "OK".equals(resJson.getStr("Code")), getConfigId());
|
||||
}
|
||||
|
||||
}
|
||||
@ -79,13 +79,13 @@ sms:
|
||||
access-key-secret: 你的Access Key Secret
|
||||
sdkAppId: 你的应用ID
|
||||
#自定义广州掌骏短信,添加factory全路径。config,factory,SmsImpl复制其他默认实现即可,修改对应的supplier和发送核心逻辑即可
|
||||
# zhangjun:
|
||||
# supplier: zhangjun
|
||||
# factory: org.dromara.sms4j.example.zhangjun.ZhangJunFactory
|
||||
# templateId: d2a****777
|
||||
# appId: 64c52d2a****77775fe72e3
|
||||
# sid: d2a****777
|
||||
# url: https://sms.idowe.com/**/**/**/send
|
||||
# zhangjun:
|
||||
# supplier: zhangjun
|
||||
# factory: org.dromara.sms4j.example.zhangjun.ZhangJunFactory
|
||||
# templateId: d2a****777
|
||||
# appId: 64c52d2a****77775fe72e3
|
||||
# sid: d2a****777
|
||||
# url: https://sms.idowe.com/**/**/**/send
|
||||
qiniu:
|
||||
access-key-id: EQcDflLTCYnU1******CmqIYLhog1lkWHb2
|
||||
access-key-secret: NeS2ptvZQoIy*****err2DdLe7wxFfQvji1
|
||||
@ -155,21 +155,29 @@ sms:
|
||||
accessKeyId: ACCOUNT SID
|
||||
accessKeySecret: AUTH TOKEN
|
||||
action: 默认请求方法 distributor/sendSMS
|
||||
# 一信通
|
||||
yixintong:
|
||||
sp-code: xxxxxx #(必填)企业编号
|
||||
access-key-id: xxxxxx #(必填)用户名
|
||||
access-key-secret: 324gaxxxxxxxxxxxxxxxxx9sdf89 #(必填)接口密钥(正式帐户需要登陆平台,接口业务-接口申请右侧钥匙状图标查看或获取,接口密钥获取后十分钟生效)
|
||||
template-id: #(可选)模板编号(若配置此参数,则会默认使用该模板,以便提高服务方性能)
|
||||
sign-code: #(可选)短信前置签名编号(登陆平台-接口业务-我的签名查看)
|
||||
f: 1 #(可选)默认为1,提交时检测方式
|
||||
|
||||
sms-oa:
|
||||
config-type: yaml
|
||||
oas:
|
||||
oaDingTalkByYaml: # configId
|
||||
isEnable: true # 表示该配置是否生效(默认生效,false表示不生效)
|
||||
supplier: dingding # 厂商标识
|
||||
supplier: ding_ding # 厂商标识
|
||||
tokenId: 您的accessKey
|
||||
sign: 您的sign
|
||||
oaByteTalkByYaml: # configId
|
||||
supplier: feishu # 厂商标识
|
||||
supplier: byte_talk # 厂商标识
|
||||
tokenId: 您的accessKey
|
||||
sign: 您的sign
|
||||
oaWeTalkByYaml:
|
||||
supplier: wetalk # 厂商标识
|
||||
supplier: we_talk # 厂商标识
|
||||
tokenId: 您的sign
|
||||
core-pool-size: 20
|
||||
queue-capacity: 20
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package org.dromara.sms4j.example;
|
||||
|
||||
import cn.hutool.core.collection.CollectionUtil;
|
||||
import cn.hutool.core.collection.ListUtil;
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import cn.hutool.core.lang.UUID;
|
||||
@ -530,4 +531,31 @@ public class Sms4jTest {
|
||||
SmsResponse smsResponse5 = danMiSms.voiceTemplate(PHONE, "opipedlqza", "111,222,333");
|
||||
Assert.isTrue(smsResponse5.isSuccess());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 联通一信通模板
|
||||
*/
|
||||
@Test
|
||||
public void yixintongSmsTest() {
|
||||
if (StrUtil.isBlank(PHONE)) {
|
||||
return;
|
||||
}
|
||||
|
||||
//短信发送模板:你有一项编号为{xxxxxxxxx}的事务需要处理{x}
|
||||
//其中的{xxxxxx}代表短信模板中的变量部分,可变化,一个x代表一个字或者字符,{}为变量标识,在发送时不用传。实发变量字数小于等于x的个数。
|
||||
|
||||
// 单发
|
||||
String message1 = StrUtil.format("你有一项编号为{}的事务需要处理。", SmsUtils.getRandomInt(6));
|
||||
SmsResponse smsResponse1 = SmsFactory.getBySupplier(SupplierConstant.YIXINTONG).sendMessage(PHONE, message1);
|
||||
log.info(JSONUtil.toJsonStr(smsResponse1));
|
||||
Assert.isTrue(smsResponse1.isSuccess());
|
||||
|
||||
// 群发
|
||||
List<String> phones = CollectionUtil.toList(PHONE);
|
||||
String message2 = StrUtil.format("你有一项编号为{}的事务需要处理。", SmsUtils.getRandomInt(6));
|
||||
SmsResponse smsResponse2 = SmsFactory.getBySupplier(SupplierConstant.YIXINTONG).massTexting(phones, message2);
|
||||
log.info(JSONUtil.toJsonStr(smsResponse2));
|
||||
Assert.isTrue(smsResponse2.isSuccess());
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user