mirror of
http://112.124.100.131/GFRS/ebiz-h5.git
synced 2025-12-09 06:26:44 +08:00
随机密钥加密解密需求,区分v3随机密钥加密,v2固定密钥加密
This commit is contained in:
@@ -155,14 +155,16 @@ service.interceptors.request.use(
|
||||
message: '加载中……'
|
||||
})
|
||||
}
|
||||
// 生成本次请求随机密钥
|
||||
let masterKey
|
||||
if(configApp.API_VERSION == 'v3'){
|
||||
// 生成本次请求随机密钥
|
||||
if (!window.localStorage.getItem('masterKey')) {
|
||||
masterKey = randomString();
|
||||
window.localStorage.setItem('masterKey',masterKey)
|
||||
} else {
|
||||
masterKey = window.localStorage.getItem('masterKey')
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 请求拦截处理(待添加 判断走统一网关处理)
|
||||
*/
|
||||
@@ -172,7 +174,7 @@ service.interceptors.request.use(
|
||||
config.data = {}
|
||||
}
|
||||
if (!!config.data && config.data != null) {
|
||||
// let encrypt = AESTools.AESEncrypt(JSON.stringify(config.data), configApp.REQ_PWD)
|
||||
if(configApp.API_VERSION == 'v3'){
|
||||
console.log('随机密钥:' + masterKey);
|
||||
// RSA加密随机密钥
|
||||
let ak = RSAEncrypt(masterKey, publicKey);
|
||||
@@ -190,7 +192,10 @@ service.interceptors.request.use(
|
||||
}else{
|
||||
console.log(AESDecrypt(config.data.data, masterKey));
|
||||
}
|
||||
// config.data = { data: encrypt }
|
||||
}else if(configApp.API_VERSION == 'v2'){
|
||||
let encrypt = AESEncrypt(JSON.stringify(config.data), configApp.REQ_PWD)
|
||||
config.data = { data: encrypt }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -241,6 +246,7 @@ service.interceptors.response.use(
|
||||
/api\/$/.test(response.config.url.split(configApp.API_VERSION)[0])
|
||||
) {
|
||||
if (res.response) {
|
||||
if(configApp.API_VERSION == 'v3'){
|
||||
// 正常情況返回必有response 节点
|
||||
// 返回结果的随机密钥
|
||||
let masterKey;
|
||||
@@ -254,7 +260,10 @@ service.interceptors.response.use(
|
||||
console.log(JSON.parse(AESDecrypt(response.data.response, masterKey)))
|
||||
// 使用随机密钥解密返回结果data
|
||||
res = JSON.parse(AESDecrypt(res.response, masterKey))
|
||||
// res = JSON.parse(AESTools.AESDecrypt(res.response, configApp.REQ_PWD))
|
||||
}else if(configApp.API_VERSION == 'v2'){
|
||||
// 使用固定密钥解密返回结果data
|
||||
res = JSON.parse(AESDecrypt(res.response, configApp.REQ_PWD))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user