postman接口测试

1、使用Pre-request script 脚本

var moment = require('moment');
var data = moment().format("YYYY-MM-DD HH:mm:ss");
console.log(data);

var param1={"companyID":23,"parkID":8000207,"areaID":3};
postman.setGlobalVariable("param",param1);
param = postman.getGlobalVariable("param");
postman.setGlobalVariable("key","EGOVA_ZNBC_SIGNKEY_2015");
key = postman.getGlobalVariable("key");

new Date().
timestamp = postman.getGlobalVariable("data");

//设置当前时间戳
postman.setGlobalVariable("timestamp",Math.round(new Date().getTime()));
stamp = postman.getGlobalVariable('stamp');

//字符串进行md5加密
var str = param+stamp+key;
var strmd5= CryptoJS.MD5(str).toString().toUpperCase();
sign = postman.setGlobalVariable("sign",strmd5);

Date.prototype.format = function(fmt) { //author: meizz var o = { "M+" : this.getMonth()+1, //月份 "d+" : this.getDate(), //日 "h+" : this.getHours(), //小时 "m+" : this.getMinutes(), //分 "s+" : this.getSeconds(), //秒 "q+" : Math.floor((this.getMonth()+3)/3), //季度 "S" : this.getMilliseconds() //毫秒 }; if(/(y+)/.test(fmt)) fmt=fmt.replace(RegExp.$1, (this.getFullYear()+"").substr(4 - RegExp.$1.length)); for(var k in o) if(new RegExp("("+ k +")").test(fmt)) fmt = fmt.replace(RegExp.$1, (RegExp.$1.length==1) ? (o[k]) : (("00"+ o[k]).substr((""+ o[k]).length))); return fmt; } postman.setGlobalVariable("param",'{"companyID":"23","parkID":"8000207","parkingSpaceCode":"P0050","validStartTime":"2019-11-20 00:00:00","validEndTime":"2019-12-20 00:00:00","regionName":"test_area","plates":"京DQ0009","paid":"10","userName":"test1","roomNum":"103","phone":"13512345678"}'); param = postman.getGlobalVariable("param"); postman.setGlobalVariable("key","EGOVA_ZNBC_SIGNKEY_2015"); key = postman.getGlobalVariable("key"); //设置当前时间戳 postman.setGlobalVariable("timestamp",new Date().format("yyyy-MM-dd hh:mm:ss")); stamp = postman.getGlobalVariable('timestamp'); //字符串进行md5加密 var str = 'param='+param+'&timestamp='+stamp+'&key='+key; var strmd5= CryptoJS.MD5(str).toString().toUpperCase(); sign = postman.setGlobalVariable("sign",strmd5);

原文地址:https://www.cnblogs.com/liuyanerfly/p/11849473.html