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