mirror of
https://gitee.com/dromara/sms4j.git
synced 2025-12-07 09:29:08 +08:00
fix pr 问题:统一使用hutool-json对象、SmsResponse删除code和message、进一步屏蔽测试信息
This commit is contained in:
parent
4d61a3563a
commit
19476a6c88
@ -25,8 +25,4 @@ public class SmsResponse {
|
|||||||
* @since 2.3.0
|
* @since 2.3.0
|
||||||
*/
|
*/
|
||||||
private Object data;
|
private Object data;
|
||||||
|
|
||||||
/** 状态码*/
|
|
||||||
private String code;
|
|
||||||
private String message;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,9 +5,9 @@ import cn.hutool.core.collection.ListUtil;
|
|||||||
import cn.hutool.core.text.StrPool;
|
import cn.hutool.core.text.StrPool;
|
||||||
import cn.hutool.core.util.StrUtil;
|
import cn.hutool.core.util.StrUtil;
|
||||||
import cn.hutool.crypto.SecureUtil;
|
import cn.hutool.crypto.SecureUtil;
|
||||||
|
import cn.hutool.json.JSONArray;
|
||||||
|
import cn.hutool.json.JSONObject;
|
||||||
import cn.hutool.json.JSONUtil;
|
import cn.hutool.json.JSONUtil;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
import org.dromara.sms4j.api.AbstractSmsBlend;
|
import org.dromara.sms4j.api.AbstractSmsBlend;
|
||||||
import org.dromara.sms4j.api.entity.SmsResponse;
|
import org.dromara.sms4j.api.entity.SmsResponse;
|
||||||
@ -198,11 +198,11 @@ public class ZhutongSmsImpl extends AbstractSmsBlend {
|
|||||||
AtomicReference<SmsResponse> reference = new AtomicReference<>();
|
AtomicReference<SmsResponse> reference = new AtomicReference<>();
|
||||||
http.post(urls)
|
http.post(urls)
|
||||||
.addHeader("Content-Type", Constant.APPLICATION_JSON_UTF8)
|
.addHeader("Content-Type", Constant.APPLICATION_JSON_UTF8)
|
||||||
.addBody(requestJson.getInnerMap())
|
.addBody(requestJson)
|
||||||
.onSuccess(((data, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class)))))
|
.onSuccess(((data, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class)))))
|
||||||
.onError((ex, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class))))
|
.onError((ex, req, res) -> reference.set(this.getResponse(res.get(JSONObject.class))))
|
||||||
.execute();
|
.execute();
|
||||||
log.info("助通短信 URL={} json={} 响应值为={}", urls, requestJson.toJSONString(), reference.get());
|
log.info("助通短信 URL={} json={} 响应值为={}", urls, requestJson, reference.get());
|
||||||
return reference.get();
|
return reference.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,7 +212,7 @@ public class ZhutongSmsImpl extends AbstractSmsBlend {
|
|||||||
|
|
||||||
private SmsResponse getResponse(JSONObject jsonObject) {
|
private SmsResponse getResponse(JSONObject jsonObject) {
|
||||||
SmsResponse response = new SmsResponse();
|
SmsResponse response = new SmsResponse();
|
||||||
response.setSuccess(jsonObject.getInteger("code") <= 200);
|
response.setSuccess(jsonObject.getInt("code", -1) <= 200);
|
||||||
response.setData(jsonObject);
|
response.setData(jsonObject);
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -31,7 +31,7 @@ class Sms4jTest {
|
|||||||
// 阿里
|
// 阿里
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ALIBABA).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("OK".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -42,7 +42,7 @@ class Sms4jTest {
|
|||||||
// 华为
|
// 华为
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.HUAWEI).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.HUAWEI).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("000000".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -53,7 +53,7 @@ class Sms4jTest {
|
|||||||
// 容联云
|
// 容联云
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.CLOOPEN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.CLOOPEN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("000000".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -64,7 +64,7 @@ class Sms4jTest {
|
|||||||
// 亿美软通
|
// 亿美软通
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.EMAY).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.EMAY).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("success".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -86,7 +86,7 @@ class Sms4jTest {
|
|||||||
// 云片
|
// 云片
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.YUNPIAN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.YUNPIAN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("0".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -97,7 +97,7 @@ class Sms4jTest {
|
|||||||
// 腾讯
|
// 腾讯
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.TENCENT).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.TENCENT).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("Ok".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -108,7 +108,7 @@ class Sms4jTest {
|
|||||||
// 合一
|
// 合一
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.UNI_SMS).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.UNI_SMS).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("Success".equals(smsResponse.getMessage()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -119,7 +119,7 @@ class Sms4jTest {
|
|||||||
// 天翼云
|
// 天翼云
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.CTYUN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.CTYUN).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue("OK".equals(smsResponse.getCode()) && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -130,7 +130,7 @@ class Sms4jTest {
|
|||||||
// 网易云短信
|
// 网易云短信
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.NETEASE).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.NETEASE).sendMessage(PHONE, SmsUtil.getRandomInt(6));
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue(Long.parseLong(smsResponse.getCode()) <= 200 && smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -174,7 +174,7 @@ class Sms4jTest {
|
|||||||
}
|
}
|
||||||
// 助通短信短信
|
// 助通短信短信
|
||||||
String msg = StrUtil.format("【图书商城】您好,你的验证码是{}:(5分钟失效)", SmsUtil.getRandomInt(6));
|
String msg = StrUtil.format("【图书商城】您好,你的验证码是{}:(5分钟失效)", SmsUtil.getRandomInt(6));
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).massTexting(ListUtil.of(PHONE, "17312345678"), msg);
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).massTexting(ListUtil.of(PHONE, "180****1111"), msg);
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue(smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
@ -190,7 +190,7 @@ class Sms4jTest {
|
|||||||
// 助通短信短信
|
// 助通短信短信
|
||||||
LinkedHashMap<String, String> messages = new LinkedHashMap<>(1);
|
LinkedHashMap<String, String> messages = new LinkedHashMap<>(1);
|
||||||
messages.put("code", SmsUtil.getRandomInt(6));
|
messages.put("code", SmsUtil.getRandomInt(6));
|
||||||
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).massTexting(ListUtil.of(PHONE, "17312345678"), "59264", messages);
|
SmsResponse smsResponse = SmsFactory.createSmsBlend(SupplierType.ZHUTONG).massTexting(ListUtil.of(PHONE, "180****1111"), "59264", messages);
|
||||||
log.info(JSONUtil.toJsonStr(smsResponse));
|
log.info(JSONUtil.toJsonStr(smsResponse));
|
||||||
Assert.isTrue(smsResponse.isSuccess());
|
Assert.isTrue(smsResponse.isSuccess());
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user