SecretID
and SecretKey
on the API Key Management page in the CAM console.SecretID
is used to identify the API caller.SecretKey
is used to encrypt the string to sign that can be verified on the server. You should keep it private and avoid disclosure.sms.tencentcloudapi.com
.const tencentcloud = require("tencentcloud-sdk-nodejs")// Import the client models of the corresponding product moduleconst smsClient = tencentcloud.sms.v20210111.Client/* Instantiate the client object of the requested product (with SMS as an example) */const client = new smsClient({credential: {/* 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.* Query the CAM Key: https://console.tencentcloud.com/cam/capi */secretId: process.env.TENCENTCLOUD_SECRET_ID,secretKey: process.env.TENCENTCLOUD_SECRET_KEY,},/* Required: region information. The parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list. */region: "ap-singapore",/* Optional:* Client configuration object. You can specify the timeout period and other configuration items */profile: {/* The SDK uses `TC3-HMAC-SHA256` to sign by default. Do not modify this field unless absolutely necessary */signMethod: "HmacSHA256",httpProfile: {reqMethod: "POST", // Request MethodreqTimeout: 10, // Request timeout time, in seconds (the default value is 60 seconds)endpoint: "sms.tencentcloudapi.com"},},})/* Request parameter. You can further set the request parameters according to the API called and actual conditions* An attribute may be of a basic type or import another data structure* We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structure */const params = {/* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */SmsSdkAppId: "2400006666",/* SMS signature content, which should be encoded in UTF-8. You must enter an approved signature, which can be viewed in the [SMS console] */SignName: "xxx",/* SMS code number extension, which is not activated by default. If you need to activate it, please contact [SMS Helper] */ExtendCode: "",/* `senderid` for Global SMS, which is not activated by default. If you need to activate it, please contact [SMS Helper] for assistance. This parameter should be left empty for Mainland China SMS */SenderId: "",/* User session content, which can carry context information such as user-side ID and will be returned as-is by the server */SessionContext: "",/* 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 */PhoneNumberSet: ["+60198890000"],/* Template ID. You must enter the ID of an approved template, which can be viewed in the [SMS console] */TemplateId: "449739",/* Template parameters. If there are no template parameters, leave it empty */TemplateParamSet: ["666"],}// Call the API you want to access through the client object; you need to pass in the request object and the response callback functionclient.SendSms(params, function (err, response) {// The request returns an exception and the exception information is printedif (err) {console.log(err)return}// The request is returned normally, and the `response` object is printedconsole.log(response)})
const tencentcloud = require("tencentcloud-sdk-nodejs")// Import the client models of the corresponding product moduleconst smsClient = tencentcloud.sms.v20210111.Client/* Instantiate the client object of the requested product (with SMS as an example) */const client = new smsClient({credential: {/* 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.* Query the CAM Key: https://console.tencentcloud.com/cam/capi */secretId: process.env.TENCENTCLOUD_SECRET_ID,secretKey: process.env.TENCENTCLOUD_SECRET_KEY,},/* Required: region information. The parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list. */region: "ap-singapore",/* Optional:* Client configuration object. You can specify the timeout period and other configuration items */profile: {/* The SDK uses `TC3-HMAC-SHA256` to sign by default. Do not modify this field unless absolutely necessary */signMethod: "HmacSHA256",httpProfile: {reqMethod: "POST", // Request MethodreqTimeout: 30, // Request timeout time, in seconds (the default value is 60 seconds)endpoint: "sms.tencentcloudapi.com"},},})/* Request parameter. You can further set the request parameters according to the API called and actual conditions* An attribute may be of a basic type or import another data structure* We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structure */const params = {// SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666SmsSdkAppId: "2400006666",// Maximum number of pulled entries. Maximum value: 100Limit: 10,}// Call the API you want to access through the client object; you need to pass in the request object and the response callback functionclient.PullSmsSendStatus(params, function (err, response) {// The request returns an exception and the exception information is printedif (err) {console.log(err)return}// The request is returned normally, and the `response` object is printedconsole.log(response)})
const tencentcloud = require("tencentcloud-sdk-nodejs")// Import the client models of the corresponding product moduleconst smsClient = tencentcloud.sms.v20210111.Client/* Instantiate the client object of the requested product (with SMS as an example) */const client = new smsClient({credential: {/* 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.* Query the CAM Key: https://console.tencentcloud.com/cam/capi */secretId: process.env.TENCENTCLOUD_SECRET_ID,secretKey: process.env.TENCENTCLOUD_SECRET_KEY,},/* Required: region information. The parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list. */region: "ap-singapore",/* Optional:* Client configuration object. You can specify the timeout period and other configuration items */profile: {/* The SDK uses `TC3-HMAC-SHA256` to sign by default. Do not modify this field unless absolutely necessary */signMethod: "HmacSHA256",httpProfile: {reqMethod: "POST", // Request MethodreqTimeout: 30, // Request timeout time, in seconds (the default value is 60 seconds)endpoint: "sms.tencentcloudapi.com"},},})/* Request parameter. You can further set the request parameters according to the API called and actual conditions* An attribute may be of a basic type or import another data structure* We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structure */const params = {// SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 1400006666SmsSdkAppId: "2400006666",// Maximum number of pulled entries. Maximum value: 100Limit: 10,// Offset. Note: this parameter is currently fixed at 0Offset: 0,// Start time of pull in the format of `yyyymmddhh` accurate to the hourBeginTime: "2019122400",// End time of pull in the format of `yyyymmddhh` accurate to the hour// Note: `EndTime` must be after `BeginTime`EndTime: "2019122523",}// Call the API you want to access through the client object; you need to pass in the request object and the response callback functionclient.SendStatusStatistics(params, function (err, response) {// The request returns an exception and the exception information is printedif (err) {console.log(err)return}// The request is returned normally, and the `response` object is printedconsole.log(response)})
const tencentcloud = require("tencentcloud-sdk-nodejs")// Import the client models of the corresponding product moduleconst smsClient = tencentcloud.sms.v20210111.Client/* Instantiate the client object of the requested product (with SMS as an example) */const client = new smsClient({credential: {/* 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.* Query the CAM Key: https://console.tencentcloud.com/cam/capi */secretId: process.env.TENCENTCLOUD_SECRET_ID,secretKey: process.env.TENCENTCLOUD_SECRET_KEY,},/* Required: region information. The parameter is the information on the region you select in Tencent Cloud International. If you select Singapore, you should enter the string `ap-singapore`. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list. */region: "ap-singapore",/* Optional:* Client configuration object. You can specify the timeout period and other configuration items */profile: {/* The SDK uses `TC3-HMAC-SHA256` to sign by default. Do not modify this field unless absolutely necessary */signMethod: "HmacSHA256",httpProfile: {reqMethod: "POST", // Request MethodreqTimeout: 30, // Request timeout, default is 60sendpoint: "sms.tencentcloudapi.com"},},})/* Request parameter. You can further set the request parameters according to the API called and actual conditions* An attribute may be of a basic type or import another data structure* We recommend you use the IDE for development where you can easily redirect to and view the documentation of each API and data structure */const params = {/* Template name */TemplateName: "Tencent Cloud",/* Template content */TemplateContent: "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 */SmsType: 3,/* Whether it is Global SMS. 0: Mainland China SMS; 1: Global SMS */International: 0,/* Template remarks, such as reason for application and use case */Remark: "xxx",}// Call the API you want to access through the client object; you need to pass in the request object and the response callback functionclient.AddSmsTemplate(params, function (err, response) {// The request returns an exception and the exception information is printedif (err) {console.log(err)return}// The request is returned normally, and the `response` object is printedconsole.log(response)})
https_proxy
; otherwise, it may not be called normally, and a connection timeout exception will be thrown.
Was this page helpful?