Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/270.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 格式化从webhook接收的数据_Php_Webhooks - Fatal编程技术网

Php 格式化从webhook接收的数据

Php 格式化从webhook接收的数据,php,webhooks,Php,Webhooks,下面是我用来从webhook获取数据的PHP代码: header('Content-Type: application/json'); $request = file_get_contents('php://input'); $req_dump = print_r( $request, true ); $fp = file_put_contents( 'request.log', $req_dump ); 我在request.log文件中收到数据,但数据如下所示: 所有%2C%22base_名

下面是我用来从webhook获取数据的PHP代码:

header('Content-Type: application/json');
$request = file_get_contents('php://input');
$req_dump = print_r( $request, true );
$fp = file_put_contents( 'request.log', $req_dump );
我在
request.log
文件中收到数据,但数据如下所示:

所有%2C%22base_名称%22%3A%22Test+products%22%2C%22button_订单%22%3Anull%2C%2C%22categories%22%3Anull%2C%22description%22%3A%22%2C%22handle%22%3A%22testproducts%22%2C%22id%22%3A%22bfe919c4-6357-46c9-a333-d3644c5%22%2C%22name%22%22%3A%22Test+products%22%22%222c%22%22%222c%22%22%222c%22sku%22id%22id%22bfe919c4-636446c5%22%222c%222c%222c%222c%222c%222c%222c%222c%222c%222c%来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,来源,价格,价格,价格,22%22%22%22%22%22%22%22%22%22%3%3%22%3%3%3%3%3%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22%22bfe919c4-6357-46c9-a333-d1db636446c5%22%2C%22重新订购点%22%3A%220%22%2C%22重新进货水平%22%3A%220%22%2C%22版本%22%3A16073174332%7D和零售商id=3fa8309c-91fa-11e3-a0f5-b8ca3a64f8f4和类型=库存。更新

我不知道如何获得正确的数据,不太确定这是由于验证

有什么想法吗


不必费劲做事。在PHP中处理帖子时,只需使用
$\u POST
。PHP应该为您处理解码

您链接到的文档,上面写着:

POST正文将包括一个名为
有效负载
的字段

因此,要访问它,您只需使用
$\u POST['payload']
。同一部分说该字段是JSON编码的,所以要将其转换为可用的结构,可以使用

例如:

// Uncomment to get a better idea of exactly what they're POSTing
// print_r($_POST);

// The payload should be here
$payload = $_POST['payload'];

// It should be JSON-encoded, so let's decode it.
$array = json_decode($payload);

// Now you should have an array of the data they sent.  Looking at the 
// product.update sample payload at
// https://docs.vendhq.com/tutorials/guides/webhooks/sample-payloads#productupdate
// there should be this kind of data:
// $array['active']      <-- should be true
// $array['brand']       <-- should be an array
// $array['brand']['id'] <-- should be 0624dbcd-ef13-11e6-e986-fcc1c343cd6a
// ... etc
//取消注释以更好地了解他们发布的内容
//打印(邮政美元);
//有效载荷应该在这里
$payload=$_POST['payload'];
//它应该是JSON编码的,所以让我们来解码它。
$array=json_解码($payload);
//现在,您应该有一个他们发送的数据数组。看着
//product.update示例有效负载位于
// https://docs.vendhq.com/tutorials/guides/webhooks/sample-payloads#productupdate
//应该有这样的数据:

//$array['active']无需费劲。在PHP中处理帖子时,只需使用
$\u POST
。PHP应该为您处理解码

您链接到的文档,上面写着:

POST正文将包括一个名为
有效负载
的字段

因此,要访问它,您只需使用
$\u POST['payload']
。同一部分说该字段是JSON编码的,所以要将其转换为可用的结构,可以使用

例如:

// Uncomment to get a better idea of exactly what they're POSTing
// print_r($_POST);

// The payload should be here
$payload = $_POST['payload'];

// It should be JSON-encoded, so let's decode it.
$array = json_decode($payload);

// Now you should have an array of the data they sent.  Looking at the 
// product.update sample payload at
// https://docs.vendhq.com/tutorials/guides/webhooks/sample-payloads#productupdate
// there should be this kind of data:
// $array['active']      <-- should be true
// $array['brand']       <-- should be an array
// $array['brand']['id'] <-- should be 0624dbcd-ef13-11e6-e986-fcc1c343cd6a
// ... etc
//取消注释以更好地了解他们发布的内容
//打印(邮政美元);
//有效载荷应该在这里
$payload=$_POST['payload'];
//它应该是JSON编码的,所以让我们来解码它。
$array=json_解码($payload);
//现在,您应该有一个他们发送的数据数组。看着
//product.update示例有效负载位于
// https://docs.vendhq.com/tutorials/guides/webhooks/sample-payloads#productupdate
//应该有这样的数据:

//$array['active']我的答案有帮助吗?我的答案有帮助吗?