php - 从hipmob接收webhook数据

时间:2015-06-11 13:01:36

标签: php post request

我正在尝试接收应该在聊天事件中触发的hipmob(实时聊天应用)的webhook。

文档:https://www.hipmob.com/documentation/chat-events.html

我一直关注How to catch the HTTP POST request sent by a Shopify Webhook,我不得不说我完全是新手。我从第一个答案尝试了解决方案,但没有成功。

这就是我所做的:

<?php
$webhookContent = "";

$webhook = fopen('php://input' , 'rb');
while (!feof($webhook)) {
    $webhookContent .= fread($webhook, 4096);
}
fclose($webhook);

$file = 'webhook.txt';
// Open the file to get existing content
$current = file_get_contents($file);
// Append a new person to the file
// Write the contents back to the file
file_put_contents($file, $current);

error_log($webhookContent);
?>

但没有成功

1 个答案:

答案 0 :(得分:0)

我能够解决它:

   <?php

    $entityBody = file_get_contents('php://input');

    $file = 'webhook.txt';
    // Open the file to get existing content
    $current = file_get_contents($file);
    // Append a new person to the file
    // Write the contents back to the file
    file_put_contents($file, $entityBody);

    error_log($webhookContent);
    ?>