1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465 |
- import sysconfig from '../sysconfig/sysconfig.js'
- import crypt from './crypt.js'
- let Fly = require("flyio")
- let fly = new Fly()
- fly.config.baseURL = sysconfig.baseURL
- fly.interceptors.request.use((config) => {
-
- const aesKey = sysconfig.copyright + sysconfig.app.snCode
-
- const token = wx.getStorageSync(sysconfig.user.tokenKey)
- if (token) {
-
- let apiName = ""
- const urlList = config.url.split("/")
- const apiWhiteList = sysconfig.apiWhiteList
- if (urlList.length > 1) {
- apiName = urlList[1]
- } else {
- apiName = urlList[0]
- }
-
- if (!apiWhiteList.includes(apiName)) {
- let item = {}
- item["rnd"] = Math.random().toString()
- item["token"] = token
- let plaintext = JSON.stringify(item)
-
- const ciphertext = crypt.aesEncode(plaintext, aesKey)
- config.headers.Authorization = ciphertext
- }
- }
-
- if (config.params && (Object.keys(config.params).length) > 0) {
- const params = config.params
- const paramsText = JSON.stringify(params)
- if (paramsText != "{}") {
- const ciphertext = crypt.aesEncode(params, aesKey)
- config.params = {}
- config.params = ciphertext
- }
- }
-
- if (config.body && (Object.keys(config.body).length) > 0) {
- const plaintext = JSON.stringify(config.body)
- const ciphertext = crypt.aesEncode(plaintext, aesKey)
- config.body = {}
- config.body = ciphertext
- }
- return config
- }, error => {
- return Promise.reject(error)
- })
- export default fly
|