Update h5st.ts

This commit is contained in:
Faker 2022-06-27 18:07:27 +08:00
parent c43dd16692
commit c5c18cf7ff

View File

@ -1,7 +1,6 @@
import axios from "axios"
import {format} from "date-fns"
const CryptoJS = require("crypto-js")
import * as CryptoJS from 'crypto-js'
class H5ST {
tk: string;
@ -51,7 +50,7 @@ class H5ST {
this.enc = data.data.result.algo.match(/algo\.(.*)\(/)[1]
}
__genKey(tk, fp, ts, ai, algo) {
__genKey(tk: string, fp: string, ts: string, ai: string, algo: object) {
let str = `${tk}${fp}${ts}${ai}${this.rd}`;
return algo[this.enc](str, tk)
}
@ -59,8 +58,8 @@ class H5ST {
__genH5st(body: object) {
let y = this.__genKey(this.tk, this.fp, this.timestamp, this.appId, CryptoJS).toString(CryptoJS.enc.Hex)
let s = ''
for (let i in body) {
i === 'body' ? s += `${i}:${CryptoJS.SHA256(body[i]).toString(CryptoJS.enc.Hex)}&` : s += `${i}:${body[i]}&`
for (let key of Object.keys(body)) {
key === 'body' ? s += `${key}:${CryptoJS.SHA256(body[key]).toString(CryptoJS.enc.Hex)}&` : s += `${key}:${body[key]}&`
}
s = s.slice(0, -1)
s = CryptoJS.HmacSHA256(s, y).toString(CryptoJS.enc.Hex)