API Convention
API Convention
Encoding
Data encoding is uniformly set to utf-8
.
Keys
The appid
& appsecret
mentioned in the interface documentation refer to the merchant's appid
& appsecret
, which can be viewed in the Merchant Console under the "API Key Information" section.
Optional Fields
For interface parameters marked as optional
, you can either pass specific values or an empty string.
Data Submission
For interfaces that involve data submission, the uniform method is to use POST
. The content-type
field in the relevant request header is:
application/json
Data Response
The system uniformly returns JSON data, as shown below:
{
"code": 200, // 200 for success, others for failure
"message": "success", // success for success, others for failure description
"data": { // Refer to corresponding documentation for different interface returns
"arg": "87.26"
},
"request_id": "f4094748-a327-42af-8b3a-5eb64540d2a1" // Request ID
}
Transaction Query
If the interface returns a hash
field, merchants can visit the official Tron blockchain explorer (https://tronscan.org) to query detailed transaction information.
Signature Algorithm
To ensure interface security, the system will perform a sign
matching verification on all received data to prevent data from being tampered with illegally.
Signature Steps
- Assuming that all data sent or received forms a collection M, arrange the non-empty parameter values within the collection M in ascending order of ASCII codes of parameter names (lexicographical order). Concatenate them into a string
signstr
in the format of URL key-value pairs (i.e., key1=value1&key2=value2…). - Append
&appsecret=secret
to the end ofsignstr
to form a string. Perform an MD5 operation on the string, and then convert all characters in the resulting string to uppercase to obtain thesign
value.
- Assuming that all data sent or received forms a collection M, arrange the non-empty parameter values within the collection M in ascending order of ASCII codes of parameter names (lexicographical order). Concatenate them into a string
Signature Rules
- Arrange parameter names in ascending order of ASCII codes (lexicographical order).
- Exclude parameters with empty values from the signature.
- Parameter names are case-sensitive.
- When verifying the signature for a returned call or platform-initiated notification, the transmitted
sign
parameter is not included in the signature. Compare the generated signature with thesign
value.
Signature Example
For example, with the following signature parameters:
{
"appid": "12345678",
"order_id": "8883214567"
}
Format the parameters in key=value format and sort them in ASCII lexicographical order.
appid=12345678&order_id=8883214567
Concatenate the string from the previous step with &appsecret=secret.
appid=12345678&order_id=8883214567&appsecret=XXXXXXXXXXXXX
Take an MD5 hash of the string from the previous step and convert it to uppercase.
sign = hashlib.md5(signstr.encode()).hexdigest().upper()