diff --git a/src/utils/http.ts b/src/utils/http.ts index 768326a..49fabfd 100644 --- a/src/utils/http.ts +++ b/src/utils/http.ts @@ -1,6 +1,7 @@ import axios, { AxiosRequestConfig, AxiosResponse, AxiosInstance } from 'axios'; import { formatMessage } from 'umi-plugin-locale'; import _ from 'lodash'; +import md5 from 'md5'; import { globalState } from '@/services/common'; import { isDev, dispatch } from './utils'; import config from '@/config'; @@ -44,6 +45,7 @@ function replaceId(obj: any) { async function filter( method: keyof AxiosInstance, + url: string, ...args: any[] ): Promise> { let ret; @@ -57,8 +59,12 @@ async function filter( } else { instance.defaults.headers = _.omit(instance.defaults.headers, 'token'); } + const matches = url.match(/(?:[/\da-zA-Z]+)/) || ['']; + const timestamp = Date.now(); + instance.defaults.headers.ts = `${timestamp}`; + instance.defaults.headers.sig = md5(`${timestamp}${matches[0]}LimitSaltLOL8080`); const { status, data, headers } = - await (instance[method] as (...args: any[]) => Promise>)(...args); + await (instance[method] as (...args: any[]) => Promise>)(url, ...args); replaceId(data); if (headers && headers.token) { dispatch({ type: 'user/updateToken', payload: headers.token });