upload project
This commit is contained in:
commit
06961cae04
422 changed files with 110626 additions and 0 deletions
32
utils/scana-signature.js
Normal file
32
utils/scana-signature.js
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
const CryptoJS = require('crypto-js');
|
||||
const config = require('../config/config.js');
|
||||
|
||||
/**
|
||||
* @param {Object} params URI请求参数
|
||||
* @returns {string} 32位MD5签名
|
||||
*/
|
||||
function generateScanaSignature(params) { // 提取参数名并按ASCII码表升序排序
|
||||
const sortedKeys = Object.keys(params).sort();
|
||||
|
||||
// 将排序好的参数名和参数值构造成字符串
|
||||
let paramStr = '';
|
||||
for (const key of sortedKeys) {
|
||||
// 确保参数值为字符串类型
|
||||
const value = String(params[key]);
|
||||
|
||||
paramStr += key + value;
|
||||
}
|
||||
|
||||
const finalStr = paramStr + config.scana.secretKey;
|
||||
|
||||
// 使用MD5算法
|
||||
const md5Hash = CryptoJS.MD5(finalStr);
|
||||
const signature = md5Hash.toString(CryptoJS.enc.Hex);
|
||||
|
||||
|
||||
return signature;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
generateScanaSignature
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue