Sparkpost 取消订阅和 webhook

Sparkpost unsubscribe and webhook

我在取消订阅时遇到问题 link 并且无法弄清楚我做错了什么。

时事通讯中的 link 是 <a title="Unsubscribe" data-msys-unsubscribe="1" href="https://example.com/en/site/unsubscribe">Unsubscribe</a>"

我创建了一个具有相同目标 URL 的 webhook,它似乎被触发了,因为它显示 "Oh yeah! Last successful batch delivered on March 04, 2016 10:02 am"。

我在 PHP 中实现了这个,起初我以为我没有正确阅读它(使用 file_get_contents('php://input') 但是当我尝试从 Sparkpost webhook 接口进行测试时 var_dump(file_get_contents('php://input')) 是:

HTTP/1.1 200
Date: Fri, 04 Mar 2016 09:17:57 GMT
Server: Apache
X-Powered-By: PHP/5.5.32
Content-Length: 1290
Connection: close
Content-Type: text/html; charset=utf-8

"<pre>string(1254) \"[{\"msys\":{\"unsubscribe_event\":{\"type\":\"list_unsubscribe\",\"campaign_id\":\"Example Campaign Name\",\"customer_id\":\"1\",\"event_id\":\"92356927693813856\",\"friendly_from\":\"sender@example.com\",\"mailfrom\":\"recipient@example.com\",\"message_id\":\"0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e\",\"rcpt_meta\":{\"customKey\":\"customValue\"},\"rcpt_tags\":[\"male\",\"US\"],\"rcpt_to\":\"recipient@example.com\",\"raw_rcpt_to\":\"recipient@example.com\",\"rcpt_type\":\"cc\",\"subaccount_id\":\"101\",\"template_id\":\"templ-1234\",\"template_version\":\"1\",\"timestamp\":1454442600,\"transmission_id\":\"65832150921904138\"}}},{\"msys\":{\"unsubscribe_event\":{\"type\":\"link_unsubscribe\",\"campaign_id\":\"Example Campaign Name\",\"customer_id\":\"1\",\"event_id\":\"92356927693813856\",\"friendly_from\":\"sender@example.com\",\"mailfrom\":\"recipient@example.com\",\"message_id\":\"0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e\",\"rcpt_meta\":{\"customKey\":\"customValue\"},\"rcpt_tags\":[\"male\",\"US\"],\"rcpt_to\":\"recipient@example.com\",\"raw_rcpt_to\":\"recipient@example.com\",\"rcpt_type\":\"cc\",\"subaccount_id\":\"101\",\"template_id\":\"templ-1234\",\"template_version\":\"1\",\"timestamp\":1454442600,\"transmission_id\":\"65832150921904138\",\"user_agent\":\"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2272.118 Safari/537.36\"}}}]\"\nstring(2) \"qq\"\n"

点击时事通讯中的取消订阅 link 时相同的转储是一个空字符串 (string(0) "")。

我是不是做错了什么?

我遇到了同样的问题。 我认为取消订阅 link 中的 URL 不需要与 webhook 相同。

不是将结果打印到屏幕,而是将其写入文件。 您会看到,在您点击取消订阅 link 一些 seconds/minutes 之后,它就会有数据。

根据这个问题的日期,我预计你已经有了答案,所以我会把它放在这里给下一个人。

取消订阅 link 不需要与您的 webhook 端点相同。它的工作方式是您将获得 "unsubscribe" webhook 事件,但用户也将被重定向到您提供的 link。

这是 SparkPost 上的文档,更详细地描述了这一点: https://www.sparkpost.com/docs/user-guide/setting-up-unsubscribe-links/

如果您需要一种快速的测试方法,可以在此处使用我的 WebHook 监视器: https://github.com/yepher/webhook_monitor

或在此处使用 运行 版本:http://webhook.yepher.com:3000/

当您访问该页面时,您将获得 "unique" URL。只需将其添加为您的 webhook 之一即可。然后发送电子邮件并单击取消订阅 link。稍等片刻后,您将看到 "unsubscribe event"。您可以打开第二个 webhook 监视器并将其用作您的 "unsubscribe link" 然后您将看到两者。 Webhook 事件将是 "POST",最终用户的实际点击将是 "GET"