2016-07-26 127 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