【postman】随机字符串

随机字符串

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);

Postman内置自动生成的随机数的参数

{
    
    {
    
    $guid}}:添加一个V4风格GUID(如: aa002-44ac-45ca-aae3-52bf19650e2d)
{
    
    {
    
    $timestamp}}:将当前的时间戳,精确到秒
{
    
    {
    
    $randomInt}}:添加0和1000之间的随机整数

Postman获取当前时间

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);

猜你喜欢

转载自blog.csdn.net/Orange_hhh/article/details/132415031