This commit is contained in:
xy
2026-03-13 01:38:40 +00:00
parent e6e4f88257
commit 28855885cd
311 changed files with 89544 additions and 94350 deletions

View File

@@ -1,39 +1,41 @@
import { genCode } from 'app/pubUtils/util';
import { MsgEncrypt } from "app/pubUtils/sysUtil";
import { genCode } from '../../../shared/pubUtils/util';
import { MsgEncrypt } from "../../../shared/pubUtils/sysUtil";
import { Context } from 'egg';
module.exports = options => {
return async function parmsDecode(ctx: Context, next) {
module.exports = (options: any) => {
return async function parmsDecode(ctx: Context, next: () => Promise<any>) {
let url = ctx.request.url;
ctx.logcode = genCode(10);
if(url.indexOf("/dev") == 0 || url.indexOf("/web") == 0 || url.indexOf("/cb") == 0) {
if (url.indexOf("/dev") == 0 || url.indexOf("/web") == 0 || url.indexOf("/cb") == 0) {
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] request: ${JSON.stringify(ctx.request.body)}`);
await next();
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] res: ${JSON.stringify(ctx.body)}`)
return;
}
}
if (options.threshold && ctx.length < options.threshold) return;
const reqBody = ctx.request.body;
const reqHeader = ctx.request.header;
console.log(ctx.app.config.decodeParm)
if(ctx.app.config.decodeParm == false) {
if (ctx.app.config.decodeParm == false) {
await next();
return;
}
if (!reqBody.data) return;
let msgEncrypt = new MsgEncrypt({ encodeK: reqHeader['k'], encodeV: reqHeader['v'] });
const k = typeof reqHeader['k'] === 'string' ? reqHeader['k'] : reqHeader['k'][0];
const v = typeof reqHeader['v'] === 'string' ? reqHeader['v'] : reqHeader['v'][0];
let msgEncrypt = new MsgEncrypt({ encodeK: k, encodeV: v });
console.log(`encode str ${msgEncrypt.encryptMsg(reqBody)}`);
try {
let decryptResult = msgEncrypt.decryptMsg(reqBody.data);
if(!decryptResult) throw new Error('params parse err');
if (!decryptResult) throw new Error('params parse err');
ctx.request.body = decryptResult;
console.log('req body', ctx.request.body);
console.log('req body', ctx.request.body);
ctx.service.utils.log('INFO', `[${ctx.request.url}] [${ctx.logcode}] request: ${JSON.stringify(ctx.request.body)}`)
} catch (e) {
console.error('parms parse err');
@@ -41,9 +43,9 @@ module.exports = options => {
}
try{
try {
await next();
} catch(e) {
} catch (e) {
ctx.service.utils.log('ERROR', `[${ctx.request.url}] [${ctx.logcode}] err: ${(<Error>e).stack}`);
throw e;
}