sms.tencentcloudapi.com
。#include <tencentcloud/core/TencentCloud.h>#include <tencentcloud/core/profile/HttpProfile.h>#include <tencentcloud/core/profile/ClientProfile.h>#include <tencentcloud/core/Credential.h>#include <tencentcloud/core/NetworkProxy.h>#include <tencentcloud/core/AsyncCallerContext.h>#include <tencentcloud/sms/v20210111/SmsClient.h>#include <tencentcloud/sms/v20210111/model/SendSmsRequest.h>#include <tencentcloud/sms/v20210111/model/SendSmsResponse.h>#include <cstdlib>#include <iostream>#include <string>using namespace TencentCloud;using namespace TencentCloud::Sms::V20210111;using namespace TencentCloud::Sms::V20210111::Model;using namespace std;int main(){TencentCloud::InitAPI();// use the sdk// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey, 切勿将密钥泄露给他人// 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。// 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。// 前往 https://console.tencentcloud.com/cam/capi 获取 API 密钥 SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个http选项,可选的,没有特殊需求可以跳过。HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // 状态保持,默认是FalsehttpProfile.SetEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)httpProfile.SetReqTimeout(10); // 请求超时时间,单位为秒(默认60秒)httpProfile.SetConnectTimeout(10); // 响应超时时间,单位是秒(默认是60秒)ClientProfile clientProfile = ClientProfile(httpProfile);SendSmsRequest req = SendSmsRequest();/* 帮助链接:* 短信控制台: https://console.tencentcloud.com/smsv2*//* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SdkAppId,例如2400006666 */req.SetSmsSdkAppId("2400006666");/* 短信签名内容: 使用 UTF-8 编码,必须填写已审核通过的签名 */req.SetSignName("Tencent");/* 模板 ID: 必须填写已审核通过的模板 ID */req.SetTemplateId("449739");/* 模板参数: 模板参数的个数需要与 TemplateId 对应模板的变量个数保持一致,若无模板参数,则设置为空 */req.SetTemplateParamSet(std::vector<std::string>{"1234"});/* 下发手机号码,采用 E.164 标准,+[国家或地区码][手机号]* 示例如:+60198890000, 其中前面有一个+号 ,60为国家码,198890000为手机号,最多不要超过200个手机号 */req.SetPhoneNumberSet(std::vector<std::string>{"+60198890000"});/* 用户的 session 内容(无需要可忽略): 可以携带用户侧 ID 等上下文信息,server 会原样返回 */req.SetSessionContext("");/* 短信码号扩展号(无需要可忽略): 默认未开通,如需开通请提交工单*/req.SetExtendCode("");/* 国际/港澳台短信 senderid(无需要可忽略): 国内短信填空,默认未开通,如需开通请提交工单 */req.SetSenderId("");/* 实例化要请求产品(以sms为例)的client对象* 第二个参数是地域信息,可以直接填写字符串ap-singapore,支持的地域列表参考 https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list */SmsClient sms_client = SmsClient(cred, "ap-singapore", clientProfile);// 设置代理(无需要直接忽略)// NetworkProxy proxy = NetworkProxy(NetworkProxy::Type::HTTP, "localhost.proxy.com", 8080);// sms_client.SetNetworkProxy(proxy);auto outcome = sms_client.SendSms(req);if (!outcome.IsSuccess()){cout << outcome.GetError().PrintAll() << endl;TencentCloud::ShutdownAPI();return -1;}SendSmsResponse rsp = outcome.GetResult();cout<<"RequestId="<<rsp.GetRequestId()<<endl;cout<<"SendSmsResponse="<<rsp.ToJsonString()<<endl;TencentCloud::ShutdownAPI();/* 当出现以下错误码时,快速解决方案参考* [FailedOperation.SignatureIncorrectOrUnapproved](https://www.tencentcloud.com/document/product/382/9558)* [FailedOperation.TemplateIncorrectOrUnapproved](https://www.tencentcloud.com/document/product/382/9558)* [UnauthorizedOperation.SmsSdkAppIdVerifyFail](https://www.tencentcloud.com/document/product/382/9558)* [UnsupportedOperation.ContainDomesticAndInternationalPhoneNumber](https://www.tencentcloud.com/document/product/382/9558)*/return 0;}
#include <tencentcloud/core/TencentCloud.h>#include <tencentcloud/core/profile/HttpProfile.h>#include <tencentcloud/core/profile/ClientProfile.h>#include <tencentcloud/core/Credential.h>#include <tencentcloud/core/NetworkProxy.h>#include <tencentcloud/core/AsyncCallerContext.h>#include <tencentcloud/sms/v20210111/SmsClient.h>#include <tencentcloud/sms/v20210111/model/PullSmsSendStatusRequest.h>#include <tencentcloud/sms/v20210111/model/PullSmsSendStatusResponse.h>#include <cstdlib>#include <iostream>#include <string>using namespace TencentCloud;using namespace TencentCloud::Sms::V20210111;using namespace TencentCloud::Sms::V20210111::Model;using namespace std;int main(){TencentCloud::InitAPI();// use the sdk// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey, 切勿将密钥泄露给他人// 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。// 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。// 前往 https://console.tencentcloud.com/cam/capi 获取 API 密钥 SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个http选项,可选的,没有特殊需求可以跳过。HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // 状态保持,默认是FalsehttpProfile.SetEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)httpProfile.SetReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)httpProfile.SetConnectTimeout(30); // 响应超时时间,单位是秒(默认是60秒)ClientProfile clientProfile = ClientProfile(httpProfile);PullSmsSendStatusRequest req = PullSmsSendStatusRequest();/* 帮助链接:* 短信控制台: https://console.tencentcloud.com/smsv2*//* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SdkAppId,例如2400006666 */req.SetSmsSdkAppId("2400006666");// 设置拉取最大条数,最多100条req.SetLimit(100);SmsClient sms_client = SmsClient(cred, "ap-singapore", clientProfile);// set proxy// NetworkProxy proxy = NetworkProxy(NetworkProxy::Type::HTTP, "localhost.proxy.com", 8080);// cvm_client.SetNetworkProxy(proxy);auto outcome = sms_client.PullSmsSendStatus(req);if (!outcome.IsSuccess()){cout << outcome.GetError().PrintAll() << endl;TencentCloud::ShutdownAPI();return -1;}PullSmsSendStatusResponse rsp = outcome.GetResult();cout<<"RequestId="<<rsp.GetRequestId()<<endl;cout<<"PullSmsSendStatusResponse="<<rsp.ToJsonString()<<endl;TencentCloud::ShutdownAPI();return 0;}
#include <tencentcloud/core/TencentCloud.h>#include <tencentcloud/core/profile/HttpProfile.h>#include <tencentcloud/core/profile/ClientProfile.h>#include <tencentcloud/core/Credential.h>#include <tencentcloud/core/NetworkProxy.h>#include <tencentcloud/core/AsyncCallerContext.h>#include <tencentcloud/sms/v20210111/SmsClient.h>#include <tencentcloud/sms/v20210111/model/SendStatusStatisticsRequest.h>#include <tencentcloud/sms/v20210111/model/SendStatusStatisticsResponse.h>#include <cstdlib>#include <iostream>#include <string>using namespace TencentCloud;using namespace TencentCloud::Sms::V20210111;using namespace TencentCloud::Sms::V20210111::Model;using namespace std;int main(){TencentCloud::InitAPI();// use the sdk// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey, 切勿将密钥泄露给他人// 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。// 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。// 前往 https://console.tencentcloud.com/cam/capi 获取 API 密钥 SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个http选项,可选的,没有特殊需求可以跳过。HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // 状态保持,默认是FalsehttpProfile.SetEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)httpProfile.SetReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)httpProfile.SetConnectTimeout(30); // 响应超时时间,单位是秒(默认是60秒)ClientProfile clientProfile = ClientProfile(httpProfile);SendStatusStatisticsRequest req = SendStatusStatisticsRequest();/* 帮助链接:* 短信控制台: https://console.tencentcloud.com/smsv2*//* 短信应用 ID: 在 [短信控制台] 添加应用后生成的实际 SdkAppId,例如2400006666 */req.SetSmsSdkAppId("2400006666");// 最大上限,目前固定设置为0req.SetLimit(0);/* 偏移量,目前固定设置为0 */req.SetOffset(0);/* 设置起始时间,格式为yyyymmddhh,精确到小时,例如2021050113,表示2021年5月1号13时。 */req.SetBeginTime("2019071100");/* 设置结束时间,格式为yyyymmddhh,精确到小时,例如2021050118,表示2021年5月1号18时。注:EndTime 必须大于 BeginTime。 */req.SetEndTime("2019071123");SmsClient sms_client = SmsClient(cred, "ap-singapore", clientProfile);// set proxy// NetworkProxy proxy = NetworkProxy(NetworkProxy::Type::HTTP, "localhost.proxy.com", 8080);// cvm_client.SetNetworkProxy(proxy);auto outcome = sms_client.SendStatusStatistics(req);if (!outcome.IsSuccess()){cout << outcome.GetError().PrintAll() << endl;TencentCloud::ShutdownAPI();return -1;}SendStatusStatisticsResponse rsp = outcome.GetResult();cout<<"RequestId="<<rsp.GetRequestId()<<endl;cout<<"SendStatusStatisticsResponse="<<rsp.ToJsonString()<<endl;TencentCloud::ShutdownAPI();return 0;}
#include <tencentcloud/core/TencentCloud.h>#include <tencentcloud/core/profile/HttpProfile.h>#include <tencentcloud/core/profile/ClientProfile.h>#include <tencentcloud/core/Credential.h>#include <tencentcloud/core/NetworkProxy.h>#include <tencentcloud/core/AsyncCallerContext.h>#include <tencentcloud/sms/v20210111/SmsClient.h>#include <tencentcloud/sms/v20210111/model/AddSmsTemplateRequest.h>#include <tencentcloud/sms/v20210111/model/AddSmsTemplateResponse.h>#include <cstdlib>#include <iostream>#include <string>using namespace TencentCloud;using namespace TencentCloud::Sms::V20210111;using namespace TencentCloud::Sms::V20210111::Model;using namespace std;int main(){TencentCloud::InitAPI();// use the sdk// 实例化一个认证对象,入参需要传入腾讯云账户 SecretId 和 SecretKey, 切勿将密钥泄露给他人// 硬编码密钥到代码中有可能随代码泄露而暴露,有安全隐患,并不推荐。// 为了保护密钥安全,建议将密钥设置在环境变量中或者配置文件中。// 前往 https://console.tencentcloud.com/cam/capi 获取 API 密钥 SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// 实例化一个http选项,可选的,没有特殊需求可以跳过。HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // 状态保持,默认是FalsehttpProfile.SetEndpoint("sms.tencentcloudapi.com"); // 指定接入地域域名(默认就近接入)httpProfile.SetReqTimeout(30); // 请求超时时间,单位为秒(默认60秒)httpProfile.SetConnectTimeout(30); // 响应超时时间,单位是秒(默认是60秒)ClientProfile clientProfile = ClientProfile(httpProfile);AddSmsTemplateRequest req = AddSmsTemplateRequest();/* 帮助链接:* 短信控制台: https://console.tencentcloud.com/smsv2*//* 模板名称 */req.SetTemplateName("腾讯云");/* 模板内容 */req.SetTemplateContent("{1}为您的登录验证码,请于{2}分钟内填写,如非本人操作,请忽略本短信。");/* 短信类型,1表示营销短信,2表示通知短信,3表示验证码短信 */req.SetSmsType(3);/* 是否国际/港澳台短信:* 0:表示中国大陆地区短信* 1:表示国际/港澳台短信 */req.SetInternational(0);/* 模板备注:例如申请原因,使用场景等 */req.SetRemark("xxx");SmsClient sms_client = SmsClient(cred, "ap-singapore", clientProfile);// set proxy// NetworkProxy proxy = NetworkProxy(NetworkProxy::Type::HTTP, "localhost.proxy.com", 8080);// cvm_client.SetNetworkProxy(proxy);auto outcome = sms_client.AddSmsTemplate(req);if (!outcome.IsSuccess()){cout << outcome.GetError().PrintAll() << endl;TencentCloud::ShutdownAPI();return -1;}AddSmsTemplateResponse rsp = outcome.GetResult();cout<<"RequestId="<<rsp.GetRequestId()<<endl;cout<<"AddSmsTemplateResponse="<<rsp.ToJsonString()<<endl;TencentCloud::ShutdownAPI();return 0;}
本页内容是否解决了您的问题?