我正在使用 Mandrill 用 PHP 发送电子邮件。我已经注册了一个 webhook,所以我可以在我的应用程序和 Mandrill 中处理任何硬反弹。我遇到的困难是生成X-Mandrill-Signature标头来验证请求。
Mandrill 有关于如何在此处执行此操作的文档,但我未能正确完成。
以下是POSTMandrill 发送给我的参数:
mandrill_events: [{"type":"whitelist","action":"add","entry":{"email":"example.webhook@mandrillapp.com","detail":"example details","created_at":"2014-01-15 12:03:19"},"ts":1452869880},{"type":"whitelist","action":"remove","entry":{"email":"example.webhook@mandrillapp.com","detail":"example details","created_at":"2014-01-15 12:03:19"},"ts":1452869880}]
Run Code Online (Sandbox Code Playgroud)
我将参数解码为一个数组json_decode(stripslashes($_POST['mandrill_events']), true),然后按照帮助文章中的描述将数组传递给函数:
function generateSignature($webhook_key, $url, $params) {
$signed_data = $url;
ksort($params);
foreach ($params as $key => $value) {
$signed_data .= $key;
$signed_data .= $value;
}
return base64_encode(hash_hmac('sha1', $signed_data, $webhook_key, true));
}
Run Code Online (Sandbox Code Playgroud)
使用这个我最终得到
"http://requestb.in/ylyl00yl0Array1Array"
Run Code Online (Sandbox Code Playgroud)
为$signed_data。我已经尝试了很多递归迭代数组键和值的变体,但无济于事。
有没有人成功使用过 Mandrill 提供的例子?任何帮助,将不胜感激。
谢谢!大卫