我使用PHP创建一个系统,将获取webhook有效载荷时,有人退订时事通讯,但我可以找出如何在PHP中获取实际有效载荷信息。
是否有任何POST数据要获取?PHP如何查找这些POST数据?
更新:我可能发现了一些东西。看起来函数http_get_request_body()
可以解决这个问题?
$http_get_request_body
解决:)
我最近遇到了这个问题,并使用以下PHP代码来处理Campaign Monitor Web hook:
<?php
$json = file_get_contents('php://input');
$data = json_decode( $json, TRUE ); //convert JSON into array
foreach ($data['Events'] as $event)
{
// Process each entry in the request
}
JSON数据,一旦转换为数组,将以以下格式提供数据:
array (
'ListID' => 'LIST_ID_KEY',
'Events' => array (
0 =>
array (
'Type' => 'Subscribe',
'Date' => '2014-01-01 16:00:00',
'EmailAddress' => 'test@example.com',
'Name' => 'John Smith',
'CustomFields' => array (),
'SignupIPAddress' => 'API',
),
),
)