let timestamp = (new Date()).getTime().toString();
timestamp = timestamp.substr(0,13);
//设置集合的全局变量
pm.collectionVariables.set("timestamp", timestamp);
var appkey='XXXXXXX';
pm.collectionVariables.set("appkey",appkey);
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0,
v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
console.log(generateUUID());
var nonce = generateUUID();
pm.collectionVariables.set("nonce",generateUUID());
const requestBody = pm.request.body.raw;//获取请求体
const newRequestBody = requestBody.replace(/\s+/g, '');//将请求体的空格和换行删除
var tianti='XXXXXXX';
var signStr ='appkey'+appkey +'nonce'+nonce+'timestamp'+timestamp+newRequestBody+tiantian;
console.log("signStr :"+signStr);
//md5加密
var signature=CryptoJS.MD5(signStr).toString().toUpperCase();
console.log("sign:"+signature);
pm.collectionVariables.set("sign", signature);
中台验签算法
let timestamp = (new Date()).getTime().toString();
timestamp = timestamp.substr(0,13);
//设置集合的全局变量
pm.collectionVariables.set("timestamp", timestamp);
var appkey='XXXXXXXXX';
pm.collectionVariables.set("appkey",appkey);
function generateUUID() {
return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {
var r = Math.random() * 16 | 0,
v = c === 'x' ? r : (r & 0x3 | 0x8);
return v.toString(16);
});
}
console.log(generateUUID());
var nonce = generateUUID();
pm.collectionVariables.set("nonce",generateUUID());
const requestBody = pm.request.body.raw;//获取请求体
const newRequestBody = requestBody.replace(/\s+/g, '');//将请求体的空格和换行删除
var secret='XXXXXXXX';
var signStr ='appkey'+appkey +'nonce'+nonce+'timestamp'+timestamp+requestBody+secret;
console.log("signStr :"+signStr);
//md5加密
var signature=CryptoJS.MD5(signStr).toString().toUpperCase();
console.log("sign:"+signature);
console.log("signStr :"+signStr);
pm.collectionVariables.set("sign", signature);
pm.request.headers.add({
key: 'Content-Type',
value: 'application/json;charset=UTF-8'
});
pm.request.headers.add({
key: 'sign',
value: signature
});
pm.request.headers.add({
key: 'appkey',
value: appkey
});
pm.request.headers.add({
key: 'timestamp',
value: timestamp
});
pm.request.headers.add({
key: 'nonce',
value: nonce
});