Signature Algorithm (sign)
- Extract the parameters from the POST request and exclude any parameter with an empty value to reduce unnecessary processing.
- Sort the remaining non-empty parameters alphabetically by their keys following the ASCII dictionary order.
- Concatenate the sorted key-value pairs into a single string in the format: key1=value1&key2=value2... This string is referred to as StringA.
- Append the crm-pay-token to StringA to form StringB, which will be used for encryption.
- Perform a SHA1 hash on StringB. Convert the resulting hash value into a hexadecimal string.
- Convert the hexadecimal string to uppercase to get the final signature value.
Sample code to obtain the signature
js
let query = Object.keys(data)
.sort()
.reduce((result, key) => result + key + '=' + data[key] + '&', "")
.slice(0, -1);
let sign = crypto.createHash('sha1').update(query + crm_pay_token).digest('hex').toUpperCase();
python
query = '&'.join([f"{key}={data[key]}" for key in sorted(data)])
sign = hashlib.sha1((query + crm_pay_token).encode('utf-8')).hexdigest().upper()