js生成签名

var timestamp = new Date().getTime().toString();
var pzKeyArr =[{name:"walletId",value:walletId},{name:"nonceStr",value:timestamp},{name:"money",value:(totalPrice*100)},{name:"goodsName",value:encodeURIComponent(goodsname)}];
var sign = getSign(pzKeyArr);
function getSign(pzKeyArr){
var PZKEY="aLBZ0NP0aFXH60bQbxk0ktibbbnbbn";
var compare = function (obj1, obj2) {
var val1 = obj1.name;
var val2 = obj2.name;
if (val1 < val2) {
return -1;
} else if (val1 > val2) {
return 1;
} else {
return 0;
}
}
pzKeyArr.sort(compare);
var signSrc = "";
for(var i=0; i<pzKeyArr.length; i++){
signSrc += pzKeyArr[i].name + "=" + pzKeyArr[i].value + "&";
}
signSrc += "key="+PZKEY;
return calcMD5(signSrc).toUpperCase();
}
posted @ 2017-06-28 15:39  lijun8637  阅读(2363)  评论(0编辑  收藏  举报