腾讯云短信接入

news/2024/10/20 11:35:15/

腾讯云短信接入

  • 一、前提条件
  • 二、代码工程引入依赖(maven工程)
  • 三、短信客户端代码示例
  • 四、测试结果展示
  • 五、其他说明


一、前提条件

  • 已开通短信服务,创建签名和模板并通过审核,具体操作请参见 国内短信快速入门。
  • 如需发送国内短信,需要先 购买国内短信套餐包。
  • 已准备依赖环境:JDK 7 及以上版本。
  • 已在访问管理控制台 >API密钥管理页面获取 SecretID 和 SecretKey。
  • 短信的调用地址为sms.tencentcloudapi.com

二、代码工程引入依赖(maven工程)

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><version>2.3.12.RELEASE</version>
</dependency>
<!-- Lombok -->
<dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><scope>provided</scope>
</dependency>
<!--腾讯云短信SDK-->
<dependency><groupId>com.tencentcloudapi</groupId><artifactId>tencentcloud-sdk-java</artifactId><!-- go to https://search.maven.org/search?q=tencentcloud-sdk-java and get the latest version. --><!-- 请到https://search.maven.org/search?q=tencentcloud-sdk-java查询所有版本,最新版本如下 --><version>3.1.722</version>
</dependency>

三、短信客户端代码示例

  • 短信客户端参数类
import lombok.Data;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;/*** Tencent Cloud Sms client property*/
@Component
@ConfigurationProperties(value = "sms.tencent")
@Data
public class TencentSmsProperty {private String secretId;private String secretKey;private String signName;private String sdkAppId;
}
  • 短信客户端配置类
import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** Tencent Cloud Sms client config*/
@Configuration(proxyBeanMethods = false)
public class TencentSmsConfig {@Autowiredprivate TencentSmsProperty tencentSmsProperty;@Bean@ConditionalOnMissingBeanpublic SmsClient smsClient() {/* 必要步骤:* 实例化一个认证对象,入参需要传入腾讯云账户密钥对secretId,secretKey。* 这里采用的是从环境变量读取的方式,需要在环境变量中先设置这两个值。* 你也可以直接在代码中写死密钥对,但是小心不要将代码复制、上传或者分享给他人,* 以免泄露密钥对危及你的财产安全。* SecretId、SecretKey 查询: https://console.cloud.tencent.com/cam/capi */Credential cred = new Credential(tencentSmsProperty.getSecretId(), tencentSmsProperty.getSecretKey());// 实例化一个http选项,可选,没有特殊需求可以跳过HttpProfile httpProfile = new HttpProfile();// 设置代理// httpProfile.setProxyHost("真实代理ip");// httpProfile.setProxyPort(真实代理端口);/* SDK默认使用POST方法。* 如果你一定要使用GET方法,可以在这里设置。GET方法无法处理一些较大的请求 */httpProfile.setReqMethod("POST");/* SDK有默认的超时时间,非必要请不要进行调整* 如有需要请在代码中查阅以获取最新的默认值 */httpProfile.setConnTimeout(60);/* 指定接入地域域名,默认就近地域接入域名为 sms.tencentcloudapi.com ,也支持指定地域域名访问,例如广州地域的域名为 sms.ap-guangzhou.tencentcloudapi.com */httpProfile.setEndpoint("sms.tencentcloudapi.com");/* 非必要步骤:* 实例化一个客户端配置对象,可以指定超时时间等配置 */ClientProfile clientProfile = new ClientProfile();/* SDK默认用TC3-HMAC-SHA256进行签名* 非必要请不要修改这个字段 */clientProfile.setSignMethod("HmacSHA256");clientProfile.setHttpProfile(httpProfile);/* 实例化要请求产品(以sms为例)的client对象* 第二个参数是地域信息,可以直接填写字符串ap-guangzhou,支持的地域列表参考 https://cloud.tencent.com/document/api/382/52071#.E5.9C.B0.E5.9F.9F.E5.88.97.E8.A1.A8 */return new SmsClient(cred, "ap-guangzhou", clientProfile);}}
  • 短信模版申请(该步骤可在腾讯云管理端进行配置)
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.AddSmsTemplateRequest;
import com.tencentcloudapi.sms.v20210111.models.AddSmsTemplateResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;/*** Tencent Cloud Sms AddSmsTemplate*/
@Component
public class AddSmsTemplate {@Autowiredprivate SmsClient smsClient;public void addSmsTemplate() {try {/* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数* 您可以直接查询 SDK 源码确定接口有哪些属性可以设置* 属性可能是基本类型,也可能引用了另一个数据结构* 推荐使用 IDE 进行开发,可以方便地跳转查阅各个接口和数据结构的文档说明 */AddSmsTemplateRequest req = new AddSmsTemplateRequest();/* 填充请求参数,这里 request 对象的成员变量即对应接口的入参* 您可以通过官网接口文档或跳转到 request 对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台:https://console.cloud.tencent.com/smsv2* 腾讯云短信小助手:https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 *//* 模板名称*/String templatename = "腾讯云";req.setTemplateName(templatename);/* 模板内容 */String templatecontent = "{1}为您的登录验证码,请于{2}分钟内填写,如非本人操作,请忽略本短信。";req.setTemplateContent(templatecontent);/* 短信类型:0表示普通短信, 1表示营销短信 */long smstype = 0;req.setSmsType(smstype);/* 是否国际/港澳台短信:0:表示国内短信,1:表示国际/港澳台短信。 */long international = 0;req.setInternational(international);/* 模板备注:例如申请原因,使用场景等 */String remark = "xxx";req.setRemark(remark);/* 通过 client 对象调用 AddSmsTemplate 方法发起请求。注意请求方法名与请求对象是对应的* 返回的 res 是一个 AddSmsTemplateResponse 类的实例,与请求对象对应 */AddSmsTemplateResponse res = smsClient.AddSmsTemplate(req);// 输出 JSON 格式的字符串回包System.out.println(AddSmsTemplateResponse.toJsonString(res));// 可以取出单个值,您可以通过官网接口文档或跳转到 response 对象的定义处查看返回字段的定义System.out.println(res.getRequestId());} catch (TencentCloudSDKException e) {e.printStackTrace();}}
}
  • 短信发送
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendSmsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendSmsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;/*** Tencent Cloud Sms Sendsms*/
@Component
public class SendSms {@Autowiredprivate SmsClient smsClient;@Autowiredprivate TencentSmsProperty tencentSmsProperty;public void sendSms() {try {/* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数* 你可以直接查询SDK源码确定接口有哪些属性可以设置* 属性可能是基本类型,也可能引用了另一个数据结构* 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */SendSmsRequest req = new SendSmsRequest();/* 填充请求参数,这里request对象的成员变量即对应接口的入参* 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台: https://console.cloud.tencent.com/smsv2* 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 *//* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */// 应用 ID 可前往 [短信控制台](https://console.cloud.tencent.com/smsv2/app-manage) 查看req.setSmsSdkAppId(tencentSmsProperty.getSdkAppId());/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */// 签名信息可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-sign) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-sign) 的签名管理查看req.setSignName(tencentSmsProperty.getSignName());/* 模板 ID: 必须填写已审核通过的模板 ID */// 模板 ID 可前往 [国内短信](https://console.cloud.tencent.com/smsv2/csms-template) 或 [国际/港澳台短信](https://console.cloud.tencent.com/smsv2/isms-template) 的正文模板管理查看String templateId = "449739";req.setTemplateId(templateId);/* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */String[] templateParamSet = {"1234"};req.setTemplateParamSet(templateParamSet);/* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]* 示例如:+8613711112222, 其中前面有一个+号 ,86为国家码,13711112222为手机号,最多不要超过200个手机号 */String[] phoneNumberSet = {"+8621212313123", "+8612345678902", "+8612345678903"};req.setPhoneNumberSet(phoneNumberSet);/* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */String sessionContext = "";req.setSessionContext(sessionContext);/* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请联系 [腾讯云短信小助手] */String extendCode = "";req.setExtendCode(extendCode);/* 国际/港澳台短信 SenderId(无需要可忽略): 国内短信填空,默认未开通,如需开通请联系 [腾讯云短信小助手] */String senderid = "";req.setSenderId(senderid);/* 通过 client 对象调用 SendSms 方法发起请求。注意请求方法名与请求对象是对应的* 返回的 res 是一个 SendSmsResponse 类的实例,与请求对象对应 */SendSmsResponse res = smsClient.SendSms(req);// 输出json格式的字符串回包System.out.println(SendSmsResponse.toJsonString(res));// 也可以取出单个值,你可以通过官网接口文档或跳转到response对象的定义处查看返回字段的定义// System.out.println(res.getRequestId());/* 当出现以下错误码时,快速解决方案参考* [FailedOperation.SignatureIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.signatureincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)* [FailedOperation.TemplateIncorrectOrUnapproved](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Afailedoperation.templateincorrectorunapproved-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)* [UnauthorizedOperation.SmsSdkAppIdVerifyFail](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunauthorizedoperation.smssdkappidverifyfail-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)* [UnsupportedOperation.ContainDomesticAndInternationalPhoneNumber](https://cloud.tencent.com/document/product/382/9558#.E7.9F.AD.E4.BF.A1.E5.8F.91.E9.80.81.E6.8F.90.E7.A4.BA.EF.BC.9Aunsupportedoperation.containdomesticandinternationalphonenumber-.E5.A6.82.E4.BD.95.E5.A4.84.E7.90.86.EF.BC.9F)* 更多错误,可咨询[腾讯云助手](https://tccc.qcloud.com/web/im/index.html#/chat?webAppId=8fa15978f85cb41f7e2ea36920cb3ae1&title=Sms)*/} catch (TencentCloudSDKException e) {e.printStackTrace();}}
}
  • 拉取回执状态
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatusRequest;
import com.tencentcloudapi.sms.v20210111.models.PullSmsSendStatusResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;/*** Tencent Cloud Sms PullSmsSendStatus* 注:此接口需要联系 [腾讯云短信小助手](https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81) 开通*/
@Component
public class PullSmsSendStatus {@Autowiredprivate SmsClient smsClient;@Autowiredprivate TencentSmsProperty tencentSmsProperty;public void pullSmsSendStatus() {try {/* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数* 你可以直接查询SDK源码确定接口有哪些属性可以设置* 属性可能是基本类型,也可能引用了另一个数据结构* 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */PullSmsSendStatusRequest req = new PullSmsSendStatusRequest();/* 填充请求参数,这里request对象的成员变量即对应接口的入参* 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台: https://console.cloud.tencent.com/smsv2* 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 *//* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */req.setSmsSdkAppId(tencentSmsProperty.getSdkAppId());// 设置拉取最大条数,最多100条Long limit = 5L;req.setLimit(limit);/* 通过 client 对象调用 PullSmsSendStatus 方法发起请求。注意请求方法名与请求对象是对应的* 返回的 res 是一个 PullSmsSendStatusResponse 类的实例,与请求对象对应 */PullSmsSendStatusResponse res = smsClient.PullSmsSendStatus(req);// 输出json格式的字符串回包System.out.println(PullSmsSendStatusResponse.toJsonString(res));} catch (TencentCloudSDKException e) {e.printStackTrace();}}
}
  • 统计短信发送数据
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.sms.v20210111.SmsClient;
import com.tencentcloudapi.sms.v20210111.models.SendStatusStatisticsRequest;
import com.tencentcloudapi.sms.v20210111.models.SendStatusStatisticsResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;/*** Tencent Cloud Sms SendStatusStatistics*/
@Component
public class SendStatusStatistics {@Autowiredprivate SmsClient smsClient;@Autowiredprivate TencentSmsProperty tencentSmsProperty;public void sendStatusStatistics() {try {/* 实例化一个请求对象,根据调用的接口和实际情况,可以进一步设置请求参数* 你可以直接查询SDK源码确定接口有哪些属性可以设置* 属性可能是基本类型,也可能引用了另一个数据结构* 推荐使用IDE进行开发,可以方便的跳转查阅各个接口和数据结构的文档说明 */SendStatusStatisticsRequest req = new SendStatusStatisticsRequest();/* 填充请求参数,这里request对象的成员变量即对应接口的入参* 你可以通过官网接口文档或跳转到request对象的定义处查看请求参数的定义* 基本类型的设置:* 帮助链接:* 短信控制台: https://console.cloud.tencent.com/smsv2* 腾讯云短信小助手: https://cloud.tencent.com/document/product/382/3773#.E6.8A.80.E6.9C.AF.E4.BA.A4.E6.B5.81 *//* 短信应用ID: 短信SdkAppId在 [短信控制台] 添加应用后生成的实际SdkAppId,示例如1400006666 */req.setSmsSdkAppId(tencentSmsProperty.getSdkAppId());// 设置拉取最大条数,最多100条Long limit = 5L;req.setLimit(limit);/* 偏移量 注:目前固定设置为0 */Long offset = 0L;req.setOffset(offset);/* 开始时间,yyyymmddhh 需要拉取的起始时间,精确到小时 */String beginTime = "2019071100";req.setBeginTime(beginTime);/* 结束时间,yyyymmddhh 需要拉取的截止时间,精确到小时* 注:EndTime 必须大于 beginTime */String endTime = "2019071123";req.setEndTime(endTime);/* 通过 client 对象调用 SendStatusStatistics 方法发起请求。注意请求方法名与请求对象是对应的* 返回的 res 是一个 SendStatusStatisticsResponse 类的实例,与请求对象对应 */SendStatusStatisticsResponse res = smsClient.SendStatusStatistics(req);// 输出json格式的字符串回包System.out.println(SendStatusStatisticsResponse.toJsonString(res));} catch (TencentCloudSDKException e) {e.printStackTrace();}}
}
  • 短信测试类
import com.example.demo.TencentSmsApplication;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;/*** Tencent Cloud Sms client test*/
@RunWith(SpringRunner.class)
@SpringBootTest(classes = TencentSmsApplication.class)
public class TencentSmsTest {@Autowiredprivate SendSms sendSms;@Autowiredprivate PullSmsSendStatus pullSmsSendStatus;@Autowiredprivate SendStatusStatistics sendStatusStatistics;@Autowiredprivate AddSmsTemplate addSmsTemplate;@Testpublic void testSendSms() {sendSms.sendSms();}@Testpublic void testPullSmsSendStatus() {pullSmsSendStatus.pullSmsSendStatus();}@Testpublic void testSendStatusStatistics() {sendStatusStatistics.sendStatusStatistics();}@Testpublic void testAddSmsTemplate() {addSmsTemplate.addSmsTemplate();}}

四、测试结果展示

Connected to the target VM, address: '127.0.0.1:50141', transport: 'socket'
16:54:29.238 [main] DEBUG org.springframework.test.context.junit4.SpringJUnit4ClassRunner - SpringJUnit4ClassRunner constructor called with [class com.example.demo.sms.TencentSmsTest]
16:54:29.249 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating CacheAwareContextLoaderDelegate from class [org.springframework.test.context.cache.DefaultCacheAwareContextLoaderDelegate]
16:54:29.260 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating BootstrapContext using constructor [public org.springframework.test.context.support.DefaultBootstrapContext(java.lang.Class,org.springframework.test.context.CacheAwareContextLoaderDelegate)]
16:54:29.322 [main] DEBUG org.springframework.test.context.BootstrapUtils - Instantiating TestContextBootstrapper for test class [com.example.demo.sms.TencentSmsTest] from class [org.springframework.boot.test.context.SpringBootTestContextBootstrapper]
16:54:29.351 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Neither @ContextConfiguration nor @ContextHierarchy found for test class [com.example.demo.sms.TencentSmsTest], using SpringBootContextLoader
16:54:29.356 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.demo.sms.TencentSmsTest]: class path resource [com/example/demo/sms/TencentSmsTest-context.xml] does not exist
16:54:29.357 [main] DEBUG org.springframework.test.context.support.AbstractContextLoader - Did not detect default resource location for test class [com.example.demo.sms.TencentSmsTest]: class path resource [com/example/demo/sms/TencentSmsTestContext.groovy] does not exist
16:54:29.357 [main] INFO org.springframework.test.context.support.AbstractContextLoader - Could not detect default resource locations for test class [com.example.demo.sms.TencentSmsTest]: no resource found for suffixes {-context.xml, Context.groovy}.
16:54:29.448 [main] DEBUG org.springframework.test.context.support.ActiveProfilesUtils - Could not find an 'annotation declaring class' for annotation type [org.springframework.test.context.ActiveProfiles] and class [com.example.demo.sms.TencentSmsTest]
16:54:29.678 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - @TestExecutionListeners is not present for class [com.example.demo.sms.TencentSmsTest]: using defaults.
16:54:29.678 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Loaded default TestExecutionListener class names from location [META-INF/spring.factories]: [org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener, org.springframework.test.context.web.ServletTestExecutionListener, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener, org.springframework.test.context.support.DependencyInjectionTestExecutionListener, org.springframework.test.context.support.DirtiesContextTestExecutionListener, org.springframework.test.context.transaction.TransactionalTestExecutionListener, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener, org.springframework.test.context.event.EventPublishingTestExecutionListener]
16:54:29.694 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.transaction.TransactionalTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttributeSource]
16:54:29.695 [main] DEBUG org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Skipping candidate TestExecutionListener [org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener] due to a missing dependency. Specify custom listener classes or make the default listener classes and their required dependencies available. Offending class: [org/springframework/transaction/interceptor/TransactionAttribute]
16:54:29.695 [main] INFO org.springframework.boot.test.context.SpringBootTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@7bd7d6d6, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@43f02ef2, org.springframework.boot.test.mock.mockito.MockitoTestExecutionListener@239a307b, org.springframework.boot.test.autoconfigure.SpringBootDependencyInjectionTestExecutionListener@2a8448fa, org.springframework.test.context.support.DirtiesContextTestExecutionListener@6f204a1a, org.springframework.test.context.event.EventPublishingTestExecutionListener@2de56eb2, org.springframework.boot.test.mock.mockito.ResetMocksTestExecutionListener@5f8e8a9d, org.springframework.boot.test.autoconfigure.restdocs.RestDocsTestExecutionListener@5745ca0e, org.springframework.boot.test.autoconfigure.web.client.MockRestServiceServerResetTestExecutionListener@3ad83a66, org.springframework.boot.test.autoconfigure.web.servlet.MockMvcPrintOnlyOnFailureTestExecutionListener@3cce5371, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverTestExecutionListener@17bffc17, org.springframework.boot.test.autoconfigure.webservices.client.MockWebServiceServerTestExecutionListener@6e535154]
16:54:29.698 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.701 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.703 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.703 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.703 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.703 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.715 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.715 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.717 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.717 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.718 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.718 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.724 [main] DEBUG org.springframework.test.context.support.AbstractDirtiesContextTestExecutionListener - Before test class: context [DefaultTestContext@23941fb4 testClass = TencentSmsTest, testInstance = [null], testMethod = [null], testException = [null], mergedContextConfiguration = [WebMergedContextConfiguration@7486b455 testClass = TencentSmsTest, locations = '{}', classes = '{class com.example.demo.Demo1Application}', contextInitializerClasses = '[]', activeProfiles = '{}', propertySourceLocations = '{}', propertySourceProperties = '{org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}', contextCustomizers = set[org.springframework.boot.test.context.filter.ExcludeFilterContextCustomizer@74f0ea28, org.springframework.boot.test.json.DuplicateJsonObjectContextCustomizerFactory$DuplicateJsonObjectContextCustomizer@3349e9bb, org.springframework.boot.test.mock.mockito.MockitoContextCustomizer@0, org.springframework.boot.test.web.client.TestRestTemplateContextCustomizer@76505305, org.springframework.boot.test.autoconfigure.properties.PropertyMappingContextCustomizer@0, org.springframework.boot.test.autoconfigure.web.servlet.WebDriverContextCustomizerFactory$Customizer@408d971b, org.springframework.boot.test.context.SpringBootTestArgs@1, org.springframework.boot.test.context.SpringBootTestWebEnvironment@2145b572], resourceBasePath = 'src/main/webapp', contextLoader = 'org.springframework.boot.test.context.SpringBootContextLoader', parent = [null]], attributes = map['org.springframework.test.context.web.ServletTestExecutionListener.activateListener' -> true]], class annotated with @DirtiesContext [false] with mode [null].
16:54:29.727 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved @ProfileValueSourceConfiguration [null] for test class [com.example.demo.sms.TencentSmsTest]
16:54:29.727 [main] DEBUG org.springframework.test.annotation.ProfileValueUtils - Retrieved ProfileValueSource type [class org.springframework.test.annotation.SystemProfileValueSource] for class [com.example.demo.sms.TencentSmsTest]
16:54:29.772 [main] DEBUG org.springframework.test.context.support.TestPropertySourceUtils - Adding inlined properties to environment: {spring.jmx.enabled=false, org.springframework.boot.test.context.SpringBootTestContextBootstrapper=true}.   ____          _            __ _ _/\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \\\/  ___)| |_)| | | | | || (_| |  ) ) ) )'  |____| .__|_| |_|_| |_\__, | / / / /=========|_|==============|___/=/_/_/_/:: Spring Boot ::       (v2.3.12.RELEASE)2023-03-24 16:54:30.153  INFO 5336 --- [           main] com.example.demo.sms.TencentSmsTest      : Starting TencentSmsTest on DESKTOP-2F8ODD2 with PID 5336 (started by dell in E:\jeecg-code\demo1)
2023-03-24 16:54:30.155  INFO 5336 --- [           main] com.example.demo.sms.TencentSmsTest      : No active profile set, falling back to default profiles: default
2023-03-24 16:54:30.446  WARN 5336 --- [kground-preinit] o.s.h.c.j.Jackson2ObjectMapperBuilder    : For Jackson Kotlin classes support please add "com.fasterxml.jackson.module:jackson-module-kotlin" to the classpath
2023-03-24 16:54:37.954  INFO 5336 --- [           main] o.s.s.concurrent.ThreadPoolTaskExecutor  : Initializing ExecutorService 'applicationTaskExecutor'
2023-03-24 16:54:38.092  INFO 5336 --- [           main] o.s.b.a.w.s.WelcomePageHandlerMapping    : Adding welcome page: class path resource [static/index.html]
2023-03-24 16:54:38.364  INFO 5336 --- [           main] com.example.demo.sms.TencentSmsTest      : Started TencentSmsTest in 8.564 seconds (JVM running for 9.83)
{"AddTemplateStatus":{"TemplateId":"1741626"},"RequestId":"9f80aff5-0d1e-4967-a8c5-18107bfd6679"}
9f80aff5-0d1e-4967-a8c5-18107bfd6679
{"PullSmsSendStatusSet":[],"RequestId":"297455c9-e68f-4684-92c1-bc1bda5b1314"}
{"SendStatusStatistics":{"FeeCount":0,"RequestCount":0,"RequestSuccessCount":0},"RequestId":"2901cae7-9b80-4059-967a-e7c460e560e4"}
{"SendStatusSet":[{"SerialNo":"","PhoneNumber":"+8621212313123","Fee":0,"SessionContext":"","Code":"FailedOperation.TemplateUnapprovedOrNotExist","Message":"template is not approved or not exist","IsoCode":""},{"SerialNo":"","PhoneNumber":"+8612345678902","Fee":0,"SessionContext":"","Code":"FailedOperation.TemplateUnapprovedOrNotExist","Message":"template is not approved or not exist","IsoCode":""},{"SerialNo":"","PhoneNumber":"+8612345678903","Fee":0,"SessionContext":"","Code":"FailedOperation.TemplateUnapprovedOrNotExist","Message":"template is not approved or not exist","IsoCode":""}],"RequestId":"5b849308-fd7f-462e-b131-405dd24c3e83"}
2023-03-24 16:54:39.893  INFO 5336 --- [extShutdownHook] o.s.s.concurrent.ThreadPoolTaskExecutor  : Shutting down ExecutorService 'applicationTaskExecutor'
Disconnected from the target VM, address: '127.0.0.1:50141', transport: 'socket'Process finished with exit code 0

五、其他说明

  • 腾讯云java-sdk,gitee仓库地址:tencentcloud/tencentcloud-sdk-java (gitee.com),工程引用参照相应版本
  • 腾讯云短信产品说明文档地址:短信简介_短信购买指南_短信操作指南-腾讯云 (tencent.com)

http://www.ppmy.cn/news/856639.html

相关文章

C:字符串、字符串指针、字符串函数

目录 一、C字符串&#xff08;字符数组&#xff09;二、字符串常量指针&#xff08;指向字符串的指针&#xff09;!!!三、C字符串函数strlen(str)strcat(s1, s2);strtok()strcpy(s1, s2)strcmp(s1, s2)strchr(s1, ch);strstr(s1, s2);strlwr(str); // lowerstrupr(str); // upp…

渲染首页数据

01 搭建项目 Vite Vue3 &#xff1a; https://xuexiluxian.cn/blog/detail/5e5d17f75af14e1586d3471f613e458602 Vite Vue项目安装router &#xff1a; https://xuexiluxian.cn/blog/detail/0a44da50c0b440d6b8f591867f8909f503 先做首页头部吧&#xff0c;先做准备工作 : ht…

JS--es6模板字符串

一、模板字符串空格 const str 这是一个${" "}空格; console.log(str); // 这是一个 空格二、模板字符串换行 1.转义 const str 这是一个换行\n内容; console.log(str); //这是一个换行 //内容2.缩进换行 const code function test() {con…

CKA备考实验 | 镜像管理

书籍来源&#xff1a;《CKA/CKAD应试指南&#xff1a;从Docker到Kubernetes完全攻略》 一边学习一边整理老师的课程内容及实验笔记&#xff0c;并与大家分享&#xff0c;侵权即删&#xff0c;谢谢支持&#xff01; 附上汇总贴&#xff1a;CKA备考实验 | 汇总_热爱编程的通信人…

2020全国工业互联网安全技术技能大赛Web题WP

0x00 SimpleCalculator 打开后&#xff0c;发现flag.php可执行数学函数&#xff0c;在网上找到一个原题&#xff1a;https://www.cnblogs.com/20175211lyz/p/11588219.html 可执行shell拿到flag。 payload如下&#xff1a; http://eci-1cei547jhyas2r4f5r2.cloudeci1.ichunqi…

雷诺卡车Renault C460 发动机失火故障

这是一个简短的案例研究&#xff0c;但这会展现正确的操作步骤&#xff0c;你将发现此任务更简易。在这个案例挑战中&#xff0c;这是一台配备D11发动机的雷诺C460卡车。客户抱怨此车性能不佳且像是发动机失火的异常抖动。没有任何警告灯显示在仪表台上&#xff0c;这很有趣&am…

联想服务器无线网卡被禁用,win10系统联想笔记本禁用无线网络适配器的处理技巧...

有关win10系统联想笔记本禁用无线网络适配器的操作方法想必大家有所耳闻。但是能够对win10系统联想笔记本禁用无线网络适配器进行实际操作的人却不多。其实解决win10系统联想笔记本禁用无线网络适配器的问题也不是难事&#xff0c;小编这里提示两点&#xff1a;1、在联想笔记本…

Node+mysql-注册和登录账号实现(原生)

1.创建数据表 说明&#xff1a;创建id&#xff0c;username,password字段&#xff0c;并设置了类型。 2.导入mysql库 npm i mysql2.18.1 3.创建了db文件夹 说明&#xff1a;创建mysql数据池 // 导入mysql包 const mysqlrequire("mysql") // 创建mysql连接池 const…