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
.package mainimport ("encoding/json""fmt""os""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" // Import SMS)func main() {// Required steps:// Instantiate an authentication object. The input parameters need Tencent Cloud account key pair SecretId, SecretKey.// 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.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// credential := common.NewCredential("SecretId", "SecretKey")credential := common.NewCredential(os.Getenv("TENCENTCLOUD_SECRET_ID"),os.Getenv("TENCENTCLOUD_SECRET_KEY"),)/* Optional steps:* Instantiate a client configuration object. You can specify the timeout period and other configuration items */cpf := profile.NewClientProfile()/* The SDK uses the POST method by default* If you have to use the GET method, you can set it here, but the GET method cannot handle some large requests */cpf.HttpProfile.ReqMethod = "POST"cpf.HttpProfile.ReqTimeout = 10 // Request timeout time, in seconds (the default value is 60 seconds)/* Specifies the access region domain name. The default nearby region domain name is sms.tencentcloudapi.com. Specifying a region domain name for access is also supported. For example, the domain name for the Singapore region is sms.ap-singapore.tencentcloudapi.com */cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"/* The SDK uses `TC3-HMAC-SHA256` to sign by default. Do not modify this field unless absolutely necessary */cpf.SignMethod = "HmacSHA1"/* Instantiate the client object of the requested product (with SMS as an example)* The second parameter is the information on the region you select in Tencent Cloud International. you can directly fill in the string ap-singapore. Click https://www.tencentcloud.com/document/api/382/40466?lang=en#region-list to view the region list. */client, _ := sms.NewClient(credential, "ap-singapore", cpf)/* Instantiate a request object. You can further set the request parameters according to the API called and actual conditions* You can directly check the SDK source code to determine which attributes of the API can be set* 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 */request := sms.NewSendSmsRequest()/* Settings of a basic parameter:* The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them.* The SDK provides encapsulation functions for importing the pointers of basic parameters* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper: https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1 *//* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */request.SmsSdkAppId = common.StringPtr("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] */request.SignName = common.StringPtr("xxx")/* `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 */request.SenderId = common.StringPtr("")/* User session content, which can carry context information such as user-side ID and will be returned as-is by the server */request.SessionContext = common.StringPtr("xxx")/* SMS code number extension, which is not activated by default. If you need to activate it, please contact [SMS Helper] */request.ExtendCode = common.StringPtr("")/* Template parameters. If there are no template parameters, leave it empty */request.TemplateParamSet = common.StringPtrs([]string{"0"})/* Template ID. You must enter the ID of an approved template, which can be viewed in the [SMS console] */request.TemplateId = common.StringPtr("449739")/* 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 */request.PhoneNumberSet = common.StringPtrs([]string{"+60198890000"})// Call the API you want to access through the client object. You need to pass in the request objectresponse, err := client.SendSms(request)// Handle the exceptionif _, ok := err.(*errors.TencentCloudSDKError); ok {fmt.Printf("An API error has returned: %s", err)return}// This is a direct failure instead of SDK exception. You can add other troubleshooting measures in the real code.if err != nil {panic(err)}b, _ := json.Marshal(response.Response)// Print the returned JSON stringfmt.Printf("%s", b)}
package mainimport ("encoding/json""fmt""os""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" // Import SMS)func main() {// Required steps:// Instantiate an authentication object. The input parameters need Tencent Cloud account key pair SecretId, SecretKey.// 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.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// credential := common.NewCredential("SecretId", "SecretKey")credential := common.NewCredential(os.Getenv("TENCENTCLOUD_SECRET_ID"),os.Getenv("TENCENTCLOUD_SECRET_KEY"),)/* Optional steps:* Instantiate a client configuration object. You can specify the timeout period and other configuration items */cpf := profile.NewClientProfile()/* The SDK uses the POST method by default* If you have to use the GET method, you can set it here, but the GET method cannot handle some large requests */cpf.HttpProfile.ReqMethod = "POST"/* The SDK has a default timeout period. Do not adjust it unless absolutely necessary* If needed, check in the code to get the latest default value */// cpf.HttpProfile.ReqTimeout = 5/* The SDK automatically specifies the domain name. Generally, you don't need to specify a domain name, but if you are accessing a service in a finance zone,* you need to manually specify the domain name. For example, the SMS domain name of the Shanghai Finance Zone is `sms.ap-shanghai-fsi.tencentcloudapi.com` */cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"/* The SDK uses `TC3-HMAC-SHA256` to sign by default* Do not modify this field unless absolutely necessary */cpf.SignMethod = "HmacSHA1"/* Instantiate the client object of the requested product (with SMS as an example)* The second 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. */client, _ := sms.NewClient(credential, "ap-singapore", cpf)/* Instantiate a request object. You can further set the request parameters according to the API called and actual conditions* You can directly check the SDK source code to determine which attributes of the API can be set* 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 */request := sms.NewPullSmsSendStatusRequest()/* Settings of a basic parameter:* The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them.* The SDK provides encapsulation functions for importing the pointers of basic parameters* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper: https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1 *//* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */request.SmsSdkAppId = common.StringPtr("2400006666")/* Maximum number of pulled entries. Maximum value: 100 */request.Limit = common.Uint64Ptr(10)// Call the API you want to access through the client object. You need to pass in the request objectresponse, err := client.PullSmsSendStatus(request)// Handle the exceptionif _, ok := err.(*errors.TencentCloudSDKError); ok {fmt.Printf("An API error has returned: %s", err)return}// This is a direct failure instead of SDK exception. You can add other troubleshooting measures in the real code.if err != nil {panic(err)}b, _ := json.Marshal(response.Response)// Print the returned JSON stringfmt.Printf("%s", b)}
package mainimport ("encoding/json""fmt""os""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" // Import SMS)func main() {// Required steps:// Instantiate an authentication object. The input parameters need Tencent Cloud account key pair SecretId, SecretKey.// 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.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// credential := common.NewCredential("SecretId", "SecretKey")credential := common.NewCredential(os.Getenv("TENCENTCLOUD_SECRET_ID"),os.Getenv("TENCENTCLOUD_SECRET_KEY"),)/* Optional steps:* Instantiate a client configuration object. You can specify the timeout period and other configuration items */cpf := profile.NewClientProfile()/* The SDK uses the POST method by default* If you have to use the GET method, you can set it here, but the GET method cannot handle some large requests */cpf.HttpProfile.ReqMethod = "POST"/* The SDK has a default timeout period. Do not adjust it unless absolutely necessary* If needed, check in the code to get the latest default value */// cpf.HttpProfile.ReqTimeout = 5/* The SDK automatically specifies the domain name. Generally, you don't need to specify a domain name, but if you are accessing a service in a finance zone,* you need to manually specify the domain name. For example, the SMS domain name of the Shanghai Finance Zone is `sms.ap-shanghai-fsi.tencentcloudapi.com` */cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"/* The SDK uses `TC3-HMAC-SHA256` to sign by default* Do not modify this field unless absolutely necessary */cpf.SignMethod = "HmacSHA1"/* Instantiate the client object of the requested product (with SMS as an example)* The second 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. */client, _ := sms.NewClient(credential, "ap-singapore", cpf)/* Instantiate a request object. You can further set the request parameters according to the API called and actual conditions* You can directly check the SDK source code to determine which attributes of the API can be set* 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 */request := sms.NewSendStatusStatisticsRequest()/* Settings of a basic parameter:* The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them.* The SDK provides encapsulation functions for importing the pointers of basic parameters* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper: https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1 *//* SMS application ID, which is the `SdkAppId` generated after an application is added in the [SMS console], such as 2400006666 */request.SmsSdkAppId = common.StringPtr("2400006666")/* Maximum number of pulled entries. Maximum value: 100 */request.Limit = common.Uint64Ptr(10)/* Offset. Note: this parameter is currently fixed at 0 */request.Offset = common.Uint64Ptr(0)/* Start time of pull in the format of `yyyymmddhh` accurate to the hour */request.BeginTime = common.StringPtr("2019122400")/* End time of pull in the format of `yyyymmddhh` accurate to the hour* Note: `EndTime` must be after `BeginTime` */request.EndTime = common.StringPtr("2019122523")// Call the API you want to access through the client object. You need to pass in the request objectresponse, err := client.SendStatusStatistics(request)// Handle the exceptionif _, ok := err.(*errors.TencentCloudSDKError); ok {fmt.Printf("An API error has returned: %s", err)return}// This is a direct failure instead of SDK exception. You can add other troubleshooting measures in the real code.if err != nil {panic(err)}b, _ := json.Marshal(response.Response)// Print the returned JSON stringfmt.Printf("%s", b)}
package mainimport ("encoding/json""fmt""os""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/errors""github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/common/profile"sms "github.com/tencentcloud/tencentcloud-sdk-go/tencentcloud/sms/v20210111" // Import SMS)func main() {// Required steps:// Instantiate an authentication object. The input parameters need Tencent Cloud account key pair SecretId, SecretKey.// 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.// For SecretId, SecretKey lookup: https://console.tencentcloud.com/cam/capi// credential := common.NewCredential("SecretId", "SecretKey")credential := common.NewCredential(os.Getenv("TENCENTCLOUD_SECRET_ID"),os.Getenv("TENCENTCLOUD_SECRET_KEY"),)/* Optional steps:* Instantiate a client configuration object. You can specify the timeout period and other configuration items */cpf := profile.NewClientProfile()/* The SDK uses the POST method by default* If you need to use the GET method, you can set it here, but the GET method cannot handle some large requests */cpf.HttpProfile.ReqMethod = "POST"/* The SDK has a default timeout period. Do not adjust it unless absolutely necessary* If needed, check in the code to get the latest default value */// cpf.HttpProfile.ReqTimeout = 5/* The SDK automatically specifies the domain name. Generally, you don't need to specify a domain name, but if you are accessing a service in a finance AZ, you must manually specify the domain name* For example, the SMS domain name of the Shanghai Finance Zone is `sms.ap-shanghai-fsi.tencentcloudapi.com` */cpf.HttpProfile.Endpoint = "sms.tencentcloudapi.com"/* The SDK uses `TC3-HMAC-SHA256` to sign by default. Do not modify this field unless absolutely necessary */cpf.SignMethod = "HmacSHA1"/* Instantiate an SMS client object* The second 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. */client, _ := sms.NewClient(credential, "ap-singapore", cpf)/* Instantiate a request object. You can further set the request parameters according to the API called and actual conditions* You can directly check the SDK source code to determine which attributes of the API can be set* 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 */request := sms.NewAddSmsTemplateRequest()/* Settings of a basic parameter:* The SDK uses the pointer style to specify parameters, so even for basic parameters, you need to use pointers to assign values to them* The SDK provides encapsulation functions for importing the pointers of basic parameters* Help link:* SMS console: https://console.tencentcloud.com/smsv2* sms helper:https://www.tencentcloud.com/document/product/382/3773?from_cn_redirect=1*//* Template name */request.TemplateName = common.StringPtr("Tencent")/* Template content */request.TemplateContent = common.StringPtr("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 */request.SmsType = common.Uint64Ptr(3)/* Whether it is Global SMS:0: Mainland China SMS1: Global SMS */request.International = common.Uint64Ptr(0)/* Template remarks, such as reason for application and use case */request.Remark = common.StringPtr("xxx")// Call the API you want to access through the client object. You need to pass in the request objectresponse, err := client.AddSmsTemplate(request)// Handle the exceptionif _, ok := err.(*errors.TencentCloudSDKError); ok {fmt.Printf("An API error has returned: %s", err)return}// This is a direct failure instead of SDK exception. You can add other troubleshooting measures in the real codeif err != nil {panic(err)}b, _ := json.Marshal(response.Response)// Print the returned JSON stringfmt.Printf("%s", b)}
https_proxy
; otherwise, it may not be called normally, and a connection timeout exception will be thrown.GODEBUG=netdns=cgo
or specify the -tags 'netcgo'
parameter when compiling go build
so as to get the nscd cache.import "crypto/tls"...client, _ := cvm.NewClient(credential, regions.Guangzhou, cpf)tr := &http.Transport{TLSClientConfig: &tls.Config{InsecureSkipVerify: true},}client.WithHttpTransport(tr)...
imported and not used: "os"
is reported, it means that the package os
is not used in the code. Therefore, simply remove it.
Was this page helpful?