加密
This commit is contained in:
parent
67cf65dbb3
commit
6b22261fb0
@ -58,7 +58,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
|
||||
// if (adminBaseRoute.path != '/admin' && isAdminApp() && /^\/admin\//.test(axiosConfig.url!)) {
|
||||
// axiosConfig.url = axiosConfig.url!.replace(/^\/admin\//, adminBaseRoute.path + '.php/')
|
||||
// }
|
||||
alert(axiosConfig.data)
|
||||
// alert(axiosConfig.data)
|
||||
|
||||
// 合并默认请求选项
|
||||
options = Object.assign(
|
||||
@ -77,6 +77,7 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
|
||||
// 请求拦截
|
||||
Axios.interceptors.request.use(
|
||||
(config) => {
|
||||
const v = generateRandomNumber(16)
|
||||
removePending(config)
|
||||
options.CancelDuplicateRequest && addPending(config)
|
||||
// 创建loading实例
|
||||
@ -87,15 +88,19 @@ function createAxios<Data = any, T = ApiPromise<Data>>(axiosConfig: AxiosRequest
|
||||
}
|
||||
}
|
||||
|
||||
if (config.method === 'post' && config.data) {
|
||||
// 对data进行加密
|
||||
config.data = encrypt_aes(config.data, v)
|
||||
} else if (config.method === 'get' && config.params) {
|
||||
// 对params进行加密
|
||||
config.params = encrypt_aes(config.params, v)
|
||||
}
|
||||
|
||||
// 自动携带token
|
||||
if (config.headers) {
|
||||
const v = generateRandomNumber(16)
|
||||
config.headers.v = v
|
||||
const token = adminInfo.getToken()
|
||||
if (token) (config.headers as anyObj).token = encrypt_aes(token, v)
|
||||
|
||||
// const userToken = options.anotherToken || userInfo.getToken()
|
||||
// if (userToken) (config.headers as anyObj)['token'] = userToken
|
||||
}
|
||||
|
||||
return config
|
||||
|
@ -11,11 +11,11 @@ export function encrypt_aes(plaintText: string, iv: string) {
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
})
|
||||
|
||||
const encryptedBase64Str = encryptedData.toString()
|
||||
// const encryptedBase64Str = encryptedData.toString()
|
||||
|
||||
// 需要读取encryptedData上的ciphertext.toString()才能拿到跟Java一样的密文
|
||||
// // 需要读取encryptedData上的ciphertext.toString()才能拿到跟Java一样的密文
|
||||
|
||||
const encryptedStr = encryptedData.ciphertext.toString()
|
||||
// const encryptedStr = encryptedData.ciphertext.toString()
|
||||
|
||||
return encryptedData.toString(CryptoJS.format.Base64)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user