Postman 随机数

作者: 乘风破浪的姐姐 | 来源:发表于2021-09-22 20:19 被阅读0次

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

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

Postman的pre-requestScript中,自定义随机数

//产生随机数字
function GetRandomNum(Min,Max)
{   
    var Range = Max - Min;   
    var Rand = Math.random();   
    return(Min + Math.round(Rand * Range));   
} 
//产生随机字符串
function randomString(length, chars) {
    var result = '';
    for (var i = length; i > 0; --i) result += chars[Math.floor(Math.random() * chars.length)];
    return result;
}
 

var tid = GetRandomNum(1111111111,99999999999);

var num = GetRandomNum(25,35); 
var oaid = randomString(num, '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ');

console.log("oaid is : "+oaid);
console.log("tid is : "+tid);
//设置环境变量
pm.environment.set("oaid", oaid);
pm.environment.set("tid", tid);

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

相关文章

  • Postman 随机数

    Postman内置自动生成的随机数的参数 Postman的pre-requestScript中,自定义随机数 Po...

  • POSTMAN

    POSTMAN简介 POSTMAN安装 POSTMAN使用

  • Postman 使用入门

    Postman Postman Makes API Development Simple. 使用 PostMan ...

  • Mastering HTTP侧

    Http调试工具Postman使用 Postman Postman测试接口之JSON结构化数据提交 Postman...

  • 2021-03-08

    tabbed postman tabbed postman

  • 教程:录制postman脚本

    postman有两种使用方式: postman安装版 chrome插件版 postman安装版 postman安装...

  • Postman的安装与更新

    Postman的安装与更新 安装Postman程序 在本机安装Postman Postman兼容性很好,可被安装到...

  • poatman 使用技巧整理

    postman 新建环境 postman 查看打印 postman 参数需要md5加密 postman 用前一个请...

  • API开发神器-Postman

    在线安装Postman Chrome插件版 MAC版本 Postman+Postman Interceptor结合...

  • Postman 使用小技巧/指南

    一、什么是 Postman(前世今生) Postman[https://www.postman.com/] 诞生于...

网友评论

    本文标题:Postman 随机数

    本文链接:https://www.haomeiwen.com/subject/rfeggltx.html