我是webhooks的新手,我已经看过很少的教程,但我仍然不知道我需要做什么。我有这个webhooks数据,我需要在PHP中读取并保存到数据库。我不会上传整个列表所以事情会丢失,但webhook列表是对的,没有错过任何错误或错误。
{
"TransactionID":0,
"CustomerID":0,
"StaffID":0,
"Barcode":"string",
[
{
"TransactionItemID":0,
"TransactionID":0,
}],
"MiscProductItems":[],
"Tenders":
[ {
"TransactionID":0,
"TypeID":0,
}],
"BaseItems":
PHP
我看到了下面的教程,如下所示,但我不明白它的作用,是否正确'php:// input'?
我想获得条形码的价值,我该怎么做?任何帮助都会非常感激,因为我已经头疼已经试图解决这个问题。
$json = file_get_contents('php://input');
$action = json_decode($json, true);
$action_t = $action->Barcode;
答案 0 :(得分:0)
嗯,该字符串不是JSON格式。查找基本的JSON格式here。 JSON必须以对象或地图的{
和列表的[
开头。
CompleteTransaction
{
是有效的JSON。重构代码,有效的JSON看起来像这样:
{
"CompleteTransaction":
{
"TransactionID":0,
"CustomerID":0,
"StaffID":0,
"Barcode":"string",
[
{
"TransactionItemID":0,
"TransactionID":0,
}],
"MiscProductItems":[],
"Tenders":
[ {
"TransactionID":0,
"TypeID":0,
}],
"BaseItems": ".."
}
}
PHP json_decode
函数将为您返回null
。阅读php://input
取决于您将拥有哪种内容类型请求标头。如果标题不是text/plain
,则php只能从php://input
读取帖子数据。另外,使用json_decode()
作为第二个参数调用true
,它会创建array
,而不是stdObject
。