zoukankan      html  css  js  c++  java
  • 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/

  • 相关阅读:
    C语言I博客作业09
    C语言I博客作业08
    14
    13
    12
    11
    10
    9
    8
    7
  • 原文地址:https://www.cnblogs.com/ycwu314/p/11268901.html
Copyright © 2011-2022 走看看