Php 如何获取webhook参数
在我的网站上,我试图将数据保存在另一台服务器上,即整个webhook预览:Php 如何获取webhook参数,php,json,webhooks,Php,Json,Webhooks,在我的网站上,我试图将数据保存在另一台服务器上,即整个webhook预览: curl -H "Authorization: Token token=sfg999666t673t7t82" -H "Content-Type: application/json" -H 'Authorization: Bearer oibk2s757l0et81s47uhq47a89w7qbnv' -d '{ "entity":"order", "order_id":{{ item.entity_
curl -H "Authorization: Token token=sfg999666t673t7t82" -H "Content-Type: application/json" -H 'Authorization: Bearer oibk2s757l0et81s47uhq47a89w7qbnv' -d '{
"entity":"order",
"order_id":{{ item.entity_id }},
"customer_id":{{ item.customer_id }},
"increment_id":{{ item.increment_id }},
"title": "New order placed",
"message": "Your order has been placed , With Order Id {{ item.increment_id }} will let you know once processed",
"type": 2
}' -X POST 'http://299.247.3.52/fcm/webhook/receive/index/'
但以下代码不起作用:
$json = json_decode(file_get_contents("php://input"), true);
Or
print_r($_REQUEST)
如何获取标题/帖子值?也在PHP代码中进行请求。不在单独的脚本上 你需要停止一次完成太多不同的步骤 在这里,您将两件事情混为一谈,每件事情都可能单独失败——您无法读取任何实际的输入后数据,或者尝试将读取的内容解码为JSON可能会失败。按照您编写本文的方式,您只能查看
$json
之后包含的内容,因此无法判断这两个步骤中的哪一个实际失败
$request_body = file_get_contents("php://input");
$json = json_decode($request_body, true);
如果失败,您可以分别检查每个步骤的结果。您可以进行var\u转储($request\u body)首先,查看您是否确实通过这种方式收到了发布的数据
在本例中,您可能会发现情况就是这样,但尝试将其解码为JSON之后失败了
如果您真的像上面显示的那样发送cURL请求,那么这并不奇怪——因为该数据一开始就不是有效的JSON
这里的双大括号中的这些部分肯定是占位符。在发送此文件之前,您需要先将其替换为实际值。这需要变成类似于“order\u id”:1234,
,只有这样它才是有效的JSON
$request_body = file_get_contents("php://input");
$json = json_decode($request_body, true);
"order_id":{{ item.entity_id }},