Postman之签名接口校验

有些接口在传参时,需要先对接口的参数进行数据签名加密,如pinter项目的中的签名接口 ,该接口参数如下:

{"phoneNum":"123434","optCode":"testfan","timestamp":"1211212","sign":"fdsfdsaafsasfas"} 其中,sign字段是按照特定算法进行加密后的数据。

本接口的签名算法为sign=Md5(phoneNum+ optCode+ timestamp)

那么,我们如何用postman工具对该接口进行测试呢?

一:输入接口地址以及参数

二:设置全局变量

三:在Pre-request Script 写入加密的脚本:

// 获取全局变量

phone= postman.getGlobalVariable("phone")

optCode= postman.getGlobalVariable("optCode")

//设置当前时间戳

postman.setGlobalVariable("time",Math.round(new Date().getTime()));

time = postman.getGlobalVariable('time')

//字符串进行md5加密

var str = phone+optCode+time;

var strmd5= CryptoJS.MD5(str).toString();

postman.setGlobalVariable("sign",strmd5)

最后,点击send该接口就运行成功了。

原文地址:https://www.cnblogs.com/zhangwuxuan/p/12326224.html