2016-03-04 182 views
3

我在通讯中取消订阅链接时遇到问题,无法弄清楚我做错了什么。Sparkpost取消订阅和webhook

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

我已经创建了一个具有相同目标URL的webhook,它似乎会被触发,因为它说“哦,是啊!上次成功批量交付2016年3月4日上午10:02”。

我在PHP并在第一次执行这个我想我不会读它正确(使用file_get_contents('php://input')但是当我试图从Sparkpost的测试网络挂接接口响应为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\":\"[email protected]\",\"mailfrom\":\"[email protected]\",\"message_id\":\"0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e\",\"rcpt_meta\":{\"customKey\":\"customValue\"},\"rcpt_tags\":[\"male\",\"US\"],\"rcpt_to\":\"[email protected]\",\"raw_rcpt_to\":\"[email protected]\",\"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\":\"[email protected]\",\"mailfrom\":\"[email protected]\",\"message_id\":\"0e0d94b7-9085-4e3c-ab30-e3f2cd9c273e\",\"rcpt_meta\":{\"customKey\":\"customValue\"},\"rcpt_tags\":[\"male\",\"US\"],\"rcpt_to\":\"[email protected]\",\"raw_rcpt_to\":\"[email protected]\",\"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" 

的在通讯退订链接上点击时相同的转储是一个空字符串(string(0) "")。

我做错什么了吗?

+0

所以纠正我,如果我错了 - 我想确认我理解这个问题。如果我正在阅读这个权利,您可以使用上面的方法将一个取消订阅链接添加到您的电子邮件中(这对我来说看起来是正确的)。然后你有一个你已经设置好的webhook,并且你想处理来自它的传入数据,对吗? – richleland

+0

对不起,延迟回复,但是,这是正确的。 – praxus

回答

1

我有同样的问题。 我认为取消订阅链接的URL不需要与webhook相同。

不是将结果打印到屏幕上,而是将其写入文件。 从点击取消订阅链接几秒钟/分钟后,您会看到数据。

0

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

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

这里是SparkPost一个文档描述得更详细些: https://www.sparkpost.com/docs/user-guide/setting-up-unsubscribe-links/

如果你需要一个快速的方法来测试,你可以用我的网络挂接显示器在这里: https://github.com/yepher/webhook_monitor

或者使用正在运行的版本这里:http://webhook.yepher.com:3000/

当你访问该页面时,你会得到一个“唯一”的网址。只需将其添加为您的webhook之一即可。然后发送电子邮件并点击取消订阅链接。一段时间后,你会看到“取消订阅事件”。您可以打开第二个webhook监视器并将其用作“取消订阅链接”,然后您将看到两者。 webhook事件将是一个“POST”,最终用户的实际点击将是一个“GET”