diff --git a/function/h5st.ts b/function/h5st.ts index 3f0463d..091b2cc 100644 --- a/function/h5st.ts +++ b/function/h5st.ts @@ -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) @@ -70,4 +69,4 @@ class H5ST { export { H5ST -} \ No newline at end of file +}