简体   繁体   English

如何获取Webhook响应数据

[英]How to get webhook response data

I'm still new to webhook. 我还是webhook的新手。 What I need to do here is to do a callback whenever there's a new registration on the registration platform called Bizzabo. 我需要做的是,每当注册平台上有一个名为Bizzabo的新注册时,就进行回调。 This platform has provided Webhook integration by having us putting the Endpoint URL and select which action that will trigger the Webhook. 该平台通过让我们放置端点URL并选择将触发Webhook的操作来提供了Webhook集成。 I've also used Request Bin and it displays the data well. 我还使用了Request Bin,它可以很好地显示数据。

However, how can I echo the JSON body data like how it displayed in Request Bin in my interface URL php? 但是,我如何回显JSON正文数据,如其在界面URL php中的“请求Bin”中显示的样子?

This is how the Webhook integration looks like on Bizzabo 这就是Webhook集成在Bizzabo上的样子

Data captured from Webhook when tested using Request Bin 使用请求容器进行测试时从Webhook捕获的数据

Thank you! 谢谢!

Your need an endpoint which receives the callback instead Request Bin, then access it in the following way using file_get_contents('php://input') and json_decode() 您需要一个接收回调而不是请求Bin的终结点,然后使用file_get_contents('php://input')json_decode()以以下方式访问它

For example http://example.com/bizzabo-callback-handler.php 例如http://example.com/bizzabo-callback-handler.php

<?php
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
    // fetch RAW input
    $json = file_get_contents('php://input');

    // decode json
    $object = json_decode($json);

    // expecting valid json
    if (json_last_error() !== JSON_ERROR_NONE) {
        die(header('HTTP/1.0 415 Unsupported Media Type'));
    }

    /**
     * Do something with object, structure will be like:
     * $object->accountId
     * $object->details->items[0]['contactName']
     */
    // dump to file so you can see
    file_put_contents('callback.test.txt', print_r($object, true));
}

If the data receiving in compressed format(gzip) use gzdecode : 如果以压缩格式(gzip)接收数据,请使用gzdecode

<?php

    if (!function_exists('gzdecode')){
        function gzdecode($data){
            // strip header and footer and inflate
            return gzinflate(substr($data, 10, -8));
        }
    }

    // get compressed (gzip) POST request into a string
    $comprReq = file_get_contents('php://input');

    // get decompressed POST request
    $decomprReq = gzdecode($comprReq);
     // decode to json
    $jsonData = json_decode($decomprReq, true);
    // do your processing on $jsonData
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM