123456789101112131415161718192021222324252627282930313233 |
- import { generateUUID } from "@/utils/index"
- import { sha256 } from 'js-sha256'
- import { decodeURIComponentSafe } from '@/utils/index'
- /**
- * @param { str } raw 参数用&隔开
- * @param { Object } body
- * @returns
- */
- export const encryptionFun = ({raw, body, appId, AppSecret, timestamp}) => {
- const initSign = {
- appId,
- nonce: generateUUID(),
- timestamp,
- }
- const _initSignArr = Object.keys(initSign).map(key => {
- return `${key}=${initSign[key]}`
- })
- const _initSign = _initSignArr.join('&')
- const paramsStr = _initSign + AppSecret
- let str = ''
- if (raw) {
- str += decodeURIComponentSafe(raw)
- }
- if (body && Object.keys(body).length) {
- str += decodeURIComponentSafe(JSON.stringify(body))
- }
- return {
- ...initSign,
- sign: sha256(str + paramsStr)
- }
- }
|