//文档:https://www.apifox.cn/help/app/scripts/examples/request-handle/#url-相关信息
var cryptoJs = require("crypto-js");
//console.log(pm.request.url.query);//获取url参数
// console.log(JSON.parse(pm.request.body.raw));//获取body参数
// console.log(pm.request.headers);//获取请求头参数
// console.log(pm.request.headers.add({ key: "access_tokens", value: "456" }));//设置请求头参数
// console.log(pm.request.auth)
// 获取 Query 参数对象
var queryParams = pm.request.url.query;
// 增加 query 参数
queryParams.add({
key: "field1",
value: "value1",
});
// 修改 query 参数(如不存在则新增)
queryParams.upsert({
key: "field2",
value: "value2",
});
//如
queryParams.upsert({
key: "time", value: time+''//此处要是字符串还能新增或者修改成功
})
queryParams.upsert({
key: "secret", value: secret
})
let token = "11111"
let userid = "22222"
let time = parseInt(new Date().getTime()/1000)
let vm = JSON.parse(pm.request.body.raw).vm
let tradeNo = JSON.parse(pm.request.body.raw).tradeNo
let secret = cryptoJs.MD5(cryptoJs.MD5("123"+time+userid+token).toString()+cryptoJs.MD5('123456').toString()+vm+cryptoJs.MD5(tradeNo).toString()).toString()
console.log(secret)
pm.environment.set("time", time);
pm.environment.set("secret", secret);
pm.environment.set("access_token", token);
apifox脚本记录
于 2023-02-03 16:22:06 首次发布