SecretId
and SecretKey
on the Manage API Key page in the CAM console.SecretId
is used to identify the API caller.SecretKey
is a key used to encrypt the signature and help the server verify the signature. You should keep it private and avoid disclosure.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// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// To ensure key security, it's recommended to set the keys in environment variables or a configuration file.// Go to https://console.tencentcloud.com/cam/capi to obtain the API key SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option.HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // Specify whether to enable the keepalive feature. The default value is “false”.httpProfile.SetEndpoint("sms.tencentcloudapi.com"); // Specify the endpoint. If you do not specify it, nearby access is enabled by default.httpProfile.SetReqTimeout(10); // Specify the request timeout value, in seconds. The default value is 60s.httpProfile.SetConnectTimeout(10); // Specify the response timeout value, in seconds. The default value is 60s.ClientProfile clientProfile = ClientProfile(httpProfile);SendSmsRequest req = SendSmsRequest();/* Help link:* SMS console: https://console.tencentcloud.com/smsv2*//* SMS application ID: The SdkAppId generated after an application is added in the [SMS console], such as 2400006666 */req.SetSmsSdkAppId("2400006666");/* SMS signature content: You must enter an approved signature that is encoded in UTF-8.*/req.SetSignName("Tencent");/* Template ID: You must enter the ID of an approved template.*/req.SetTemplateId("449739");/* Template parameter: The number of template parameters must be the same as that of the variables in the template. If no template parameters are involved, leave this field empty.*/req.SetTemplateParamSet(std::vector<std::string>{"1234"});/* Target mobile number in the E.164 standard (+[country/region code][mobile number])* Example: +60198890000, which has a “+” sign followed by 60 (country/region code) and then by 198890000 (mobile number). Up to 200 mobile numbers are supported */req.SetPhoneNumberSet(std::vector<std::string>{"+60198890000"});/* (Ignorable) User session content: Context information like the user ID can be carried and will be returned by the server as is.*/req.SetSessionContext("");/* (Ignorable) SMS code number extension, which is not activated by default. If you need to activate it, submit a ticket.*/req.SetExtendCode("");/* (Ignorable) SenderId for Global SMS, which is not activated by default. If you need to activate it, submit a ticket. For Chinese Mainland SMS, leave it empty.*/req.SetSenderId("");/* Instantiate the client object of the product (with SMS as an example) to be requested.* The second parameter is used to specify region information. You can enter a string like "ap-singapore". For more supported regions, see https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list */SmsClient sms_client = SmsClient(cred, "ap-singapore", clientProfile);// (Ignorable) Set a proxy.// 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();/* Below are some error codes and the corresponding solutions to them:* [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// Instantiate an authentication object. Enter Tencent Cloud SecretId and SecretKey as input parameters, do not reveal the key to others// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// Go to https://console.tencentcloud.com/cam/capi to obtain the API key SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option.HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // Specify whether to enable the keepalive feature. The default value is “false”.httpProfile.SetEndpoint("sms.tencentcloudapi.com"); // Specify the endpoint. If you do not specify it, nearby access is enabled by default.httpProfile.SetReqTimeout(30); // Specify the request timeout value, in seconds. The default value is 60s.httpProfile.SetConnectTimeout(30); // Specify the response timeout value, in seconds. The default value is 60s.ClientProfile clientProfile = ClientProfile(httpProfile);PullSmsSendStatusRequest req = PullSmsSendStatusRequest();/* Help link:* SMS console: https://console.tencentcloud.com/smsv2*//* SMS application ID, which is the SdkAppId generated after an application is added in the [SMS console], such as 2400006666 */req.SetSmsSdkAppId("2400006666");// Set the max number of pulled entries. Max value: 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// Instantiate an authentication object. Enter Tencent Cloud SecretId and SecretKey as input parameters, do not reveal the key to others// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// Go to https://console.tencentcloud.com/cam/capi to obtain the API key SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option.HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // Specify whether to enable the keepalive feature. The default value is “false”.httpProfile.SetEndpoint("sms.tencentcloudapi.com"); // Specify the endpoint. If you do not specify it, nearby access is enabled by default.httpProfile.SetReqTimeout(30); // Specify the request timeout value, in seconds. The default value is 60s.httpProfile.SetConnectTimeout(30); // Specify the response timeout value, in seconds. The default value is 60s.ClientProfile clientProfile = ClientProfile(httpProfile);SendStatusStatisticsRequest req = SendStatusStatisticsRequest();/* Help link:* SMS console: https://console.tencentcloud.com/smsv2*//* SMS application ID, which is the SdkAppId generated after an application is added in the [SMS console], such as 2400006666 */req.SetSmsSdkAppId("2400006666");// Upper limit, which is currently fixed at 0.req.SetLimit(0);/* Offset, which is currently fixed at 0 */req.SetOffset(0);/* Start time in the format of “yyyymmddhh” accurate down to the hour, such as 2021050113 (13:00 on May 1, 2021).*/req.SetBeginTime("2019071100");/* End time in the format of “yyyymmddhh” accurate down to the hour, such as 2021050118 (18:00 on May 1, 2021).*/* Note: “EndTime” must be after “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// Instantiate an authentication object. Enter Tencent Cloud SecretId and SecretKey as input parameters, do not reveal the key to others// To protect key security, it is suggested to set keys in environment variables or configuration files. // Hardcoding keys into the code might lead to exposure through leaked code, posing a security vulnerability, and is not recommended.// Go to https://console.tencentcloud.com/cam/capi to obtain the API key SecretId SecretKeyCredential cred = Credential(getenv("TENCENTCLOUD_SECRET_ID"),getenv("TENCENTCLOUD_SECRET_KEY"));// (Optional) Instantiate an HTTP option.HttpProfile httpProfile = HttpProfile();httpProfile.SetKeepAlive(true); // Specify whether to enable the keepalive feature. The default value is “false”.httpProfile.SetEndpoint("sms.tencentcloudapi.com"); // Specify the endpoint. If you do not specify it, nearby access is enabled by default.httpProfile.SetReqTimeout(30); // Specify the request timeout value, in seconds. The default value is 60s.httpProfile.SetConnectTimeout(30); // Specify the response timeout value, in seconds. The default value is 60s.ClientProfile clientProfile = ClientProfile(httpProfile);AddSmsTemplateRequest req = AddSmsTemplateRequest();/* Help link:* SMS console: https://console.tencentcloud.com/smsv2*//* Template name */req.SetTemplateName("Tencent");/* Template content */req.SetTemplateContent("{Your login verification code is {1}. Please enter it within {2} minutes. If the login was not initiated by you, please ignore this message");/* SMS type. 1: Marketing SMS, 2: Notification SMS, 3: OTP SMS */req.SetSmsType(3);/* A parameter used to specify whether it is Global SMS:* 0: Chinese Mainland SMS* 1: Global SMS.*/req.SetInternational(0);/* Template remarks, such as the reason for application and its use cases.*/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;}
この記事はお役に立ちましたか?