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