scorpio 2 年 前
コミット
e8b01c7ad3
5 ファイル変更104 行追加2 行削除
  1. 1 0
      package.json
  2. 12 0
      src/api/fetch.js
  3. 84 0
      src/utils/crypto.js
  4. 2 2
      vite.config.js
  5. 5 0
      yarn.lock

+ 1 - 0
package.json

@@ -12,6 +12,7 @@
     "@amap/amap-jsapi-loader": "^1.0.1",
     "@element-plus/icons-vue": "^2.0.6",
     "@smallwei/avue": "^3.2.5",
+    "crypto-js": "^4.1.1",
     "dateformat": "^5.0.3",
     "echarts": "^5.4.1",
     "element-plus": "^2.2.9",

+ 12 - 0
src/api/fetch.js

@@ -5,6 +5,8 @@ import axios from './axios.js'
 import router from '../router'
 import { getToken, removeToken } from '../utils/auth'
 import { ElMessage } from 'element-plus'
+import crypto from '@/utils/crypto'
+import website from '@/config/website.js'
 
 axios.defaults.baseURL = ''
 
@@ -28,6 +30,11 @@ axios.interceptors.request.use(
 )
 
 // insurance 保险 502 503 504时兜底的
+const desUrl =
+  website.baseUrl.indexOf('https://prod') > -1
+    ? ['blade-pc-applet']
+    : ['blade-pc-applet']
+console.log(website.baseUrl)
 function fetch(
   url = '',
   params = {},
@@ -69,6 +76,11 @@ function fetch(
       }
     }
     const success = response => {
+      // const tmps = desUrl.filter(e => url.indexOf(e) > -1)
+      // if (tmps.length > 0) {
+      //   response = JSON.parse(crypto.decryptDES(response, crypto.desKey))
+      //   console.log(response)
+      // }
       const { status, data = {}, statusText } = response
       if (status >= 200 && status <= 401) {
         if (data.code === 401 || data.code === 400) {

+ 84 - 0
src/utils/crypto.js

@@ -0,0 +1,84 @@
+import CryptoJS from 'crypto-js'
+
+export default class crypto {
+  // 使用AesUtil.genAesKey()生成,需和后端配置保持一致
+  static aesKey = 'uQFw4pOEtPdzU4LP3ywbaUtoGMHywnUi'
+
+  // 使用DesUtil.genDesKey()生成,需和后端配置保持一致
+  static desKey = 'XHHUNdnCka60Y5zJ'
+
+  /**
+   * aes 加密方法
+   * @param data
+   * @returns {*}
+   */
+  static encrypt(data) {
+    return this.encryptAES(data, this.aesKey)
+  }
+
+  /**
+   * aes 解密方法
+   * @param data
+   * @returns {*}
+   */
+  static decrypt(data) {
+    return this.decryptAES(data, this.aesKey)
+  }
+
+  /**
+   * aes 加密方法,同java:AesUtil.encryptToBase64(text, aesKey);
+   */
+  static encryptAES(data, key) {
+    const dataBytes = CryptoJS.enc.Utf8.parse(data)
+    const keyBytes = CryptoJS.enc.Utf8.parse(key)
+    const encrypted = CryptoJS.AES.encrypt(dataBytes, keyBytes, {
+      iv: keyBytes,
+      mode: CryptoJS.mode.CBC,
+      padding: CryptoJS.pad.Pkcs7
+    })
+    return CryptoJS.enc.Base64.stringify(encrypted.ciphertext)
+  }
+
+  /**
+   * aes 解密方法,同java:AesUtil.decryptFormBase64ToString(encrypt, aesKey);
+   */
+  static decryptAES(data, key) {
+    const keyBytes = CryptoJS.enc.Utf8.parse(key)
+    const decrypted = CryptoJS.AES.decrypt(data, keyBytes, {
+      iv: keyBytes,
+      mode: CryptoJS.mode.CBC,
+      padding: CryptoJS.pad.Pkcs7
+    })
+    return CryptoJS.enc.Utf8.stringify(decrypted)
+  }
+
+  /**
+   * des 加密方法,同java:DesUtil.encryptToBase64(text, desKey)
+   */
+  static encryptDES(data, key) {
+    const keyHex = CryptoJS.enc.Utf8.parse(key)
+    const encrypted = CryptoJS.DES.encrypt(data, keyHex, {
+      mode: CryptoJS.mode.ECB,
+      padding: CryptoJS.pad.Pkcs7
+    })
+    return encrypted.toString()
+  }
+
+  /**
+   * des 解密方法,同java:DesUtil.decryptFormBase64(encryptBase64, desKey);
+   */
+  static decryptDES(data, key) {
+    const keyHex = CryptoJS.enc.Utf8.parse(key)
+    const decrypted = CryptoJS.DES.decrypt(
+      {
+        ciphertext: CryptoJS.enc.Base64.parse(data)
+      },
+      keyHex,
+      {
+        mode: CryptoJS.mode.ECB,
+        padding: CryptoJS.pad.Pkcs7
+      }
+    )
+    return decrypted.toString(CryptoJS.enc.Utf8)
+  }
+}

+ 2 - 2
vite.config.js

@@ -57,8 +57,8 @@ export default defineConfig({
     proxy: {
       '/api': {
         // 正式环境地址
-        target: 'https://dev.wutongresearch.club/api',
-        // target: 'https://prod.wutongshucloud.com/api',
+        // target: 'https://dev.wutongresearch.club/api',
+        target: 'https://prod.wutongshucloud.com/api',
         // target: 'http://192.168.31.181:8110',
         changeOrigin: true,
         rewrite: path => path.replace(/^\/api/, '')

+ 5 - 0
yarn.lock

@@ -1049,6 +1049,11 @@ cross-spawn@^7.0.0, cross-spawn@^7.0.2:
     shebang-command "^2.0.0"
     which "^2.0.1"
 
+crypto-js@^4.1.1:
+  version "4.1.1"
+  resolved "https://registry.yarnpkg.com/crypto-js/-/crypto-js-4.1.1.tgz#9e485bcf03521041bd85844786b83fb7619736cf"
+  integrity sha512-o2JlM7ydqd3Qk9CA0L4NL6mTzU2sdx96a+oOfPu8Mkl/PK51vSyoi8/rQ8NknZtk44vq15lmhAj9CIAGwgeWKw==
+
 cssesc@^3.0.0:
   version "3.0.0"
   resolved "https://registry.yarnpkg.com/cssesc/-/cssesc-3.0.0.tgz#37741919903b868565e1c09ea747445cd18983ee"