This commit is contained in:
parent
a21a7cd967
commit
5921d123cf
|
|
@ -3,7 +3,7 @@ const platform = uni.getSystemInfoSync().platform
|
|||
// let BASE_URL = 'http://192.168.2.188:21907/gz_att_wechat' // 本地
|
||||
// let BASE_URL = 'http://192.168.0.14:21907/gz_att_wechat' // 测试服务地址
|
||||
// let BASE_URL = 'https://jj.jypxks.com/gz_att_wechat' // 生产服务地址
|
||||
let BASE_URL = 'http://192.168.0.50:1907' // 孙亮
|
||||
let BASE_URL = 'http://192.168.0.50:1907/gz_att_wechat' // 孙亮
|
||||
|
||||
// 如果是浏览器调试会产生跨域 则配置请求基地址为 api 或其他 必须与vue.config.js 中配置的代理一致 解决跨域问题
|
||||
// if (ENV === 'development' && (platform === 'h5' || platform === 'windows')) {
|
||||
|
|
|
|||
|
|
@ -1,24 +1,23 @@
|
|||
import BASE_URL from './env'
|
||||
const CryptoJS = require("@/utils/crypto-js");
|
||||
import { aqEnnable } from "@/api/index.js"
|
||||
const CryptoJS = require('@/utils/crypto-js')
|
||||
import { aqEnnable } from '@/api/index.js'
|
||||
|
||||
var cbc_key = CryptoJS.enc.Utf8.parse("zhst@bonus@zhst@bonus@1234567890");
|
||||
var cbc_key = CryptoJS.enc.Utf8.parse('zhst@bonus@zhst@bonus@1234567890')
|
||||
// var cbc_key = CryptoJS.enc.Utf8.parse("zhst@bonus@zhst@");
|
||||
var cbc_iv = CryptoJS.enc.Utf8.parse("1234567812345678");
|
||||
|
||||
var cbc_iv = CryptoJS.enc.Utf8.parse('1234567812345678')
|
||||
|
||||
// 加密
|
||||
export function encryptCBC(word) {
|
||||
if(!aqEnnable) {
|
||||
if (!aqEnnable) {
|
||||
return word
|
||||
}
|
||||
var srcs = CryptoJS.enc.Utf8.parse(word)
|
||||
var encrypted = CryptoJS.AES.encrypt(srcs, cbc_key, {
|
||||
iv: cbc_iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
return encrypted.toString();
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
})
|
||||
return encrypted.toString()
|
||||
}
|
||||
/**
|
||||
* 解密
|
||||
|
|
@ -26,38 +25,40 @@ export function encryptCBC(word) {
|
|||
* @returns {*}
|
||||
*/
|
||||
export function decryptCBC(word) {
|
||||
if(!aqEnnable) {
|
||||
if (!aqEnnable) {
|
||||
return word
|
||||
}
|
||||
var encrypted = CryptoJS.AES.decrypt(word, cbc_key, {
|
||||
iv: cbc_iv,
|
||||
mode: CryptoJS.mode.CBC,
|
||||
padding: CryptoJS.pad.Pkcs7
|
||||
});
|
||||
return encrypted.toString(CryptoJS.enc.Utf8);
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
})
|
||||
return encrypted.toString(CryptoJS.enc.Utf8)
|
||||
}
|
||||
|
||||
function parseUrl(url) {
|
||||
var json = {};
|
||||
if (url === undefined || typeof(url) != 'string' || url.indexOf("?") == -1 || url.indexOf("=") == -1) {
|
||||
return json;
|
||||
var json = {}
|
||||
if (
|
||||
url === undefined ||
|
||||
typeof url != 'string' ||
|
||||
url.indexOf('?') == -1 ||
|
||||
url.indexOf('=') == -1
|
||||
) {
|
||||
return json
|
||||
} else {
|
||||
|
||||
let items = url.split('?')[1].split('&');
|
||||
let items = url.split('?')[1].split('&')
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var item = items[i].split('=');
|
||||
json[item[0]] = item[1];
|
||||
var item = items[i].split('=')
|
||||
json[item[0]] = item[1]
|
||||
}
|
||||
|
||||
}
|
||||
return json;
|
||||
return json
|
||||
}
|
||||
// 是否空对象
|
||||
function isEmptyObject(obj) {
|
||||
return Object.keys(obj).length === 0;
|
||||
return Object.keys(obj).length === 0
|
||||
}
|
||||
|
||||
|
||||
// 创建一个请求实例
|
||||
console.log('当前平台信息', uni.getSystemInfoSync().platform)
|
||||
const request = (options) => {
|
||||
|
|
@ -92,22 +93,20 @@ const request = (options) => {
|
|||
config.header['Authorization'] = `${token}`
|
||||
}
|
||||
|
||||
if(options.encry) {
|
||||
if (options.encry) {
|
||||
if (config.method == 'get') {
|
||||
|
||||
console.log('parseUrl',parseUrl(config.url))
|
||||
console.log('parseUrl', parseUrl(config.url))
|
||||
let obj = parseUrl(config.url)
|
||||
config.url = `${config.url.split('?')[0]}?encryptedData=${encodeURIComponent(encryptCBC(JSON.stringify(obj)))}`
|
||||
console.log('config.url',config.url)
|
||||
|
||||
}else if(config.method == 'post') {
|
||||
|
||||
if(!isEmptyObject(config.data)) {
|
||||
config.url = `${config.url.split('?')[0]}?encryptedData=${encodeURIComponent(
|
||||
encryptCBC(JSON.stringify(obj)),
|
||||
)}`
|
||||
console.log('config.url', config.url)
|
||||
} else if (config.method == 'post') {
|
||||
if (!isEmptyObject(config.data)) {
|
||||
config.data = {
|
||||
encryptedData: encryptCBC(JSON.stringify(config.data))
|
||||
encryptedData: encryptCBC(JSON.stringify(config.data)),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue