微信支付 签名算法 sign node实现
开发微信支付过程中,第一道门槛就是微信支付接口签名
,只要按照官方文档写,就不会有什么错。
1、官方签名文档地址
https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=4_3
2、我的实现
// 获取微信签名
getSign: (params, key) => {
const paramsArr = Object.keys(params);
paramsArr.sort();
const stringArr = []
paramsArr.map(key => {
stringArr.push(key + '=' + params[key]);
})
// 最后加上 商户Key
stringArr.push("key=" + key)
const string = stringArr.join('&');
return md5(string).toString().toUpperCase();
}
3、微信支付接口签名校验工具
https://pay.weixin.qq.com/wiki/doc/api/tools/cash_coupon.php?chapter=20_1