小编Dav*_*ord的帖子

使用 PHP 验证 Mandrill Webhook

我正在使用 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 提供的例子?任何帮助,将不胜感激。

谢谢!大卫

php webhooks mandrill

5
推荐指数
1
解决办法
898
查看次数

标签 统计

mandrill ×1

php ×1

webhooks ×1