WooCommerce如何接收WebHooks数据?

WooCommerce如何接收WebHooks数据?,woocommerce,webhooks,Woocommerce,Webhooks,我是WooCommerce WebHooks开发的新手 我启用了RESTAPI 在订单创建时创建webhook操作 设置操作url 我还尝试将webhooks触发值保存到一个文件中 $json = file_get_contents('php://input'); $action = json_decode($json, true); $myfile = fopen("newfile.txt", "w") or die("Unable to open file!"); $txt = $ac

我是WooCommerce WebHooks开发的新手

  • 我启用了RESTAPI
  • 在订单创建时创建webhook操作
  • 设置操作url
我还尝试将webhooks触发值保存到一个文件中

$json = file_get_contents('php://input');
$action = json_decode($json, true);

$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");
$txt = $action;
fwrite($myfile, $txt);

fclose($myfile);
但是我没有触发我的代码。

解决了它:

<?php
$webhookContent = "";



$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

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


$txt = $webhookContent;
fwrite($myfile, $txt);

fclose($myfile);

?>

解决了这个问题:

<?php
$webhookContent = "";



$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

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


$txt = $webhookContent;
fwrite($myfile, $txt);

fclose($myfile);

?>