function randomString(e){
e = e ||32;
var t ="ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678",
a = t.length,
n ="";for(i =0; i < e; i++) n += t.charAt(Math.floor(Math.random() * a));return n
}
var repo_name = randomString(6);
pm.environment.set("repo_name", repo_name);
var moment = require("moment"); // 获取时间
var data = moment().format(" YYYY-MM-DD HH:mm:ss"); //定义时间格式
console.log(data);
pm.globals.set("TIME", data); //设置为全局变量
Postman获取当前时间戳(毫秒)
// 设置当前时间戳(毫秒)
Timestamp = Math.round(new Date().getTime());
postman.setGlobalVariable("Timestamp",Timestamp);
Postman签名
//设置签名秘钥
key ="E84F708A9B8B42E6A08F9025CBBCC934";
//字符串进行md5加密
var token=pm.request.headers.get("Token")||"";
var body=pm.request.body.raw;
body = body.replace("{{Timestamp}}",Timestamp);
//计算签名
var str = token+"&"+body+"&"+key;
postman.setGlobalVariable("str",str);
var strmd5= CryptoJS.MD5(str).toString(CryptoJS.enc.Hex).toUpperCase();
postman.setGlobalVariable("SignKey",strmd5);