This commit is contained in:
linlu 2023-05-12 13:55:29 +08:00
parent 31aa126ecf
commit 9c0222e660
2 changed files with 110 additions and 4 deletions

View File

@ -3,10 +3,13 @@ import ReactDOM from 'react-dom'
import './index.css'
import './iconfont.css'
import App from './App'
import * as serviceWorker from './serviceWorker'
ReactDOM.render(<App />, document.getElementById('root'))
// If you want your app to work offline and load faster, you can change
// unregister() to register() below. Note this comes with some pitfalls.
// Learn more about service workers: https://bit.ly/CRA-PWA

View File

@ -17,6 +17,100 @@ if (process.env.NODE_ENV === "development") {
}
window._debugType = debugType
const aKey ="e83900ca9be33747397cc81a8f68ac11";
const sKey = "6de3a75ae5718cde1e0907a593afd01f";
const parseParamsStr = (v,method) => {
const param = {};
const p = Object.assign(true, v, {});
const arr = []
Object.keys(p)
.sort()
.forEach(function(key) {
p[key] = p[key] === true ? "true" : p[key];
p[key] = p[key] === false ? "false" : p[key];
if(method === "GET"){
if( p[key] !== null ){
if(typeof p[key] === "object" && (!Array.isArray(p[key]) || (Array.isArray(p[key])) && !p[key].length)) return;
const _key = (p[key] === null || p[key] === "null") ? "" : p[key];
arr.push(`${key}=${(typeof _key === "string" || typeof _key === "number") ? decodeURIComponent(_key) : JSON.stringify(_key)}`)
}
}else{
const _key = (p[key] === null || p[key] === "null") ? "" : p[key];
arr.push(`${key}=${(typeof _key === "string" || typeof _key === "number") ? _key : JSON.stringify(_key)}`)
if (typeof p[key] === "object") {
param[key] = p[key];
} else {
param[key] = p[key];
}
}
});
return arr.join("&")
};
function base64Encode(str) {
var base64Chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
var result = "";
var padding = "";
var i, j, triplet;
for (i = 0; i < str.length; i += 3) {
triplet = (str.charCodeAt(i) << 16) | (str.charCodeAt(i + 1) << 8) | str.charCodeAt(i + 2);
for (j = 0; j < 4; j += 1) {
if (i + j * 0.75 >= str.length) {
padding = "=";
result += padding;
} else {
result += base64Chars.charAt((triplet >>> (6 * (3 - j))) & 0x3F);
}
}
}
return result;
}
const parseParams = (param) => {
param = param || {};
// param.domain = window.location.host
let paramStr = '';
for (let key in param) {
if (typeof param[key] === 'object') {
if (Array.isArray(param[key])) {
param[key].forEach((element) => {
paramStr += '&' + key + `[]=` + (element);
});
}
} else {
// if ((param[key]) || param[key] === 0)
if(param[key] !== undefined)
paramStr += '&' + key + '=' + (param[key]);
}
}
return paramStr.substr(1);
};
// axios 封装签名
function signRequest(config) {
try {
const timenow = Date.now();
const stringToSign =
"method=" + config.method.toUpperCase() + "&"+
((!!Object.keys(config?.params || {})?.length && parseParams(config.params)) ? parseParamsStr(config.params,config.method) + "&" : "") +
(!!Object.keys((config.data || {}))?.length ? parseParamsStr((config.data)) + "&" : "") +
"ak=" + aKey + "&sk="+ sKey +"&time=" + timenow;
console.log("stringToSign:",stringToSign,config,config.url)
config.headers["X-EDU-Timestamp"] = timenow;
config.headers["X-EDU-Signature"] = md5(base64Encode((stringToSign)));
} catch (error) {
debugger
}
return config;
}
async function requestTimestamp(proxy) {
if (checkSubmitFlg === false) {
const response = await fetch(proxy)
@ -112,17 +206,24 @@ export function initAxiosInterceptors() {
if (window.location.port === "3000") {
config.url = `${proxy}${url}`;
if (config.url.indexOf('?') == -1) {
config.url = `${config.url}?debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`;
config.url = `${config.url}`;
} else {
config.url = `${config.url}&debug=${debugType}&randomcode=${timestamp}&client_key=${newopens}`;
config.url = `${config.url}`;
}
config.params = config.params || {};
config.params.debug = debugType;
config.params.randomcode = timestamp || "";
config.params.client_key = newopens;
} else {
config.url = url;
if (config.url.indexOf('?') == -1) {
config.url = `${config.url}?randomcode=${timestamp}&client_key=${newopens}`;
config.url = `${config.url}`;
} else {
config.url = `${config.url}&randomcode=${timestamp}&client_key=${newopens}`;
config.url = `${config.url}`;
}
config.params = config.params || {};
config.params.randomcode = timestamp || "";
config.params.client_key = newopens;
}
}
@ -136,6 +237,8 @@ export function initAxiosInterceptors() {
window.setTimeout("setfalseInRequestMap('" + config.url + "')", 900)
}
signRequest(config)
return config;
}, error => {