Commit 22686bafa29a9628ef4dbe54c7d1acd11055a714
1 parent
0c8ee55a
【代码优化】SYSTEM:增加新阿里云 SmsClient 的单测
Showing
4 changed files
with
107 additions
and
92 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/http/HttpUtils.java
| @@ -5,6 +5,8 @@ import cn.hutool.core.map.TableMap; | @@ -5,6 +5,8 @@ import cn.hutool.core.map.TableMap; | ||
| 5 | import cn.hutool.core.net.url.UrlBuilder; | 5 | import cn.hutool.core.net.url.UrlBuilder; |
| 6 | import cn.hutool.core.util.ReflectUtil; | 6 | import cn.hutool.core.util.ReflectUtil; |
| 7 | import cn.hutool.core.util.StrUtil; | 7 | import cn.hutool.core.util.StrUtil; |
| 8 | +import cn.hutool.http.HttpRequest; | ||
| 9 | +import cn.hutool.http.HttpResponse; | ||
| 8 | import org.springframework.util.StringUtils; | 10 | import org.springframework.util.StringUtils; |
| 9 | import org.springframework.web.util.UriComponents; | 11 | import org.springframework.web.util.UriComponents; |
| 10 | import org.springframework.web.util.UriComponentsBuilder; | 12 | import org.springframework.web.util.UriComponentsBuilder; |
| @@ -122,5 +124,23 @@ public class HttpUtils { | @@ -122,5 +124,23 @@ public class HttpUtils { | ||
| 122 | return null; | 124 | return null; |
| 123 | } | 125 | } |
| 124 | 126 | ||
| 127 | + /** | ||
| 128 | + * HTTP post 请求,基于 {@link cn.hutool.http.HttpUtil} 实现 | ||
| 129 | + * | ||
| 130 | + * 为什么要封装该方法,因为 HttpUtil 默认封装的方法,没有允许传递 headers 参数 | ||
| 131 | + * | ||
| 132 | + * @param url URL | ||
| 133 | + * @param headers 请求头 | ||
| 134 | + * @param requestBody 请求体 | ||
| 135 | + * @return 请求结果 | ||
| 136 | + */ | ||
| 137 | + public static String post(String url, Map<String, String> headers, String requestBody) { | ||
| 138 | + try (HttpResponse response = HttpRequest.post(url) | ||
| 139 | + .addHeaders(headers) | ||
| 140 | + .body(requestBody) | ||
| 141 | + .execute()) { | ||
| 142 | + return response.body(); | ||
| 143 | + } | ||
| 144 | + } | ||
| 125 | 145 | ||
| 126 | } | 146 | } |
yudao-module-system/yudao-module-system-biz/src/main/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClient.java
| @@ -6,13 +6,12 @@ import cn.hutool.core.util.IdUtil; | @@ -6,13 +6,12 @@ import cn.hutool.core.util.IdUtil; | ||
| 6 | import cn.hutool.core.util.ObjectUtil; | 6 | import cn.hutool.core.util.ObjectUtil; |
| 7 | import cn.hutool.crypto.SecureUtil; | 7 | import cn.hutool.crypto.SecureUtil; |
| 8 | import cn.hutool.crypto.digest.DigestUtil; | 8 | import cn.hutool.crypto.digest.DigestUtil; |
| 9 | -import cn.hutool.http.HttpRequest; | ||
| 10 | -import cn.hutool.http.HttpResponse; | ||
| 11 | import cn.hutool.json.JSONArray; | 9 | import cn.hutool.json.JSONArray; |
| 12 | import cn.hutool.json.JSONObject; | 10 | import cn.hutool.json.JSONObject; |
| 13 | import cn.hutool.json.JSONUtil; | 11 | import cn.hutool.json.JSONUtil; |
| 14 | import cn.iocoder.yudao.framework.common.core.KeyValue; | 12 | import cn.iocoder.yudao.framework.common.core.KeyValue; |
| 15 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; | 13 | import cn.iocoder.yudao.framework.common.util.collection.MapUtils; |
| 14 | +import cn.iocoder.yudao.framework.common.util.http.HttpUtils; | ||
| 16 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 15 | import cn.iocoder.yudao.framework.common.util.json.JsonUtils; |
| 17 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | 16 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 18 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | 17 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; |
| @@ -58,10 +57,11 @@ public class AliyunSmsClient extends AbstractSmsClient { | @@ -58,10 +57,11 @@ public class AliyunSmsClient extends AbstractSmsClient { | ||
| 58 | @Override | 57 | @Override |
| 59 | public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, | 58 | public SmsSendRespDTO sendSms(Long sendLogId, String mobile, String apiTemplateId, |
| 60 | List<KeyValue<String, Object>> templateParams) throws Throwable { | 59 | List<KeyValue<String, Object>> templateParams) throws Throwable { |
| 60 | + Assert.notBlank(properties.getSignature(), "短信签名不能为空"); | ||
| 61 | // 1. 执行请求 | 61 | // 1. 执行请求 |
| 62 | // 参考链接 https://api.aliyun.com/document/Dysmsapi/2017-05-25/SendSms | 62 | // 参考链接 https://api.aliyun.com/document/Dysmsapi/2017-05-25/SendSms |
| 63 | TreeMap<String, Object> queryParam = new TreeMap<>(); | 63 | TreeMap<String, Object> queryParam = new TreeMap<>(); |
| 64 | - queryParam.put("PhoneNumbers",mobile); | 64 | + queryParam.put("PhoneNumbers", mobile); |
| 65 | queryParam.put("SignName", properties.getSignature()); | 65 | queryParam.put("SignName", properties.getSignature()); |
| 66 | queryParam.put("TemplateCode", apiTemplateId); | 66 | queryParam.put("TemplateCode", apiTemplateId); |
| 67 | queryParam.put("TemplateParam", JsonUtils.toJsonString(MapUtils.convertMap(templateParams))); | 67 | queryParam.put("TemplateParam", JsonUtils.toJsonString(MapUtils.convertMap(templateParams))); |
| @@ -111,7 +111,8 @@ public class AliyunSmsClient extends AbstractSmsClient { | @@ -111,7 +111,8 @@ public class AliyunSmsClient extends AbstractSmsClient { | ||
| 111 | return null; | 111 | return null; |
| 112 | } | 112 | } |
| 113 | // 2.2 请求成功 | 113 | // 2.2 请求成功 |
| 114 | - return new SmsTemplateRespDTO().setId(apiTemplateId) | 114 | + return new SmsTemplateRespDTO() |
| 115 | + .setId(response.getStr("TemplateCode")) | ||
| 115 | .setContent(response.getStr("TemplateContent")) | 116 | .setContent(response.getStr("TemplateContent")) |
| 116 | .setAuditStatus(convertSmsTemplateAuditStatus(response.getInt("TemplateStatus"))) | 117 | .setAuditStatus(convertSmsTemplateAuditStatus(response.getInt("TemplateStatus"))) |
| 117 | .setAuditReason(response.getStr("Reason")); | 118 | .setAuditReason(response.getStr("Reason")); |
| @@ -176,10 +177,8 @@ public class AliyunSmsClient extends AbstractSmsClient { | @@ -176,10 +177,8 @@ public class AliyunSmsClient extends AbstractSmsClient { | ||
| 176 | + ", " + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature); | 177 | + ", " + "SignedHeaders=" + signedHeaders + ", " + "Signature=" + signature); |
| 177 | 178 | ||
| 178 | // 5. 发起请求 | 179 | // 5. 发起请求 |
| 179 | - try (HttpResponse response = HttpRequest.post(URL + "?" + queryString) | ||
| 180 | - .addHeaders(headers).body(requestBody).execute()) { | ||
| 181 | - return JSONUtil.parseObj(response.body()); | ||
| 182 | - } | 180 | + String responseBody = HttpUtils.post(URL + "?" + queryString, headers, requestBody); |
| 181 | + return JSONUtil.parseObj(responseBody); | ||
| 183 | } | 182 | } |
| 184 | 183 | ||
| 185 | /** | 184 | /** |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/AliyunSmsClientTest.java
| 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; | 1 | package cn.iocoder.yudao.module.system.framework.sms.core.client.impl; |
| 2 | 2 | ||
| 3 | +import cn.iocoder.yudao.framework.common.core.KeyValue; | ||
| 4 | +import cn.iocoder.yudao.framework.common.util.http.HttpUtils; | ||
| 3 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; | 5 | import cn.iocoder.yudao.framework.test.core.ut.BaseMockitoUnitTest; |
| 4 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; | 6 | import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsReceiveRespDTO; |
| 7 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsSendRespDTO; | ||
| 8 | +import cn.iocoder.yudao.module.system.framework.sms.core.client.dto.SmsTemplateRespDTO; | ||
| 5 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; | 9 | import cn.iocoder.yudao.module.system.framework.sms.core.enums.SmsTemplateAuditStatusEnum; |
| 6 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; | 10 | import cn.iocoder.yudao.module.system.framework.sms.core.property.SmsChannelProperties; |
| 11 | +import com.google.common.collect.Lists; | ||
| 7 | import org.junit.jupiter.api.Test; | 12 | import org.junit.jupiter.api.Test; |
| 8 | import org.mockito.InjectMocks; | 13 | import org.mockito.InjectMocks; |
| 14 | +import org.mockito.MockedStatic; | ||
| 9 | 15 | ||
| 10 | import java.time.LocalDateTime; | 16 | import java.time.LocalDateTime; |
| 11 | import java.util.List; | 17 | import java.util.List; |
| 12 | 18 | ||
| 19 | +import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId; | ||
| 13 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; | 20 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomString; |
| 14 | import static org.junit.jupiter.api.Assertions.*; | 21 | import static org.junit.jupiter.api.Assertions.*; |
| 22 | +import static org.mockito.ArgumentMatchers.anyMap; | ||
| 23 | +import static org.mockito.ArgumentMatchers.anyString; | ||
| 24 | +import static org.mockito.Mockito.mockStatic; | ||
| 15 | 25 | ||
| 16 | -// TODO 芋艿:需要优化 | ||
| 17 | /** | 26 | /** |
| 18 | - * {@link cn.iocoder.yudao.module.system.framework.sms.core.client.impl.AliyunSmsClient_old} 的单元测试 | 27 | + * {@link cn.iocoder.yudao.module.system.framework.sms.core.client.impl.AliyunSmsClient} 的单元测试 |
| 19 | * | 28 | * |
| 20 | * @author 芋道源码 | 29 | * @author 芋道源码 |
| 21 | */ | 30 | */ |
| @@ -38,64 +47,54 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | @@ -38,64 +47,54 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | ||
| 38 | smsClient.doInit(); | 47 | smsClient.doInit(); |
| 39 | } | 48 | } |
| 40 | 49 | ||
| 41 | -// @Test | ||
| 42 | -// public void tesSendSms_success() throws Throwable { | ||
| 43 | -// // 准备参数 | ||
| 44 | -// Long sendLogId = randomLongId(); | ||
| 45 | -// String mobile = randomString(); | ||
| 46 | -// String apiTemplateId = randomString(); | ||
| 47 | -// List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 48 | -// new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 49 | -// // mock 方法 | ||
| 50 | -// SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("OK")); | ||
| 51 | -// when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> { | ||
| 52 | -// assertEquals(mobile, acsRequest.getPhoneNumbers()); | ||
| 53 | -// assertEquals(properties.getSignature(), acsRequest.getSignName()); | ||
| 54 | -// assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 55 | -// assertEquals(toJsonString(MapUtils.convertMap(templateParams)), acsRequest.getTemplateParam()); | ||
| 56 | -// assertEquals(sendLogId.toString(), acsRequest.getOutId()); | ||
| 57 | -// return true; | ||
| 58 | -// }))).thenReturn(response); | ||
| 59 | -// | ||
| 60 | -// // 调用 | ||
| 61 | -// SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, | ||
| 62 | -// apiTemplateId, templateParams); | ||
| 63 | -// // 断言 | ||
| 64 | -// assertTrue(result.getSuccess()); | ||
| 65 | -// assertEquals(response.getRequestId(), result.getApiRequestId()); | ||
| 66 | -// assertEquals(response.getCode(), result.getApiCode()); | ||
| 67 | -// assertEquals(response.getMessage(), result.getApiMsg()); | ||
| 68 | -// assertEquals(response.getBizId(), result.getSerialNo()); | ||
| 69 | -// } | ||
| 70 | - | ||
| 71 | -// @Test | ||
| 72 | -// public void tesSendSms_fail() throws Throwable { | ||
| 73 | -// // 准备参数 | ||
| 74 | -// Long sendLogId = randomLongId(); | ||
| 75 | -// String mobile = randomString(); | ||
| 76 | -// String apiTemplateId = randomString(); | ||
| 77 | -// List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 78 | -// new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 79 | -// // mock 方法 | ||
| 80 | -// SendSmsResponse response = randomPojo(SendSmsResponse.class, o -> o.setCode("ERROR")); | ||
| 81 | -// when(client.getAcsResponse(argThat((ArgumentMatcher<SendSmsRequest>) acsRequest -> { | ||
| 82 | -// assertEquals(mobile, acsRequest.getPhoneNumbers()); | ||
| 83 | -// assertEquals(properties.getSignature(), acsRequest.getSignName()); | ||
| 84 | -// assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 85 | -// assertEquals(toJsonString(MapUtils.convertMap(templateParams)), acsRequest.getTemplateParam()); | ||
| 86 | -// assertEquals(sendLogId.toString(), acsRequest.getOutId()); | ||
| 87 | -// return true; | ||
| 88 | -// }))).thenReturn(response); | ||
| 89 | -// | ||
| 90 | -// // 调用 | ||
| 91 | -// SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, apiTemplateId, templateParams); | ||
| 92 | -// // 断言 | ||
| 93 | -// assertFalse(result.getSuccess()); | ||
| 94 | -// assertEquals(response.getRequestId(), result.getApiRequestId()); | ||
| 95 | -// assertEquals(response.getCode(), result.getApiCode()); | ||
| 96 | -// assertEquals(response.getMessage(), result.getApiMsg()); | ||
| 97 | -// assertEquals(response.getBizId(), result.getSerialNo()); | ||
| 98 | -// } | 50 | + @Test |
| 51 | + public void tesSendSms_success() throws Throwable { | ||
| 52 | + try (MockedStatic<HttpUtils> httpUtilsMockedStatic = mockStatic(HttpUtils.class)) { | ||
| 53 | + // 准备参数 | ||
| 54 | + Long sendLogId = randomLongId(); | ||
| 55 | + String mobile = randomString(); | ||
| 56 | + String apiTemplateId = randomString(); | ||
| 57 | + List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 58 | + new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 59 | + // mock 方法 | ||
| 60 | + httpUtilsMockedStatic.when(() -> HttpUtils.post(anyString(), anyMap(), anyString())) | ||
| 61 | + .thenReturn("{\"Message\":\"OK\",\"RequestId\":\"30067CE9-3710-5984-8881-909B21D8DB28\",\"Code\":\"OK\",\"BizId\":\"800025323183427988\"}"); | ||
| 62 | + | ||
| 63 | + // 调用 | ||
| 64 | + SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, | ||
| 65 | + apiTemplateId, templateParams); | ||
| 66 | + // 断言 | ||
| 67 | + assertTrue(result.getSuccess()); | ||
| 68 | + assertEquals("30067CE9-3710-5984-8881-909B21D8DB28", result.getApiRequestId()); | ||
| 69 | + assertEquals("OK", result.getApiCode()); | ||
| 70 | + assertEquals("OK", result.getApiMsg()); | ||
| 71 | + assertEquals("800025323183427988", result.getSerialNo()); | ||
| 72 | + } | ||
| 73 | + } | ||
| 74 | + | ||
| 75 | + @Test | ||
| 76 | + public void tesSendSms_fail() throws Throwable { | ||
| 77 | + try (MockedStatic<HttpUtils> httpUtilsMockedStatic = mockStatic(HttpUtils.class)) { | ||
| 78 | + // 准备参数 | ||
| 79 | + Long sendLogId = randomLongId(); | ||
| 80 | + String mobile = randomString(); | ||
| 81 | + String apiTemplateId = randomString(); | ||
| 82 | + List<KeyValue<String, Object>> templateParams = Lists.newArrayList( | ||
| 83 | + new KeyValue<>("code", 1234), new KeyValue<>("op", "login")); | ||
| 84 | + // mock 方法 | ||
| 85 | + httpUtilsMockedStatic.when(() -> HttpUtils.post(anyString(), anyMap(), anyString())) | ||
| 86 | + .thenReturn("{\"Message\":\"手机号码格式错误\",\"RequestId\":\"B7700B8E-227E-5886-9564-26036172F01F\",\"Code\":\"isv.MOBILE_NUMBER_ILLEGAL\"}"); | ||
| 87 | + | ||
| 88 | + // 调用 | ||
| 89 | + SmsSendRespDTO result = smsClient.sendSms(sendLogId, mobile, apiTemplateId, templateParams); | ||
| 90 | + // 断言 | ||
| 91 | + assertFalse(result.getSuccess()); | ||
| 92 | + assertEquals("B7700B8E-227E-5886-9564-26036172F01F", result.getApiRequestId()); | ||
| 93 | + assertEquals("isv.MOBILE_NUMBER_ILLEGAL", result.getApiCode()); | ||
| 94 | + assertEquals("手机号码格式错误", result.getApiMsg()); | ||
| 95 | + assertNull(result.getSerialNo()); | ||
| 96 | + } | ||
| 97 | + } | ||
| 99 | 98 | ||
| 100 | @Test | 99 | @Test |
| 101 | public void testParseSmsReceiveStatus() { | 100 | public void testParseSmsReceiveStatus() { |
| @@ -129,28 +128,24 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | @@ -129,28 +128,24 @@ public class AliyunSmsClientTest extends BaseMockitoUnitTest { | ||
| 129 | assertEquals(67890L, statuses.get(0).getLogId()); | 128 | assertEquals(67890L, statuses.get(0).getLogId()); |
| 130 | } | 129 | } |
| 131 | 130 | ||
| 132 | -// @Test | ||
| 133 | -// public void testGetSmsTemplate() throws Throwable { | ||
| 134 | -// // 准备参数 | ||
| 135 | -// String apiTemplateId = randomString(); | ||
| 136 | -// // mock 方法 | ||
| 137 | -// QuerySmsTemplateResponse response = randomPojo(QuerySmsTemplateResponse.class, o -> { | ||
| 138 | -// o.setCode("OK"); | ||
| 139 | -// o.setTemplateStatus(1); // 设置模板通过 | ||
| 140 | -// }); | ||
| 141 | -// when(client.getAcsResponse(argThat((ArgumentMatcher<QuerySmsTemplateRequest>) acsRequest -> { | ||
| 142 | -// assertEquals(apiTemplateId, acsRequest.getTemplateCode()); | ||
| 143 | -// return true; | ||
| 144 | -// }))).thenReturn(response); | ||
| 145 | -// | ||
| 146 | -// // 调用 | ||
| 147 | -// SmsTemplateRespDTO result = smsClient.getSmsTemplate(apiTemplateId); | ||
| 148 | -// // 断言 | ||
| 149 | -// assertEquals(response.getTemplateCode(), result.getId()); | ||
| 150 | -// assertEquals(response.getTemplateContent(), result.getContent()); | ||
| 151 | -// assertEquals(SmsTemplateAuditStatusEnum.SUCCESS.getStatus(), result.getAuditStatus()); | ||
| 152 | -// assertEquals(response.getReason(), result.getAuditReason()); | ||
| 153 | -// } | 131 | + @Test |
| 132 | + public void testGetSmsTemplate() throws Throwable { | ||
| 133 | + try (MockedStatic<HttpUtils> httpUtilsMockedStatic = mockStatic(HttpUtils.class)) { | ||
| 134 | + // 准备参数 | ||
| 135 | + String apiTemplateId = randomString(); | ||
| 136 | + // mock 方法 | ||
| 137 | + httpUtilsMockedStatic.when(() -> HttpUtils.post(anyString(), anyMap(), anyString())) | ||
| 138 | + .thenReturn("{\"TemplateCode\":\"SMS_207945135\",\"RequestId\":\"6F4CC077-29C8-5BA5-AB62-5FF95068A5AC\",\"Message\":\"OK\",\"TemplateContent\":\"您的验证码${code},该验证码5分钟内有效,请勿泄漏于他人!\",\"TemplateName\":\"公告通知\",\"TemplateType\":0,\"Code\":\"OK\",\"CreateDate\":\"2020-12-23 17:34:42\",\"Reason\":\"无审批备注\",\"TemplateStatus\":1}"); | ||
| 139 | + | ||
| 140 | + // 调用 | ||
| 141 | + SmsTemplateRespDTO result = smsClient.getSmsTemplate(apiTemplateId); | ||
| 142 | + // 断言 | ||
| 143 | + assertEquals("SMS_207945135", result.getId()); | ||
| 144 | + assertEquals("您的验证码${code},该验证码5分钟内有效,请勿泄漏于他人!", result.getContent()); | ||
| 145 | + assertEquals(SmsTemplateAuditStatusEnum.SUCCESS.getStatus(), result.getAuditStatus()); | ||
| 146 | + assertEquals("无审批备注", result.getAuditReason()); | ||
| 147 | + } | ||
| 148 | + } | ||
| 154 | 149 | ||
| 155 | @Test | 150 | @Test |
| 156 | public void testConvertSmsTemplateAuditStatus() { | 151 | public void testConvertSmsTemplateAuditStatus() { |
yudao-module-system/yudao-module-system-biz/src/test/java/cn/iocoder/yudao/module/system/framework/sms/core/client/impl/SmsClientTests.java
| @@ -57,11 +57,12 @@ public class SmsClientTests { | @@ -57,11 +57,12 @@ public class SmsClientTests { | ||
| 57 | public void testAliyunSmsClient_sendSms() throws Throwable { | 57 | public void testAliyunSmsClient_sendSms() throws Throwable { |
| 58 | SmsChannelProperties properties = new SmsChannelProperties() | 58 | SmsChannelProperties properties = new SmsChannelProperties() |
| 59 | .setApiKey("LTAI5tAicJAxaSFiZuGGeXHR") | 59 | .setApiKey("LTAI5tAicJAxaSFiZuGGeXHR") |
| 60 | - .setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz"); | 60 | + .setApiSecret("Fdr9vadxnDvS6GJU0W1tijQ0VmLhYz") |
| 61 | + .setSignature("Ballcat"); | ||
| 61 | AliyunSmsClient client = new AliyunSmsClient(properties); | 62 | AliyunSmsClient client = new AliyunSmsClient(properties); |
| 62 | // 准备参数 | 63 | // 准备参数 |
| 63 | Long sendLogId = System.currentTimeMillis(); | 64 | Long sendLogId = System.currentTimeMillis(); |
| 64 | - String mobile = "17321315478"; | 65 | + String mobile = "173213154791"; |
| 65 | String apiTemplateId = "SMS_207945135"; | 66 | String apiTemplateId = "SMS_207945135"; |
| 66 | // 调用 | 67 | // 调用 |
| 67 | SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); | 68 | SmsSendRespDTO sendRespDTO = client.sendSms(sendLogId, mobile, apiTemplateId, List.of(new KeyValue<>("code", "1024"))); |