pull file
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
Close Stale Issues / close_stale_issues (push) Has been cancelled
repo-sync / repo-sync (push) Has been cancelled
auto-deploy-tencent-scf / pre-check (push) Has been cancelled
auto-deploy-tencent-scf / deploy serverless (push) Has been cancelled
This commit is contained in:
48
bruno/app.bilibili.com/folder.bru
Normal file
48
bruno/app.bilibili.com/folder.bru
Normal file
@@ -0,0 +1,48 @@
|
||||
meta {
|
||||
name: app.bilibili.com
|
||||
}
|
||||
|
||||
script:pre-request {
|
||||
const CryptoJS = require('crypto-js');
|
||||
|
||||
console.log("start");
|
||||
|
||||
const md5 = (str) => CryptoJS.MD5(str).toString(CryptoJS.enc.Hex);
|
||||
|
||||
const replacePlaceholders = (body) => {
|
||||
for (const key in body) {
|
||||
if (typeof body[key] === 'string') {
|
||||
// Check if value contains {{}} placeholders
|
||||
const matches = body[key].match(/{{(.*?)}}/g);
|
||||
if (matches) {
|
||||
matches.forEach(match => {
|
||||
const placeholder = match.slice(2, -2); // Remove the {{ and }}
|
||||
const value = bru.getEnvVar(placeholder);
|
||||
body[key] = body[key].replace(match, value);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function appSign(params, appkey, appsec) {
|
||||
params.appkey = appkey;
|
||||
delete body.sign;
|
||||
const sortedKeys = Object.keys(params).sort();
|
||||
const sortedParams = sortedKeys.map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&');
|
||||
console.log(sortedParams);
|
||||
return md5(sortedParams + appsec);
|
||||
}
|
||||
|
||||
const body = req.getBody();
|
||||
|
||||
if (body && body.hasOwnProperty('sign')) {
|
||||
replacePlaceholders(body);
|
||||
const sign = appSign(body, bru.getEnvVar("appKey"), bru.getEnvVar("appSec"));
|
||||
console.log("calculate sign:" + sign);
|
||||
|
||||
body.sign = sign;
|
||||
}
|
||||
|
||||
req.setBody(body);
|
||||
}
|
||||
Reference in New Issue
Block a user