Brief Description
- Signature mechanism 和 Signature Example
Signature mechanism
Signature Key Generation Method
- Sort the request fields in the interface in ascending order based on their Ascii codes.
- Format it as
key1=val1&key2=val2&key3=val3…&key=md5_secret_key. - Encrypt the string generated in the previous step using MD5.
Signature Example
Example Request Parameters
json
{
"amount": "100",
"order_no": "ts3023423423",
"key": "adesf235"
}TypeScript Request Example
typescript
import * as crypto from 'crypto'
const payload = {
amount: "100",
order_no: "ts3023423423",
}
const secret = "adesf235" // md5秘钥
// 1. 排序(ASCII码升序)
const sortedKeys = Object.keys(payload).sort()
// 2. 拼接为 key1=val1&key2=val2... 的格式(不包含 key 字段)
const signingString = sortedKeys
.filter(key => key !== 'key') // 去掉 key 字段
.map(key => `${key}=${payload[key]}`)
.join('&') + `&key=${secret}`
// 3. 进行 MD5 加密
const signature = crypto.createHash('md5').update(signingString).digest('hex')
console.log("签名前字符串:", signingString)
console.log("签名:", signature)Note
- For more questions regarding the global request interface, please consult the administrator.
- Update Date: 2024-04-24