postman使用pre-request script计算md5

接口加了验签逻辑,具体是md5(salt+时间戳)。被某君吐槽说测试不方便啊能不能先关掉。其实没有必要打开又关闭验签功能,postman的pre-request script功能完全可以模拟客户端加密过程。

创建环境变量

接口使用了tmsign字段,先创建环境变量

pre-request script脚本

1
2
3
4
5
var tm = new Date().getTime()
var salt = 'F5ZeNjdP2IpoLYc3'
var sign = CryptoJS.MD5(salt + tm).toString()
postman.setEnvironmentVariable('tm', tm);
postman.setEnvironmentVariable('sign', sign);

使用CryptoJS计算md5。然后把tmsign设置为环境变量。注意url参数的写法,是用双花括号包住环境变量:tm=

验证

点击SendCode,可以看到tm和sign已经被替换了。

1
2
3
4
GET /test/hello2?tm=1564422732095& sign=69b5e46368f3e1f3aa3be03ddd4b7dae HTTP/1.1
Host: localhost:8000
cache-control: no-cache
Postman-Token: f8388dfc-c1d7-4c99-a5f5-5839f31da081

so easy!

 

https://ycwu314.github.io/p/postman-use-prescript-to-calculate-md5-sign/

posted @ 2019-07-30 11:18  ycwu314  阅读(1197)  评论(0编辑  收藏  举报