var nonce = pm.variables.replaceIn('{{$guid}}').replaceAll("-", "");
var timestamp = pm.variables.replaceIn('{{$timestamp}}');
var appkey = pm.environment.get("appkey");
var secret = pm.environment.get("secret");
let mySet = new Map();
// 拼接参数准备好签名字符串
mySet.set("nonce",nonce);
mySet.set("timestamp", timestamp);
mySet.set("appKey", appkey);
var str = [];
mySet.forEach((value, key) => {
str.push(key + "=" + value);
})
// 补充key到参数串中
var sign = str.sort().join("&")+secret;
sign = CryptoJS.MD5(sign).toString();
// 先清除之前的sign变量值
pm.environment.unset("sign");
// 填充时间戳给声明的变量
pm.environment.set("timestamp", timestamp);
// 填充随机数给声明的变量
pm.environment.set("nonce", nonce);
// 7. MD5加密签名规格,并赋值给环境变量`sign`
pm.environment.set("sign", sign);