Signature Algorithm
1. Algorithm Process
Provide the required parameters:
sid
(survey ID),timestamp
(current timestamp in milliseconds), andalgorithm_version
(signature algorithm version, using"v2"
), structured in a key-value (KV) format.Sort the keys in ascending order based on ASCII values.
Iterate through the sorted key-value structure and concatenate all elements into a string using the format
"key1value1key2value2"
.Apply the MD5 hashing algorithm to the concatenated string to generate the
sign
signature.Append the generated
sign
as a signature field to the key-value structure.Add
appSecret
as the signature key field in the key-value structure.Convert the key-value structure into HTTP query parameters or body parameters.
Attach the generated request parameters and invoke the session authentication API.
2.Configure Open API Secret
You can find the secret corresponding to your survey here and modify it if needed.

3.Full Example
Golang
package main
import (
"crypto/md5"
"encoding/hex"
"fmt"
"sort"
)
// Generate MD5 hash
func MD5(s string) string {
hash := md5.Sum([]byte(s))
return hex.EncodeToString(hash[:])
}
// Generate signature
func MakeSign(data map[string]string, secret string) string {
str := MakeSignParamStr(data, secret)
return MD5(str)
}
// Generate parameter string
func MakeSignParamStr(data map[string]string, secret string) string {
data["appSecret"] = secret
keys := make([]string, 0, len(data))
for key := range data {
keys = append(keys, key)
}
sort.Strings(keys)
str := ""
for _, key := range keys {
if data[key] != "" {
str += key + data[key]
}
}
delete(data, "appSecret")
return str
}
// Verify signature
func VerifySign(sign string, params map[string]string, secret string) bool {
return sign == MakeSign(params, secret)
}
func main() {
// Example parameters
params := map[string]string{
"sid": "67c6a30e2797730bf50d0972",
"timestamp": "1741071430",
"algorithm_version": "v2",
}
secret := "mySecretKey"
// Generate sign
sign := MakeSign(params, secret)
params["sign"] = sign
// Print result
fmt.Println("Generated sign:", sign)
fmt.Println("Final request parameters:", params)
}
4. Signature Verification
On this page: https://test.a.imur.tencent.com/static/tools-out/#/open_api, you can enter the required parameters to generate your signature, which is used to verify that your algorithm is consistent with ours.
最后更新于
这有帮助吗?