php - 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"}
解决方案
推荐阅读
- android - 如何选择设备摄像头(从多个后置摄像头,我想要主摄像头)用于使用 QuaggaJS 进行条码扫描?
- symfony4 - 如何从 Sylius 管理后端的表单中删除字段?
- python - 如何在 Python 中通过名义/有序变量对文本字符串进行分组?
- css - 日期选择器图标放置在输入字段的左侧
- laravel - 在 Laravel 的 Yajra 数据表中添加列时添加列属性
- php - 迭代数据时,Laravel 无法将 stdClass 类型的对象用作 Job 的数组
- python - 基于另一个变量重新采样数据以匹配时间戳
- reason - 如何在 ReasonML 中读取带有未知键的 JSON?
- ruby-on-rails - grouped_collection_select 中的条件 group_method
- html - svg内的路径比例