open-withdrawal-demo/nodejs/sign.js
echo 82c7f3406d init: multi-language OpenAPI demos (java/php/nodejs/python)
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-20 13:40:29 +08:00

20 lines
577 B
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const crypto = require('crypto');
/** 空值不参与字典序MD5 小写 */
function buildSign(params, secretKey) {
const keys = Object.keys(params).filter((k) => k !== 'Sign').sort();
const parts = [];
for (const k of keys) {
const v = params[k];
if (v === null || v === undefined) continue;
const s = String(v);
if (s === '') continue;
parts.push(`${k}=${s}`);
}
const raw = parts.join('&') + `&SecretKey=${secretKey}`;
return crypto.createHash('md5').update(raw, 'utf8').digest('hex');
}
module.exports = { buildSign };