Sign
Refer to the demo on GitHub.
Extract all keys and sort them
Stitching key-value pair string
Use Md5 encryption
const crypto = require('crypto');
function sign(data, secret) {
// Extract all keys and sort them
const keys = Object.keys(data).sort();
// Stitching key-value pair string
const keyValueStrings = keys
.filter(key => key !== 'sign') // Exclude the sign key
.map(key => `${key}=${data[key]}`);
const result = keyValueStrings.join('&') + '&' + secret;
// Use md5 encryption
const hash = crypto.createHash('md5');
hash.update(result);
return hash.digest('hex');
}
// test
let tmp = Date.now()
const data = {
"file_base64": "Your base64 string contains data:image/png;base64",
"timestamp": "xxx",
"merchant_no": xxx,
"mode": "nude",
"notify_url": "string"
};
const secret = 'Your secret';
console.log(tmp,sign(data, secret));
Last updated