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 }; }