首页 > 其他分享 >postman接口测试-时间戳和MD5加密

postman接口测试-时间戳和MD5加密

时间:2022-10-22 23:56:20浏览次数:56  
标签:加密 postman timestamp sign token deviceId MD5

在使用postman工具进行接口测试的时候,通过鉴权方式,有的接口字段需要获取当前或者最近时间段内时间戳,有的字段还需要进行MD5加密,这个时候我们就面临怎么获取时间戳和对相关字段进行加密的问题:

####示范例子

接口文档信息,如图所示

接口请求方式

GET | POST

路径:http//test.api.com

请求参数

请求头:

Content-Type   application/json  

ln-stamp           其值为${当前时间戳}-${5位随机字符串},比如"1655971416-abc12"

ln-sign               MD5(${clientScret}+${In-stamp})

clientScret         20913b5f9065410bbf777       

 

 

此接口中参数ln-sign 是token + timestamp + deviceId 加密后的结果

token 是接口参数中clientScret

####在postman中的pre-request script的具体代码:

1、在Pre-request-Script中添加脚本

//设置全局变量
postman.setGlobalVariable("timestamp",Math.round(new Date()/1000));
postman.setGlobalVariable("token","20913b5f9065410bbf777");
postman.setGlobalVariable("deviceId","-abc12");
//获取变量
timestamp = postman.getGlobalVariable("timestamp");
token = postman.getGlobalVariable("token");
deviceId = postman.getGlobalVariable("deviceId");
//sign:进行MD5加密
var sign = token + timestamp + deviceId;
var signmd5 = CryptoJS.MD5(sign).toString();
//signmd5设置成全局变量
postman.setGlobalVariable('signmd5',signmd5);
//输出日志
console.log("timestamp = "+timestamp);
console.log("token = "+token);
console.log("deviceId = "+deviceId);
console.log("sign = "+sign);
console.log("signmd5 = "+signmd5);

 

标签:加密,postman,timestamp,sign,token,deviceId,MD5
From: https://www.cnblogs.com/8330cc/p/16817636.html

相关文章