You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

38 lines
1.0 KiB

const crypto = require('crypto');
function sha256Hash(input) {
return crypto.createHash('sha256').update(input).digest('hex');
}
function get_signature(keyword, page) {
// 获取当前时间戳
const u = new Date().getTime();
// 生成随机字符串
function generateRandomString(e, t, r) {
let n = "";
let i = t;
const a = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
if (e) {
i = Math.round(Math.random() * (r - t)) + t;
}
for (let o = 0; o < i; o++) {
n += a[Math.round(Math.random() * (a.length - 1))];
}
return n;
}
const l = generateRandomString(false, 16);
// 将输入参数排序并连接成字符串
const inputStr = [u, l, '$d6eb7ff91ee257475%', keyword, 10, page].sort().join("");
// 使用 SHA-256 算法生成签名
const signature = sha256Hash(inputStr);
return {
'ts': u,
'rs': l,
'signature': signature
};
}