hmp пре 4 година
родитељ
комит
dbe7721319
2 измењених фајлова са 39 додато и 9 уклоњено
  1. 18 9
      src/router/axios.js
  2. 21 0
      src/util/crypto.js

+ 18 - 9
src/router/axios.js

@@ -8,11 +8,19 @@
 import axios from 'axios';
 import store from '@/store/';
 import router from '@/router/router';
-import {serialize} from '@/util/util';
-import {getToken} from '@/util/auth';
-import {Message} from 'element-ui';
+import {
+  serialize
+} from '@/util/util';
+import {
+  getToken
+} from '@/util/auth';
+import {
+  Message
+} from 'element-ui';
 import website from '@/config/website';
-import {Base64} from 'js-base64';
+import {
+  Base64
+} from 'js-base64';
 import NProgress from 'nprogress';
 import 'nprogress/nprogress.css';
 import crypto from '@/util/crypto.js';
@@ -21,7 +29,7 @@ import crypto from '@/util/crypto.js';
 //默认超时时间
 axios.defaults.timeout = 10000;
 //返回其他状态码
-axios.defaults.validateStatus = function (status) {
+axios.defaults.validateStatus = function(status) {
   return status >= 200 && status <= 500;
 };
 //跨域请求,允许保存cookie
@@ -51,10 +59,9 @@ axios.interceptors.request.use(config => {
     config.data = serialize(config.data);
   }
   //报文加密
-  console.log(config.method === 'post',"/*************");
-  if (config.method === 'post' && config.data) {
+  if (config.method === 'post' && config.data && crypto.isNotInWhiteList(config.url)) {
     let encrypt = crypto.encrypt(JSON.stringify(config.data))
-    config.data=encrypt
+    config.data = encrypt
   }
 
 
@@ -73,7 +80,9 @@ axios.interceptors.response.use(res => {
   //如果在白名单里则自行catch逻辑处理
   if (statusWhiteList.includes(status)) return Promise.reject(res);
   //如果是401则跳转到登录页面
-  if (status === 401) store.dispatch('FedLogOut').then(() => router.push({path: '/login'}));
+  if (status === 401) store.dispatch('FedLogOut').then(() => router.push({
+    path: '/login'
+  }));
   // 如果请求为非200否者默认统一处理
   if (status !== 200) {
     Message({

+ 21 - 0
src/util/crypto.js

@@ -3,6 +3,27 @@ console.log(CryptoJS.HmacSHA1("Message", "Key"));
 
 let crypto = {}
 
+const WHITE_LIST = [
+  '/yeepay',
+  '/put-file',
+  '/blade-test',
+  '/payment',
+  '/sms',
+  '/mall/yeepay/product/fee/modifyProductFeeNotify',
+  '/shop/yeepay/product/fee/modifyProductFeeNotify',
+  '/withdraw',
+  '/pressure_test/scanPay',
+  '/pressure_test/deCodeNotifyData',
+  '/ocr',
+  '/import-bank-type'
+]
+
+crypto.isNotInWhiteList=(url)=>{
+    return !WHITE_LIST.some(item=>{
+        return url.indexOf(item)>0
+    })
+}
+
 //前后端定义的密钥,AES使用16位
 const CRYPTOJS_KEY = "uAY9ugkHQpvozZeA";
 // 加密