提供一份样例,供参考
var apikey = 'key';
// 获取当前时间
var timestamp = parseInt(pm.variables.replaceIn('{{$timestamp}}'));
var salt = 'secret';
var expires = String(timestamp + 3600);
// 获取请求路径
var path = pm.request.url.getPath();
// 生成签名,需要utf8字符集
var signature = CryptoJS.enc.Utf8.parse(path);
var secret = CryptoJS.enc.Utf8.parse(salt + expires);
var hmac = CryptoJS.HmacSHA256(signature, secret).toString();
// 设置到变量
pm.variables.set('hmac', hmac);
pm.variables.set('expires', expires);
// 追加到query参数
pm.request.addQueryParams('APIKEY=' + apikey);
pm.request.addQueryParams('EXPIRES=' + expires);
pm.request.addQueryParams('HMAC=' + hmac);
参考sdk:
Postman Collection: https://www.postmanlabs.com/postman-collection/index.html
发表评论