Asynchronous Notification Signature Generation Process
Asynchronous Notification Parameters Example
Field | Type | Description | Details |
---|---|---|---|
order_id | String | Order ID | The order ID assigned by YiSiHui. |
pay_result | Int | Payment Result | 1 for success, 0 for failure. |
pay_amount | Float | Payment Amount | A floating-point value, e.g., 10000.00 . |
pay_datetime | String | Payment Time | A string, e.g., 2017-10-12 10:00:00 . |
extend_info | String | Extended Info | Reserved for future use. |
sign | String | Signature | Generated using MD5. See the detailed process below. |
Signature Generation Process for Asynchronous Notifications
1.
Exclude the
sign
field from the parameters. Sort the remaining parameters alphabetically by their key names. If the first letters are the same, compare the second letters, and so on.2.
Concatenate the sorted parameters into a single string. Use the
&
symbol to separate each key-value pair in the format key=value
.3.
Add a specified salt value to the beginning of the concatenated string.
4.
Apply the MD5 algorithm to compute the hash of the resulting string from the previous step.
5.
Use the computed MD5 hash as the value for the
sign
field in the notification.Example for Signature Generation
{
"order_id": "ETxxxxxxxxxxxx01",
"pay_result": 1,
"pay_amount": 10000.00,
"pay_datetime": "2024-12-01 10:00:00",
"extend_info": ""
}
1.
extend_info=&order_id=ETxxxxxxxxxxxx01&pay_amount=10000.00&pay_datetime=2024-12-01 10:00:00&pay_result=1
2.
abc123
) (optional):abc123extend_info=&order_id=ETxxxxxxxxxxxx01&pay_amount=10000.00&pay_datetime=2024-12-01 10:00:00&pay_result=1
3.
Generate the MD5 hash of the string:
MD5("abc123extend_info=&order_id=ETxxxxxxxxxxxx01&pay_amount=10000.00&pay_datetime=2024-12-01 10:00:00&pay_result=1")
4.
The resulting MD5 hash becomes the value of the
sign
field.{
"order_id": "ETxxxxxxxxxxxx01",
"pay_result": 1,
"pay_amount": 10000.00,
"pay_datetime": "2024-12-01 10:00:00",
"extend_info": "",
"sign": "652614570bcc49940d7dcc7a3c3dc7e5"
}
Example: Signature Generation
# Python3
import hashlib
def generate_sign(sign_params: dict, salt=None) -> str:
if not salt:
salt = ""
md5_text = str(salt) + "&".join(
[f"{k}={v}" for k, v in sorted(sign_params.items())]
)
return hashlib.md5(bytes(md5_text, encoding="utf-8")).hexdigest()