123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869 |
- import sysconfig from '../sysconfig/sysconfig.js'
- import crypt from './crypt.js'
- let Fly = require("flyio/dist/npm/wx")
- let fly = new Fly()
- fly.config.baseURL = "http://127.0.0.1:8080/msapi"
- fly.config.baseURL = "http://www.locaty.com.cn/msapi"
- 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
|