perf:增加base64Key
This commit is contained in:
@@ -21,6 +21,16 @@ const codeMessage = {
|
||||
504: "网关超时。",
|
||||
};
|
||||
|
||||
/**
|
||||
* 默认配置
|
||||
* @type {{prefix: string, encryptBody: boolean}}
|
||||
*/
|
||||
const defaultConfig = {
|
||||
encryptBody: true,
|
||||
base64Key: "WmdUzPJXbngVNiaSsQrihg==",
|
||||
prefix: "",
|
||||
}
|
||||
|
||||
/**
|
||||
* 异常处理程序
|
||||
*/
|
||||
@@ -44,12 +54,10 @@ const request = extend({
|
||||
|
||||
|
||||
/**
|
||||
* 请求配置
|
||||
* @type {{encryptBody: boolean}}
|
||||
* 获取网络请求配置
|
||||
*/
|
||||
let httpConfig = {
|
||||
encryptBody: true,
|
||||
prefix: "",
|
||||
const getHttpConfig = () => {
|
||||
return window.httpConfig || defaultConfig;
|
||||
}
|
||||
|
||||
|
||||
@@ -87,8 +95,8 @@ const dealParamsBody = (options) => {
|
||||
* @returns {Promise<<any>>}
|
||||
*/
|
||||
async function req(url, options) {
|
||||
if (httpConfig.prefix) {
|
||||
url = httpConfig.prefix + url;
|
||||
if (getHttpConfig().prefix) {
|
||||
url = getHttpConfig().prefix + url;
|
||||
}
|
||||
return new Promise((resolve, reject) => {
|
||||
request(url, {
|
||||
@@ -132,7 +140,7 @@ async function get(url, params = {}) {
|
||||
async function post(url, data = {}) {
|
||||
|
||||
let newData = {}
|
||||
if (httpConfig.encryptBody) {
|
||||
if (getHttpConfig().encryptBody) {
|
||||
newData.encryptData = crypto.encrypt(JSON.stringify(data));
|
||||
} else {
|
||||
newData = {...data};
|
||||
@@ -155,8 +163,8 @@ async function form(url, data = {}) {
|
||||
* 网络请求配置
|
||||
* @param obj
|
||||
*/
|
||||
function setConfig(obj) {
|
||||
httpConfig = obj;
|
||||
function setConfig(obj = defaultConfig) {
|
||||
window.httpConfig = {...getHttpConfig(), ...obj};
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
const base64js = require("base64-js");
|
||||
const keyBase64 = "WmdUzPJXbngVNiaSsQrihg==";
|
||||
const SM4 = require("./SM4");
|
||||
|
||||
class Crypto {
|
||||
|
||||
constructor() {
|
||||
this.sm4 = new SM4({
|
||||
keyBuffer: base64js.toByteArray(keyBase64),
|
||||
keyBuffer: base64js.toByteArray(window.httpConfig.base64Key),
|
||||
mode: "ecb",
|
||||
cipherType: 'base64'
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user