2016-03-04 185 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」