postman快速体验API效果
目的:通过postman快速请求openApi,不需要在idea等工具上面执行脚本
1.参数说明(获取证件照抠图接口为例)
2.复制代码到脚本里面
替换掉ak、sk和app_id
需复制的代码如下:
<code>
var CryptoJS = require('crypto-js');
//联调ak sk
var ak = '1E6FD7F4CEADF35EE7B4BCB5E6911963';
var sk = '4A1459AF9EF9ACFDBF03FDF2762F1BBB';
var app_id = 'QGNRVI166130';
var httpMethod = pm.request.method;
var url = pm.request.url;
//生成uri
var uri = url.path.join('/');
uri ="/"+uri+"/";
//获取queryString
var queryString = pm.request.url.query;
var jsonBody = pm.request.body.raw;
var timestamp = Math.floor(new Date().getTime() / 1000);
if(httpMethod=="POST"){
var requestRaw = [httpMethod, "@", uri, "@", queryString, "@", timestamp.toString(), "@", jsonBody].join("");
}
if(httpMethod=="GET"){
//将body设置为空
pm.request.body=null;
var requestRaw = [httpMethod, "@", uri, "@", queryString, "@", timestamp.toString()].join("");
}
console.log(requestRaw);
var hash = CryptoJS.HmacSHA1(requestRaw, sk);
var signature = CryptoJS.enc.Base64.stringify(hash)
pm.request.headers.add({
key: 'X-Timestamp',
value: timestamp
});
pm.request.headers.add({
key: 'X-AccessKey',
value: ak
});
pm.request.headers.add({
key: 'X-Signature',
value: signature
});
pm.request.headers.add({
key: 'app_id',
value: app_id
});
</code>