增加参数解密
parent
d6e7e55d12
commit
9c21ef74b5
|
|
@ -4,6 +4,7 @@
|
|||
"description": "<p align=\"center\"> <img alt=\"logo\" src=\"https://uviewui.com/common/logo.png\" width=\"120\" height=\"120\" style=\"margin-bottom: 10px;\"> </p> <h3 align=\"center\" style=\"margin: 30px 0 30px;font-weight: bold;font-size:40px;\">uView</h3> <h3 align=\"center\">多平台快速开发的UI框架</h3>",
|
||||
"main": "main.js",
|
||||
"dependencies": {
|
||||
"crypto-js": "^4.2.0",
|
||||
"uview-ui": "^2.0.36",
|
||||
"vue": "^2.7.14",
|
||||
"vuex-persistedstate": "^3.2.1"
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import CryptoJS from "crypto-js";
|
||||
|
||||
const key = CryptoJS.enc.Utf8.parse("daac3ae52eff4cec"); // 16位
|
||||
|
||||
const encrypt = (word) => {
|
||||
let encrypted = "";
|
||||
if (typeof word === "string") {
|
||||
const src = CryptoJS.enc.Utf8.parse(word);
|
||||
encrypted = CryptoJS.AES.encrypt(src, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
} else if (typeof word === "object") {
|
||||
// 对象格式的转成json字符串
|
||||
const data = JSON.stringify(word);
|
||||
const src = CryptoJS.enc.Utf8.parse(data);
|
||||
encrypted = CryptoJS.AES.encrypt(src, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
}
|
||||
return encrypted.ciphertext.toString(CryptoJS.enc.Base64);
|
||||
};
|
||||
function decryptAes(params) {
|
||||
try {
|
||||
const key = CryptoJS.enc.Utf8.parse("fa4e0fae59534676"); // 16 bytes key for AES
|
||||
|
||||
const bytes = CryptoJS.AES.decrypt(params.info, key, {
|
||||
mode: CryptoJS.mode.ECB,
|
||||
padding: CryptoJS.pad.Pkcs7,
|
||||
});
|
||||
const decryptedText = bytes.toString(CryptoJS.enc.Utf8);
|
||||
return JSON.parse(decryptedText);
|
||||
} catch (e) {
|
||||
console.info(e);
|
||||
}
|
||||
}
|
||||
|
||||
export { encrypt, decryptAes };
|
||||
|
|
@ -6,6 +6,7 @@ let requestPath = 'http://127.0.0.1:8059/xgf_gwj_2.0/'; // 后台请求地址
|
|||
// let requestPath = 'https://qgxgf.qhdsafety.com/qa-prevention-xgf/'; // 外网地址
|
||||
import store from '../store/index'
|
||||
import {setRefreshToken} from "../api/api";
|
||||
import {decryptAes} from "@/utils/aes_secret";
|
||||
|
||||
function post(url, data) {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
|
@ -27,6 +28,7 @@ function post(url, data) {
|
|||
'token': store.state.userInfo.token || ''
|
||||
},
|
||||
success: (res) => {
|
||||
res.data = decryptAes(res.data);
|
||||
if (res.statusCode != 200){
|
||||
uni.showToast({
|
||||
title: '网络错误请重试',
|
||||
|
|
@ -80,6 +82,7 @@ function upload(url, data) {
|
|||
'token': store.state.userInfo.token || ''
|
||||
},
|
||||
success: (res) => {
|
||||
res.data = decryptAes(res.data);
|
||||
uni.hideLoading();
|
||||
if (JSON.parse(res.data).result === 'success') {
|
||||
resolve(JSON.parse(res.data))
|
||||
|
|
@ -120,6 +123,7 @@ function uploads(url, data) {
|
|||
'token': store.state.userInfo.token || ''
|
||||
},
|
||||
success: (res) => {
|
||||
res.data = decryptAes(res.data);
|
||||
uni.hideLoading();
|
||||
if (JSON.parse(res.data).result === 'success') {
|
||||
resolve(JSON.parse(res.data))
|
||||
|
|
|
|||
Loading…
Reference in New Issue