国富金掌柜隐私政策无法读取问题处理

This commit is contained in:
jiawei
2023-03-29 11:29:14 +08:00
parent 2a41b41761
commit f580606085

View File

@@ -158,11 +158,11 @@ service.interceptors.request.use(
}) })
} }
let masterKey let masterKey
if(configApp.API_VERSION == 'v3'){ if (configApp.API_VERSION == 'v3') {
// 生成本次请求随机密钥 // 生成本次请求随机密钥
if (!window.localStorage.getItem('masterKey')) { if (!window.localStorage.getItem('masterKey')) {
masterKey = randomString(); masterKey = randomString();
window.localStorage.setItem('masterKey',masterKey) window.localStorage.setItem('masterKey', masterKey)
} else { } else {
masterKey = window.localStorage.getItem('masterKey') masterKey = window.localStorage.getItem('masterKey')
} }
@@ -177,30 +177,30 @@ service.interceptors.request.use(
if (!config.data || config.data == null) { if (!config.data || config.data == null) {
config.data = {} config.data = {}
} }
if (!!config.data && config.data != null) { if (!!config.data && config.data != null) {
if(configApp.API_VERSION == 'v3'){ if (configApp.API_VERSION == 'v3') {
// console.log('随机密钥:' + masterKey); // console.log('随机密钥:' + masterKey);
// RSA加密随机密钥 // RSA加密随机密钥
let ak = RSAEncrypt(masterKey, publicKey); let ak = RSAEncrypt(masterKey, publicKey);
// console.log('加密后的masterKey' + ak); // console.log('加密后的masterKey' + ak);
// 随机密钥加密data // 随机密钥加密data
let data = AESEncrypt(JSON.stringify(config.data), masterKey); let data = AESEncrypt(JSON.stringify(config.data), masterKey);
// console.log('MD5值' + MD5(AESEncrypt(data, masterKey)).toString()); // 验证数据完整性SHA256
// 验证数据完整性MD5 // 数据完整性SHA256需要进行二次AES加密
// 数据完整性MD5需要进行二次AES加密
config.headers['signature'] = SHA256(AESEncrypt(data, masterKey)).toString(); config.headers['signature'] = SHA256(AESEncrypt(data, masterKey)).toString();
if(config.method == 'get'){ if (config.method == 'get') {
config.headers['ak'] = ak config.headers['ak'] = ak
config.headers['data'] = data config.headers['data'] = data
} }
config.data = { ak, data }; config.data = { ak, data };
// console.log(config.data); // console.log(config.data);
if(AESDecrypt(config.data.data, masterKey)){ if (AESDecrypt(config.data.data, masterKey)) {
// console.log(JSON.parse(AESDecrypt(config.data.data, masterKey))); // console.log(JSON.parse(AESDecrypt(config.data.data, masterKey)));
}else{ } else {
// console.log(AESDecrypt(config.data.data, masterKey)); // console.log(AESDecrypt(config.data.data, masterKey));
} }
}else if(configApp.API_VERSION == 'v2'){ } else if (configApp.API_VERSION == 'v2') {
config.headers['signature'] = MD5(timeStr + CacheUtils.getLocItem('token')) config.headers['signature'] = MD5(timeStr + CacheUtils.getLocItem('token'))
let encrypt = AESEncryptV2(JSON.stringify(config.data), configApp.REQ_PWD) let encrypt = AESEncryptV2(JSON.stringify(config.data), configApp.REQ_PWD)
config.data = { data: encrypt } config.data = { data: encrypt }
@@ -217,18 +217,21 @@ service.interceptors.request.use(
// eslint-disable-next-line no-undef // eslint-disable-next-line no-undef
let u = navigator.userAgent; let u = navigator.userAgent;
let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //判断是否是 android终端 let isAndroid = u.indexOf('Android') > -1 || u.indexOf('Adr') > -1; //判断是否是 android终端
if(isAndroid){ if (isAndroid) {
// setTimeout(() => { // setTimeout(() => {
console.log(window.Android.getToken(),'Android获取token') if (window.location.hash !== '#/my/privacyPolicy') {
console.log(window.Android.getToken(), 'Android获取token')
CacheUtils.setLocItem('token', window.Android.getToken()) CacheUtils.setLocItem('token', window.Android.getToken())
}
// }, 1000) // }, 1000)
}else{ } else {
if (window.location.hash !== '#/my/privacyPolicy') {
const res = await EWebBridge.webCallAppInJs('getToken') const res = await EWebBridge.webCallAppInJs('getToken')
CacheUtils.setLocItem('token', JSON.parse(res).token) CacheUtils.setLocItem('token', JSON.parse(res).token)
} }
} }
} }
}
config.headers['token'] = CacheUtils.getLocItem('token') config.headers['token'] = CacheUtils.getLocItem('token')
// 添加请时间戳 // 添加请时间戳
let timeStr = new Date().getTime() + '' let timeStr = new Date().getTime() + ''
@@ -252,7 +255,7 @@ service.interceptors.response.use(
/api\/$/.test(response.config.url.split(configApp.API_VERSION)[0]) /api\/$/.test(response.config.url.split(configApp.API_VERSION)[0])
) { ) {
if (res.response) { if (res.response) {
if(configApp.API_VERSION == 'v3'){ if (configApp.API_VERSION == 'v3') {
// 正常情況返回必有response 节点 // 正常情況返回必有response 节点
// 返回结果的随机密钥 // 返回结果的随机密钥
let masterKey; let masterKey;
@@ -266,7 +269,7 @@ service.interceptors.response.use(
// console.log(JSON.parse(AESDecrypt(response.data.response, masterKey))) // console.log(JSON.parse(AESDecrypt(response.data.response, masterKey)))
// 使用随机密钥解密返回结果data // 使用随机密钥解密返回结果data
res = JSON.parse(AESDecrypt(res.response, masterKey)) res = JSON.parse(AESDecrypt(res.response, masterKey))
}else if(configApp.API_VERSION == 'v2'){ } else if (configApp.API_VERSION == 'v2') {
// 使用固定密钥解密返回结果data // 使用固定密钥解密返回结果data
res = JSON.parse(AESDecryptV2(res.response, configApp.REQ_PWD)) res = JSON.parse(AESDecryptV2(res.response, configApp.REQ_PWD))
// console.log(res,'JSON.parse(AESDecrypt(res.response, configApp.REQ_PWD))') // console.log(res,'JSON.parse(AESDecrypt(res.response, configApp.REQ_PWD))')
@@ -280,7 +283,7 @@ service.interceptors.response.use(
if (res.code == 10001 || res.code == 10002) { if (res.code == 10001 || res.code == 10002) {
var ua = window.navigator.userAgent.toLowerCase(); var ua = window.navigator.userAgent.toLowerCase();
//通过正则表达式匹配ua中是否含有MicroMessenger字符串, 在微信 //通过正则表达式匹配ua中是否含有MicroMessenger字符串, 在微信
if(ua.match(/MicroMessenger/i) == 'micromessenger'){ if (ua.match(/MicroMessenger/i) == 'micromessenger') {
Dialog.alert({ Dialog.alert({
title: '提示', title: '提示',
confirmButtonText: '退出', confirmButtonText: '退出',