This commit is contained in:
Teo
2025-09-04 11:06:45 +08:00
parent 9d1f96309f
commit 910b24019e
83 changed files with 8390 additions and 834 deletions

50
src/utils/sign.js Normal file
View File

@ -0,0 +1,50 @@
import crypto from 'crypto-js';
let coyr = 'coyrOrtiehanhan1223202409111457';
// 生成 nonce随机生成一个16位的字符串
function generateNonce() {
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
let nonce = '';
for (let i = 0; i < 16; i++) {
nonce += chars.charAt(Math.floor(Math.random() * chars.length));
}
return nonce;
}
// 生成当前时间戳(格式为 yyyyMMddHHmmss
function generateTimestamp() {
return new Date().getTime();
}
// 生成 MD5 哈希(需要引入第三方库,如 crypto-js
function md5Hash(str) {
return crypto.MD5(str).toString();
}
// 生成 SHA-256 哈希(需要引入第三方库,如 crypto-js
function sha256Hash(str) {
return crypto.SHA256(str).toString();
}
// 生成签名
function generateSignature(params, timestamp, nonce) {
// 加密
let coyr1 = md5Hash(coyr);
// 拼接时间戳、nonce 和 secretKey
let signStr = coyr1 + timestamp + nonce;
// MD5 加密
const md5Str = md5Hash(signStr);
// SHA-256 加密
let aaaa = sha256Hash(md5Str);
return aaaa;
}
function sign(data) {
// 生成签名
const timestamp = generateTimestamp();
const nonce = generateNonce();
const sign = generateSignature(data, timestamp, nonce);
return {
timestamp,
nonce,
sign,
};
}
// 封装
export default sign;