59-postman 取时间戳,md5加密
作者:互联网
var username = "zyz3";
var securityKey = "111111111";
var timestamp = new Date().getTime();
var paraStr = username+securityKey+timestamp;
var accesstoken = CryptoJS.MD5(paraStr).toString();
postman.setGlobalVariable("username",username)
postman.setGlobalVariable("timestamp",timestamp)
postman.setGlobalVariable("accesstoken",accesstoken)
其他实现:
var moment = require('moment');
// AES 加密方法
// word是加密内容,keyStr是秘钥
// ECB:加密算法,padding:对齐方式
// ciphertext:16进制加密,不加此方法就是Base64加密
function encrypt(word, keyStr){
var key = CryptoJS.enc.Utf8.parse(keyStr);
var srcs = CryptoJS.enc.Utf8.parse(word);
console.log('content:'+word);
var encrypted = CryptoJS.AES.encrypt(srcs, key, {mode:CryptoJS.mode.ECB, padding: CryptoJS.pad.Pkcs7});
return encrypted.toString();
}
var curDate = new Date();
var aesSecret="";
var appid = "";
var appSecret = "";
var date1 = moment().format("YYYYMMDD");
var date2 = moment().format("YYYYMMDDHHmmss");
var data = [];
var datajson = JSON.stringify(data);
var data1 = encrypt(datajson,aesSecret);
var sign1 = appid+appSecret+date1+data1;
var token = CryptoJS.MD5(sign1).toString();
var tranId = date2+appid;
var serviceId = "";
postman.setGlobalVariable("token",token)
postman.setGlobalVariable("tranId",tranId)
postman.setGlobalVariable("serviceId",serviceId)
postman.setGlobalVariable("serviceValue",serviceId)
postman.setGlobalVariable("datajson",datajson)
标签:59,postman,setGlobalVariable,datajson,var,加密,CryptoJS,md5 来源: https://www.cnblogs.com/jianquan100/p/16148267.html