You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

122 lines
3.1 KiB

import config from '../config.js'
import {
encryptDes,
decryptDes,
encrypt_by_des
} from '@/utils/des.js'
import Base64 from 'base-64';
import cryptoJS from "crypto-js"
const httpRequest = (params) => {
if (params.isLoad) {
// uni.showLoading({
// title: "Loading..."
// });
}
const json_data = {
appcode: 'DOPE+', //应用编码
appchannel: 'DOPEGOOGLE', //应用发布渠道
appver: '1.0.0', //应用版本
appname: 'cnic_buyer', //应用名称
manufacturer: 'HUAWEI', //设备生产商
phonebrand: 'HORNOR', //设备品牌
phonetype: 'X30', //设备型号
phoneos: 'ANDROID' // 设备系统
}
let data = Object.assign(json_data, params.data)
// console.info(data)
uni.setStorageSync('appdata', data)
let key = params.key
if (params.isEncryption) {
// console.info(JSON.parse(JSON.stringify(data.consignee)))
key = encryption(JSON.parse(JSON.stringify(data[params.key])))
// console.info(key)
data = encryption(data)
// console.log(data)
data[params.key] = key
} else {
data = encryption(data)
}
// console.info(data)
//进行加密
// console.info(encryptDes(JSON.stringify(data),'6780f04cf2e211ec86a8005056c00008'))
// console.info(encrypt_by_des(JSON.stringify(data),'6780f04cf2e211ec86a8005056c00008'))
// data=Base64.encode(encryptDes(JSON.stringify(data),'6780f04cf2e211ec86a8005056c00008'));
data = encryptDes(JSON.stringify(data), '6780f04cf2e211ec86a8005056c00008');
// console.info(data)
// 解密
let data2 = JSON.parse(decryptDes(data, "6780f04cf2e211ec86a8005056c00008"))
// console.info(data2)
let data1 = {
data: data
}
let httpOptions = {
url: config.apiUri + params.url,
data: data1,
method: params.method,
header: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
// 'cookies':uni.getStorageSync('cookies') || ""
}
};
return new Promise((resolve, reject) => {
uni.request({
...httpOptions,
success: res => {
// console.info(res)
uni.hideLoading();
// 进行解密
// let list = res.data
// res.data=JSON.parse(decryptDes(res.data,"6780f04cf2e211ec86a8005056c00008"))
res.data = JSON.parse(decryptDes(res.data, "6780f04cf2e211ec86a8005056c00008"))
// res.data=Base64.decode(decryptDes(res.data,'6780f04cf2e211ec86a8005056c00008'));
// console.info(list)
// res.data = list
if (res.data.error != 0 && params.errMsg) {
// uni.showToast({
// // title: res.data.message,
// icon:'none',
// duration: 2000
// });
}
if (res.data.error != 0 && params.isCookies) {
let user_info = uni.getStorageSync('user_info')
user_info.isLogin = false
uni.setStorageSync('user_info', user_info)
}
resolve(res.data);
},
fail: err => {
uni.hideLoading();
reject(err);
}
})
})
}
const encryption = (data) => {
for (let key in data) {
let item = data[key]
if (key === 'comments') {
data[key] = encryptDes(JSON.stringify(data[key]), '6780f04cf2e211ec86a8005056c00008');
data[key] = JSON.parse(decryptDes(data[key], "6780f04cf2e211ec86a8005056c00008"))
} else {
data[key] = encodeURIComponent(item)
}
}
return data
}
export default httpRequest;