首页 > 解决方案 > Json decode 什么都不返回

问题描述

我正在使用 Webhook 来接收数据,因此我可以将其存储到数据库中,因此我获取了数据Json并尝试对其进行解码,因此我可以使用检索每个数据json_decode并将它们保存在一个文本文件中,但我什么也没有得到该文件是空的
所以这是我的代码:

<?php
require_once('vendor/autoload.php');


$payload = @file_get_contents('php://input');
if (isset($payload) && !empty($payload)) {

    $data = json_decode($payload, true);
    $myFile2 = "file.txt";
    $myFileLink2 = fopen($myFile2, 'w+') or die("Can't open file.");
    $newnbord = $data;
    fwrite($myFileLink2, $newnbord);
    fclose($myFileLink2);
}

这是我通过 webhook 收到的数据示例:

{"accountingCurrency":"USD","address1":"test address","billedCurrency":"EUR","billedRecurringPrice":"0.00","bin":"444444","cardType":"VISA","city":"testcity","country":"FR","initialPeriod":"30","lastName":"test","timestamp":"2020-11-12 06:05:49","username":"llllll","threeDSecure":"NOT_APPLICABLE"}

标签: phpjsonwebhooks

解决方案


推荐阅读