mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-08-06 22:31:53 +08:00
【功能优化】短信:腾讯云的实现优化
This commit is contained in:
@@ -57,15 +57,16 @@ public class SmsClientTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void testTencentSmsClient_sendSms() throws Throwable {
|
||||
String sdkAppId = "1400500458";
|
||||
SmsChannelProperties properties = new SmsChannelProperties()
|
||||
.setApiKey("LTAI5tAicJAxaSFiZuGGeXHR 1428926523")
|
||||
.setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz")
|
||||
.setApiKey(System.getenv("SMS_TENCENT_ACCESS_KEY") + " " + sdkAppId)
|
||||
.setApiSecret(System.getenv("SMS_TENCENT_SECRET_KEY"))
|
||||
.setSignature("芋道源码");
|
||||
TencentSmsClient client = new TencentSmsClient(properties);
|
||||
// 准备参数
|
||||
Long sendLogId = System.currentTimeMillis();
|
||||
String mobile = "15601691323";
|
||||
String apiTemplateId = "2136358";
|
||||
String apiTemplateId = "358212";
|
||||
// 调用
|
||||
SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024")));
|
||||
// 打印结果
|
||||
@@ -75,13 +76,14 @@ public class SmsClientTests {
|
||||
@Test
|
||||
@Disabled
|
||||
public void testTencentSmsClient_getSmsTemplate() throws Throwable {
|
||||
String sdkAppId = "1400500458";
|
||||
SmsChannelProperties properties = new SmsChannelProperties()
|
||||
.setApiKey("LTAI5tAicJAxaSFiZuGGeXHR 1428926523")
|
||||
.setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz")
|
||||
.setApiKey(System.getenv("SMS_TENCENT_ACCESS_KEY") + " " + sdkAppId)
|
||||
.setApiSecret(System.getenv("SMS_TENCENT_SECRET_KEY"))
|
||||
.setSignature("芋道源码");
|
||||
TencentSmsClient client = new TencentSmsClient(properties);
|
||||
// 准备参数
|
||||
String apiTemplateId = "2136358";
|
||||
String apiTemplateId = "358212";
|
||||
// 调用
|
||||
SmsTemplateRespDTO template = client.getSmsTemplate(apiTemplateId);
|
||||
// 打印结果
|
||||
|
@@ -78,7 +78,7 @@ public class TencentSmsClientTest extends BaseMockitoUnitTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoSendSms_fail() throws Throwable {
|
||||
public void testDoSendSms_fail_01() throws Throwable {
|
||||
try (MockedStatic<HttpUtils> httpUtilsMockedStatic = mockStatic(HttpUtils.class)) {
|
||||
// 准备参数
|
||||
Long sendLogId = randomLongId();
|
||||
@@ -117,6 +117,31 @@ public class TencentSmsClientTest extends BaseMockitoUnitTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoSendSms_fail_02() throws Throwable {
|
||||
try (MockedStatic<HttpUtils> httpUtilsMockedStatic = mockStatic(HttpUtils.class)) {
|
||||
// 准备参数
|
||||
Long sendLogId = randomLongId();
|
||||
String mobile = randomString();
|
||||
String apiTemplateId = randomString();
|
||||
List<KeyValue<String, Object>> templateParams = Lists.newArrayList(
|
||||
new KeyValue<>("1", 1234), new KeyValue<>("2", "login"));
|
||||
|
||||
// mock 方法
|
||||
httpUtilsMockedStatic.when(() -> HttpUtils.post(anyString(), anyMap(), anyString()))
|
||||
.thenReturn("{\"Response\":{\"Error\":{\"Code\":\"AuthFailure.SecretIdNotFound\",\"Message\":\"The SecretId is not found, please ensure that your SecretId is correct.\"},\"RequestId\":\"2a88f82a-261c-4ac6-9fa9-c7d01aaa486a\"}}");
|
||||
|
||||
// 调用
|
||||
SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile,
|
||||
apiTemplateId, templateParams);
|
||||
// 断言
|
||||
assertFalse(result.getSuccess());
|
||||
assertEquals("2a88f82a-261c-4ac6-9fa9-c7d01aaa486a", result.getApiRequestId());
|
||||
assertEquals("AuthFailure.SecretIdNotFound", result.getApiCode());
|
||||
assertEquals("The SecretId is not found, please ensure that your SecretId is correct.", result.getApiMsg());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseSmsReceiveStatus() {
|
||||
// 准备参数
|
||||
|
Reference in New Issue
Block a user