postman脚本
通过postman调用密钥接口
全部环境变量
{ "id": "48f429a6-6855-4cd5-b788rtcbed5", "name": "获取组织架构", "values": [ { "key": "appid", "value": "fslocal_miwork", "enabled": true }, { "key": "appkey", "value": "03a2e28765854834fd52aaf1068355", "enabled": true } ], "_postman_variable_scope": "environment", "_postman_exported_at": "2022-04-11T12:06:21.421Z", "_postman_exported_using": "Postman/8.9.1" }
脚本测试执行
var x5 = { run: function(appid,appkey) { if (typeof appid == "undefined") { appid = pm.environment.get("appid"); } if (typeof appkey == "undefined") { appkey = pm.environment.get("appkey"); } var self = this; var tmpArr = {}; var reqData = request.data;
//var data = pm.request.body.raw;获取消息体
//base64Data = CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse());
//CryptoJS.SHA256();做加密
if (_.isObject(reqData)) { var keys = _.sortBy(_.keys(reqData)); _(keys).forEach(function(key) { tmpArr[key] = reqData[key]; }).value() } delete tmpArr.data; var json_body = JSON.stringify(tmpArr).replace(/\\\\u/g, '\\u'); var sign = CryptoJS.MD5(appid + json_body + appkey, {asString: true}).toString().toUpperCase(); var data = { header :{ appid : appid, sign : sign }, body : json_body }; data = JSON.stringify(data).replace(/\\\\u/g, '\\u'); pm.globals.set("data", CryptoJS.enc.Base64.stringify(CryptoJS.enc.Utf8.parse(data))); } } x5.run();
执行方法传递参数通过xxx-form-urlencoded
data:{{data}}
currentPage:1
pageSize:1
status:I