[英]How to store webhook data to database using php?
對於webhooks來說,我是新手,雖然我已經看過很少的教程,但是我仍然不知道該怎么做。 我有需要在php中讀取並保存到數據庫的webhooks數據。 我不會上載整個列表,因此一切都會丟失,但是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;
好吧,該字符串不是JSON格式。 在此處查找基本的JSON格式。 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
讀取帖子數據。 同樣,以true
作為第二個參數調用json_decode()
,它將創建一個array
,而不是stdObject
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.