|
|
@@ -1,11 +1,29 @@
|
|
|
import axios from 'axios';
|
|
|
import router from '../router';
|
|
|
import qs from 'qs';
|
|
|
+import CryptoJS from 'crypto-js';
|
|
|
+
|
|
|
let baseUrl = process.env.VUE_APP_BASE_URL; //如要修改本地开发地址,新建.env.development.local文件
|
|
|
const axiosInstance = axios.create({
|
|
|
baseURL: baseUrl,
|
|
|
});
|
|
|
|
|
|
+function decrypt(content) {
|
|
|
+ const key = CryptoJS.enc.Hex.parse('2181E9E80460B852859EE455AC5203D9');
|
|
|
+ const cipherText = CryptoJS.enc.Hex.parse(content);
|
|
|
+ var decrypted = CryptoJS.AES.decrypt(
|
|
|
+ {
|
|
|
+ ciphertext: cipherText,
|
|
|
+ },
|
|
|
+ key,
|
|
|
+ {
|
|
|
+ mode: CryptoJS.mode.ECB,
|
|
|
+ padding: CryptoJS.pad.Pkcs7,
|
|
|
+ }
|
|
|
+ );
|
|
|
+ return decrypted.toString(CryptoJS.enc.Utf8);
|
|
|
+}
|
|
|
+
|
|
|
axiosInstance.interceptors.request.use(
|
|
|
function (config) {
|
|
|
config.headers = config.headers || {};
|
|
|
@@ -22,6 +40,14 @@ axiosInstance.interceptors.request.use(
|
|
|
|
|
|
axiosInstance.interceptors.response.use(
|
|
|
function (response) {
|
|
|
+ if (response.headers['content-encrypted'] === 'true') {
|
|
|
+ let decrypted = decrypt(response.data);
|
|
|
+ if (response.headers['content-type'].includes('application/json')) {
|
|
|
+ response.data = JSON.parse(decrypted);
|
|
|
+ } else {
|
|
|
+ response.data = decrypted;
|
|
|
+ }
|
|
|
+ }
|
|
|
return response;
|
|
|
},
|
|
|
function (error) {
|