有些接口在傳參時,需要先對接口的參數進行數據簽名加密,如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該接口就運行成功了。