【问题标题】:How do I fetch Campaign Monitor webhook payload with PHP?如何使用 PHP 获取 Campaign Monitor webhook 有效负载?
【发布时间】:2014-11-06 20:26:01
【问题描述】:

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

是否有任何 POST 数据要获取? PHP 如何查找这个 POST 数据?

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

【问题讨论】:

    标签: php api webhooks


    【解决方案1】:

    $http_get_request_body 解决了:)

    【讨论】:

      【解决方案2】:

      我最近遇到了这个问题,并使用以下 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',
                  ),
              ),
      )
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2017-02-11
        • 1970-01-01
        • 2014-05-02
        • 2018-06-29
        • 2017-05-12
        • 2016-06-06
        • 2019-06-22
        • 1970-01-01
        相关资源
        最近更新 更多