0

我正在使用 PHP 创建一个系统,该系统将在有人取消订阅时事通讯时获取 webhook 有效负载,但我可以弄清楚如何在 PHP 中获取实际的有效负载信息。

是否有要获取的 POST 数据?PHP 如何查找此 POST 数据?

更新:我可能正在做某事。似乎该功能http_get_request_body()可以解决问题?

4

2 回答 2

0

我最近遇到了这个问题,并使用以下 PHP 代码来处理 Campaign Monitor Web Hooks

<?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',
            ),
        ),
)
于 2014-01-24T05:44:07.740 回答
0

$http_get_request_body解决它:)

于 2012-04-24T12:16:28.330 回答