### HTTP GET Request Structure Example (Signature Method v1) Source: https://cloud.tencent.com/document/product/1110/36920 Example of an HTTP GET request structure using Signature Method v1. This includes common parameters like Action, Version, SignatureMethod, Timestamp, Signature, Region, Nonce, and SecretId. ```http https://cvm.tencentcloudapi.com/?Action=DescribeInstances&Version=2017-03-12&SignatureMethod=HmacSHA256&Timestamp=1527672334&Signature=37ac2f4fde00b0ac9bd9eadeb459b1bbee224158d66e7ae5fcadb70b2d181d02&Region=ap-guangzhou&Nonce=23823223&SecretId=AKID******************************** Host: cvm.tencentcloudapi.com ``` -------------------------------- ### Example String to Sign Source: https://cloud.tencent.com/document/product/1110/36921 An example of the String to Sign, including the algorithm, timestamp, credential scope, and hashed canonical request. ```text TC3-HMAC-SHA256 1551113065 2019-02-25/cvm/tc3_request 7019a55be8395899b900fb5564e4200d984910f34794a27cb3fb7d10ff6a1e84 ``` -------------------------------- ### DescribeCaptchaMiniData API Request Example Source: https://cloud.tencent.com/document/product/1110/48472 This example shows how to construct a request to the DescribeCaptchaMiniData API to query security verification code data for mini-programs. It includes common parameters and specific query parameters like CaptchaAppId, Start, End, and Type. ```http https://captcha.tencentcloudapi.com/?Action=DescribeCaptchaMiniData &CaptchaAppId=201000000 &Start=2019112900 &End=2019112902 &Type=1 &<公共请求参数> ``` -------------------------------- ### Example Authorization Header Value Source: https://cloud.tencent.com/document/product/1110/36921 An example of a fully constructed Authorization header value based on the specified components. ```text TC3-HMAC-SHA256 Credential=AKID********************************/2019-02-25/cvm/tc3_request, SignedHeaders=content-type;host;x-tc-action, Signature=10b1a37a7301a02ca19a647ad722d5e43b4b3cff309d421d85b46093f6ab6c4f ``` -------------------------------- ### Golang API Signing Example Source: https://cloud.tencent.com/document/product/1110/36922 Illustrates how to compute an API signature using Golang. This example focuses on the core logic of parameter sorting and HMAC-SHA1 calculation. ```go package main import ( "crypto/hmac" "crypto/sha1" "encoding/base64" "fmt" "net/url" "sort" "strings" ) func getSignature(params map[string]string, secretKey string) string { // 1. 对参数进行排序 keys := make([]string, 0, len(params)) for k := range params { keys = append(keys, k) } sort.Strings(keys) // 2. 拼接请求字符串 var canonicalQueryString strings.Builder for _, k := range keys { canonicalQueryString.WriteString(url.QueryEscape(k)) canonicalQueryString.WriteString("=") canonicalQueryString.WriteString(url.QueryEscape(params[k])) canonicalQueryString.WriteString("&") } // 去掉最后一个& query := canonicalQueryString.String() if len(query) > 0 { query = query[:len(query)-1] } // 3. 拼接签名原文字符串 stringToSign := "GET" + "cvm.tencentcloudapi.com" + "/" + "?" + query // 4. 生成签名串 hmacSha1 := hmac.New(sha1.New, []byte(secretKey)) hmacSha1.Write([]byte(stringToSign)) return base64.StdEncoding.EncodeToString(hmacSha1.Sum(nil)) } func main() { // 示例参数 params := map[string]string{ "Action": "DescribeInstances", "Region": "ap-guangzhou", "Timestamp": "1510073600", "Nonce": "123456", "SecretId": "AKIDEXAMPLE", "SecretKey": "EXAMPLEKEY", "Version": "2017-03-12", } secretKey := "EXAMPLEKEY" signature := getSignature(params, secretKey) fmt.Println("Signature: " + signature) } ``` -------------------------------- ### Java API Signing Example Source: https://cloud.tencent.com/document/product/1110/36922 Demonstrates how to generate an API signature in Java. Ensure all necessary parameters are included and correctly processed. ```java import java.security.SignatureException; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Base64; public class Signature { private static final String HMAC_SHA1 = "HmacSHA1"; public static String computeSignature(String text, String secret) throws SignatureException { try { SecretKeySpec signingKey = new SecretKeySpec(secret.getBytes(), HMAC_SHA1); Mac mac = Mac.getInstance(HMAC_SHA1); mac.init(signingKey); byte[] rawHmac = mac.doFinal(text.getBytes()); return new String(Base64.encodeBase64(rawHmac)); } catch (Exception e) { throw new SignatureException("Failed to generate HMAC : " + e.getMessage()); } } public static String getSignature(Map params, String secretId, String secretKey, String method, String host, String action, String version, String endpoint) throws SignatureException { // 1. 对参数进行排序 List sortedKeys = new ArrayList(params.keySet()); Collections.sort(sortedKeys); // 2. 拼接请求字符串 StringBuilder canonicalQueryString = new StringBuilder(); for (String key : sortedKeys) { canonicalQueryString.append(key).append("=").append(params.get(key)).append("&"); } // 去掉最后一个& if (canonicalQueryString.length() > 0) { canonicalQueryString.deleteCharAt(canonicalQueryString.length() - 1); } // 3. 拼接签名原文字符串 StringBuilder stringToSign = new StringBuilder(); stringToSign.append(method).append(host).append(endpoint).append("?").append(canonicalQueryString); // 4. 生成签名串 String signature = computeSignature(stringToSign.toString(), secretKey); return signature; } public static void main(String[] args) { // 示例参数 Map params = new HashMap(); params.put("Action", "DescribeInstances"); params.put("Region", "ap-guangzhou"); params.put("Timestamp", "1510073600"); params.put("Nonce", "123456"); params.put("SecretId", "AKIDEXAMPLE"); params.put("SecretKey", "EXAMPLEKEY"); params.put("Version", "2017-03-12"); String secretId = "AKIDEXAMPLE"; String secretKey = "EXAMPLEKEY"; String method = "GET"; String host = "cvm.tencentcloudapi.com"; String action = "DescribeInstances"; String version = "2017-03-12"; String endpoint = "/"; try { String signature = getSignature(params, secretId, secretKey, method, host, action, version, endpoint); System.out.println("Signature: " + signature); } catch (SignatureException e) { e.printStackTrace(); } } } ``` -------------------------------- ### Common Parameters for Signature Method v1 Source: https://cloud.tencent.com/document/product/1110/36920 This section describes the common parameters that must be included in all Tencent Cloud API requests when using Signature Method v1. It provides examples for both HTTP GET and HTTP POST request structures. ```APIDOC ## GET / (Common Parameters) ### Description This example demonstrates how to include common parameters in an HTTP GET request using Signature Method v1. The parameters are included as query string parameters. ### Method GET ### Endpoint `https://cvm.tencentcloudapi.com/` (Base URL for Tencent Cloud APIs) ### Parameters #### Query Parameters - **Action** (String) - Required - The name of the operation interface. Refer to the API documentation for specific actions, e.g., `DescribeInstances` for querying CVM instances. - **Region** (String) - Optional - Region parameter, used to identify which region's data to operate on. Refer to the API documentation for accepted region values. Note: Some interfaces do not require this parameter; the documentation will specify this, and passing it will have no effect. - **Timestamp** (Integer) - Required - Current UNIX timestamp, recording the time the API request was initiated. For example, 1529223702. If the difference from the current time is too large, it will cause a signature expiration error. - **Nonce** (Integer) - Required - Random positive integer, combined with Timestamp to prevent replay attacks. - **SecretId** (String) - Required - The SecretId identifying the identity, applied on the Cloud API Key. A SecretId corresponds to a unique SecretKey, which is used to generate the request signature. - **Signature** (String) - Required - Request signature, used to verify the legality of this request. Users need to calculate it based on the actual input parameters. Refer to the documentation for specific calculation methods. - **Version** (String) - Required - The API version of the operation. Refer to the API documentation for specific version values, e.g., `2017-03-12` for CVM. - **SignatureMethod** (String) - Optional - Signature method. Currently supports `HmacSHA256` and `HmacSHA1`. Only when this parameter is specified as `HmacSHA256` will the `HmacSHA256` algorithm be used to verify the signature; otherwise, `HmacSHA1` will be used. - **Token** (String) - Optional - The Token from the temporary security credential issued by the Security Credential Service. When used, the values of SecretId and SecretKey need to be replaced with TmpSecretId and TmpSecretKey from the temporary security credential. This Token field cannot be set when using long-term keys. - **Language** (String) - Optional - Specifies the language for the interface return. Only some interfaces support this parameter. Values: `zh-CN` (Chinese) and `en-US` (English). `zh-CN` returns Chinese, `en-US` returns English. ### Request Example ``` GET https://cvm.tencentcloudapi.com/?Action=DescribeInstances&Version=2017-03-12&SignatureMethod=HmacSHA256&Timestamp=1527672334&Signature=37ac2f4fde00b0ac9bd9eadeb459b1bbee224158d66e7ae5fcadb70b2d181d02&Region=ap-guangzhou&Nonce=23823223&SecretId=AKID******************************** HTTP/1.1 Host: cvm.tencentcloudapi.com ``` ``` ```APIDOC ## POST / (Common Parameters) ### Description This example demonstrates how to include common parameters in an HTTP POST request using Signature Method v1. The parameters are included in the request body as `application/x-www-form-urlencoded`. ### Method POST ### Endpoint `https://cvm.tencentcloudapi.com/` (Base URL for Tencent Cloud APIs) ### Parameters #### Request Body - **Action** (String) - Required - The name of the operation interface. Refer to the API documentation for specific actions, e.g., `DescribeInstances` for querying CVM instances. - **Region** (String) - Optional - Region parameter, used to identify which region's data to operate on. Refer to the API documentation for accepted region values. Note: Some interfaces do not require this parameter; the documentation will specify this, and passing it will have no effect. - **Timestamp** (Integer) - Required - Current UNIX timestamp, recording the time the API request was initiated. For example, 1529223702. If the difference from the current time is too large, it will cause a signature expiration error. - **Nonce** (Integer) - Required - Random positive integer, combined with Timestamp to prevent replay attacks. - **SecretId** (String) - Required - The SecretId identifying the identity, applied on the Cloud API Key. A SecretId corresponds to a unique SecretKey, which is used to generate the request signature. - **Signature** (String) - Required - Request signature, used to verify the legality of this request. Users need to calculate it based on the actual input parameters. Refer to the documentation for specific calculation methods. - **Version** (String) - Required - The API version of the operation. Refer to the API documentation for specific version values, e.g., `2017-03-12` for CVM. - **SignatureMethod** (String) - Optional - Signature method. Currently supports `HmacSHA256` and `HmacSHA1`. Only when this parameter is specified as `HmacSHA256` will the `HmacSHA256` algorithm be used to verify the signature; otherwise, `HmacSHA1` will be used. - **Token** (String) - Optional - The Token from the temporary security credential issued by the Security Credential Service. When used, the values of SecretId and SecretKey need to be replaced with TmpSecretId and TmpSecretKey from the temporary security credential. This Token field cannot be set when using long-term keys. - **Language** (String) - Optional - Specifies the language for the interface return. Only some interfaces support this parameter. Values: `zh-CN` (Chinese) and `en-US` (English). `zh-CN` returns Chinese, `en-US` returns English. ### Request Example ``` POST https://cvm.tencentcloudapi.com/ HTTP/1.1 Host: cvm.tencentcloudapi.com Content-Type: application/x-www-form-urlencoded Action=DescribeInstances&Version=2017-03-12&SignatureMethod=HmacSHA256&Timestamp=1527672334&Signature=37ac2f4fde00b0ac9bd9eadeb459b1bbee224158d66e7ae5fcadb70b2d181d02&Region=ap-guangzhou&Nonce=23823223&SecretId=AKID******************************** ``` ``` -------------------------------- ### Embedded Captcha Example Source: https://cloud.tencent.com/document/product/1110/36841 Example of how to integrate the captcha in embedded mode. ```APIDOC ## Embedded Captcha Parameter Configuration Example ```html 验证码-内嵌接入
``` ``` -------------------------------- ### Complete HTTP Request Example Source: https://cloud.tencent.com/document/product/1110/36921 A full example of an HTTP POST request, including the Authorization header and other necessary headers and payload. Ensure headers and payload match signature calculation. ```http POST https://cvm.tencentcloudapi.com/ Authorization: TC3-HMAC-SHA256 Credential=AKID********************************/2019-02-25/cvm/tc3_request, SignedHeaders=content-type;host;x-tc-action, Signature=10b1a37a7301a02ca19a647ad722d5e43b4b3cff309d421d85b46093f6ab6c4f Content-Type: application/json; charset=utf-8 Host: cvm.tencentcloudapi.com X-TC-Action: DescribeInstances X-TC-Version: 2017-03-12 X-TC-Timestamp: 1551113065 X-TC-Region: ap-guangzhou {"Limit": 1, "Filters": [{"Values": ["\u672a\u547d\u540d"], "Name": "instance-name"}]} ``` -------------------------------- ### Example Canonical Request Source: https://cloud.tencent.com/document/product/1110/36921 An example of a fully constructed Canonical Request for a POST request to describe instances. ```text POST / content-type:application/json; charset=utf-8 host:cvm.tencentcloudapi.com x-tc-action:describeinstances content-type;host;x-tc-action 35e9c5b0e3ae67532d3c9f17ead6c90222632e5b1ff7f6e89887f1398934f064 ``` -------------------------------- ### DotNet API Signing Example Source: https://cloud.tencent.com/document/product/1110/36922 Provides a C# (.NET) example for API signature generation. This snippet details the process of sorting parameters, constructing the request string, and calculating the HMAC-SHA1 signature. ```csharp using System; using System.Collections.Generic; using System.Linq; using System.Security.Cryptography; using System.Text; public class Signature { public static string ComputeSignature(string text, string secretKey) { using (var hmac = new HMACSHA1(Encoding.UTF8.GetBytes(secretKey))) { byte[] data = hmac.ComputeHash(Encoding.UTF8.GetBytes(text)); return Convert.ToBase64String(data); } } public static string GetSignature(Dictionary paramsDict, string secretId, string secretKey, string method, string host, string endpoint) { // 1. 对参数进行排序 var sortedKeys = paramsDict.Keys.OrderBy(k => k).ToList(); // 2. 拼接请求字符串 var canonicalQueryString = new StringBuilder(); foreach (var key in sortedKeys) { canonicalQueryString.Append(Uri.EscapeDataString(key)).Append("=").Append(Uri.EscapeDataString(paramsDict[key])).Append("&"); } // 去掉最后一个& var query = canonicalQueryString.ToString().TrimEnd('&'); // 3. 拼接签名原文字符串 var stringToSign = new StringBuilder(); stringToSign.Append(method).Append(host).Append(endpoint).Append("?").Append(query); // 4. 生成签名串 string signature = ComputeSignature(stringToSign.ToString(), secretKey); return signature; } public static void Main(string[] args) { // 示例参数 var paramsDict = new Dictionary { {"Action", "DescribeInstances"}, {"Region", "ap-guangzhou"}, {"Timestamp", "1510073600"}, {"Nonce", "123456"}, {"SecretId", "AKIDEXAMPLE"}, {"SecretKey", "EXAMPLEKEY"}, {"Version", "2017-03-12"} }; string secretId = "AKIDEXAMPLE"; string secretKey = "EXAMPLEKEY"; string method = "GET"; string host = "cvm.tencentcloudapi.com"; string endpoint = "/"; string signature = GetSignature(paramsDict, secretId, secretKey, method, host, endpoint); Console.WriteLine("Signature: " + signature); } } ``` -------------------------------- ### Example Signature String Source: https://cloud.tencent.com/document/product/1110/36922 This is an example of a final signature string generated after Base64 encoding. It is used as part of the API request parameters. ```text 7RAM2xfNMO9EiVTNmPg06MRnCvQ= ```