// 生成32位随机字符串
const arr = ['0', '1', '2', '3', '4','5', '6', '7', '8', '9', 'A', 'B','C', 'D', 'E', 'F', 'G', 'H', 'I','J', 'K', 'L', 'M', 'N', 'O', 'P','Q', 'R', 'S', 'T', 'U', 'V', 'W','X', 'Y', 'Z'];
let num = '';
for(let i = 0; i < 32; i++) {
num += arr[parseInt(Math.random() * 36)];
}
var nonce=num;
pm.collectionVariables.set("nonce", nonce);
var requestDate=JSON.parse(request.data);
//删除请求参数
delete requestDate.activityCode
delete requestDate.nonce
var activityCode = pm.globals.get("activityCode");
console.log(activityCode)
requestDate.activityCode=activityCode;
var nonce = pm.collectionVariables.get("nonce");
requestDate.nonce=nonce;
// 删除token及校验参数
delete requestDate.token;
delete requestDate.timestamp;
delete requestDate.sign;
// 获取环境token
var huodongtoken = pm.globals.get("huodongtoken");
requestDate.token=huodongtoken;
//时间戳
// var timestamp = String(Date.parse(new Date().toString()));
var timestamp = String(Math.round(new Date().getTime()));
requestDate.timestamp = timestamp
pm.globals.set("timestamp", timestamp)
console.log(requestDate)
//加密key
var key = "dwsad3$#@$!!@#^%&$_###";
//请求参数json
var requestString=JSON.stringify(requestDate)
var temp = requestString+key;
var sign=CryptoJS.MD5(temp).toString();
requestDate.sign=sign
pm.globals.set("sign",sign);
标签:nonce,加密,postman,timestamp,sign,requestDate,var,pm,请求
From: https://www.cnblogs.com/kxtomato/p/16645937.html