postman-对请求参数加密

// 生成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);
posted @ 2022-09-01 11:23  我是小菜鸡丫丫  阅读(514)  评论(0编辑  收藏  举报