2016-07-26 52 views
0

我正在尝试实施Bigcommerce webhook,并且我成功地为webhook提供了商店/产品/更新*。当我试图在我的目标网址上获得响应时,我什么都没有。我使用下面的代码来记录webhook发送给我的url的响应。我的代码是Bigcommerce Webhook

<?php 
$webhook_content = ''; 
$webhook = fopen('php://input' , 'rb'); 
while(!feof($webhook)){ //loop through the input stream while the end of file is not reached 
    $webhook_content .= fread($webhook, 4096); //append the content on the current iteration 
} 
fclose($webhook); //close the resource 
$data=$webhook_content; 
$data = json_decode($webhook_content,true); //convert the json to array 
$myfile = __DIR__.'/productupdatelog.txt'; 
file_put_contents($myfile, print_r($data,true)); 
?> 

但我仍然没有得到任何东西。 Bigcommerce团队正在说,检出我们确实发送的目标网址似乎在向您发送webhook,并正确地从您的服务器接收到200响应。但我不能记录任何东西。

回答

0

可以使用的file_get_contents和对是error_log看到的数据:

$webhookContent = file_get_contents("php://input"); 
error_log($webhookContent); 
1

您可以使用file_get_content得到它,存储文件或数据库的响应。你会在接下来的1分钟内得到json编码的响应。

if ($_SERVER['REQUEST_METHOD'] == "POST") { 
     $webhookContent = file_get_contents("php://input"); 
     $result   = json_decode($webhookContent, true);    
    } 

了解更多详情:https://developer.bigcommerce.com/api/#respond-to-webhook-callbacks