选择Pre-request Scripts,输入脚本
md5
var appKey = pm.environment.get("appKey");
var appSecret = pm.environment.get("appSecret");
var queryParam = pm.request.url.query.members;
var timestamp = new Date().getTime();
let param = JSON.parse("{}");
for (let i in queryParam){
param[queryParam[i].key] = queryParam[i].value;
}
param['timestamp'] = timestamp;
var keys = [];
for (let k in param){
if (k == 'sign'){
continue;
}
keys.push(k);
}
//排序
keys.sort();
//取value
var sign = '';
sign = sign + appSecret;
for (let k of keys){
sign = sign+ (k + '' + encodeURIComponent(param[k]));
}
sign = sign+appSecret;
console.log(sign);
sign = CryptoJS.MD5(sign).toString();
console.log(sign);
pm.environment.set('sign',sign);
pm.environment.set('timestamp',timestamp);
pm.environment.set('appKey',encodeURIComponent(appKey));
```
#### sha256
```
let token = "";
let now = new Date().getTime();
let timestamp = Math.floor(now / 1000).toString();
let nonce = now.toString(16) + "-" + Math.floor(Math.random() * 16777215).toString(16);
let signature = CryptoJS.SHA256(timestamp + token + nonce + timestamp).toString(CryptoJS.enc.Hex);
console.log("signature: " + signature);
console.log("timestamp: " + timestamp);
console.log("nonce: " + nonce);
pm.environment.set('signature', signature);
pm.environment.set('timestamp', timestamp);
pm.environment.set('nonce', nonce);
```
标签:set,postman,timestamp,sign,environment,自动,签名,let,pm
From: https://www.cnblogs.com/guanchaoguo/p/17553446.html