山魈webhook认证签名不匹配



山魈webhook认证验证签名

对于node js

示例验证签名

请检查下面的代码

等事件类型,但它的工作只发送、拒绝。不工作的事件类型,如打开,点击&其他

function generateSignature(webhook_key, url, params) {
var signed_data = url;
const param_keys = Object.keys(params);
param_keys.sort();
param_keys.forEach(function (key) {
signed_data += key + params[key];
}); 
hmac = crypto.createHmac('sha1', webhook_key);
hmac.update(signed_data);
return hmac.digest('base64');
}
let url = "https://your-app-domain.com/default/MandrillXP-new";
let key = "abcd1234"; //your mandrill webhook api key
let bodyPayload;
if(event.isBase64Encoded){
bodyPayload = Buffer.from(event.body, 'base64').toString()
}else{
bodyPayload = event.body
} 
let splitData = req.body.split("=")
let decodeData = decodeURIComponent(splitData[1]);    
var generatedSignature = generateSignature(key, url, { "mandrill_events": decodeData })
if (req.headers["x-mandrill-signature"]!== generatedSignature) {
console.log("signature mismatch")
}else{
console.log("signature  matched")
}

将字符串中的'+'替换为' '(空格)

var decodeData = decodeData .replace (/[+]/g, ' ');

相关内容

  • 没有找到相关文章

最新更新