赞
踩
1.在代码片段中,使用 JavaScript 将需要加密的参数拼接成一个字符串,例如
- let json = JSON.parse(pm.request.body);
- let arr = []
- arr.push(json["appKey"])
- arr.push(json["ts"])
- arr.push(json["randomNum"])
- arr.push(JSON.stringify(json["body"]))
- arr.push("c5a05d17fe601d2b6f4346914c826604")
- let str = arr.map(e => e + "").join("");
2.安装 CryptoJS 库。在 Postman 的 "Pre-request Script" 或 "Tests" 中,使用以下命令安装 CryptoJS:
npm install crypto-js
3.在代码片段中,使用 CryptoJS 对拼接后的字符串进行 MD5 加密,转化为小写字符串,赋值给请求变量。例如:
- let encryStr = CryptoJS.MD5(str).toString()
- json.sign = encryStr.toLowerCase();
- pm.globals.set("sign", json.sign);
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。