腾讯云短信接入

14 篇文章 0 订阅


一、前提条件

  • 已开通短信服务,创建签名和模板并通过审核,具体操作请参见 国内短信快速入门。
  • 如需发送国内短信,需要先 购买国内短信套餐包。
  • 已准备依赖环境: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 {
 
    @Autowired
    private TencentSmsProperty tencentSmsProperty;
 
    @Bean
    @ConditionalOnMissingBean
    public 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 {
 
    @Autowired
    private 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 {
 
    @Autowired
    private SmsClient smsClient;
    @Autowired
    private 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 {
 
    @Autowired
    private SmsClient smsClient;
    @Autowired
    private 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 {
 
    @Autowired
    private SmsClient smsClient;
    @Autowired
    private 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 {
 
    @Autowired
    private SendSms sendSms;
    @Autowired
    private PullSmsSendStatus pullSmsSendStatus;
    @Autowired
    private SendStatusStatistics sendStatusStatistics;
    @Autowired
    private AddSmsTemplate addSmsTemplate;
 
    @Test
    public void testSendSms() {
        sendSms.sendSms();
    }
 
    @Test
    public void testPullSmsSendStatus() {
        pullSmsSendStatus.pullSmsSendStatus();
    }
 
    @Test
    public void testSendStatusStatistics() {
        sendStatusStatistics.sendStatusStatistics();
    }
 
    @Test
    public 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)
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

mister-big

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值