
我正在使用Block.io Web Hooks。它说通知服务需要通过POST请求进行通信。它还声明所有通知事件都将使用以下JSON对象结构:
{
"notification_id" : "...", // a unique identifier issued when you created the notification
"delivery_attempt" : 1, // number of times we've tried deliverying this object
"type" : "...", // the type of notification, helps you understand the data sent below
"data" : {
... // the notification data
},
"created_at" : 1426104819 // timestamp of when we created this notification
}我已经提供了我的回调URL,我看到有行插入到我的数据库中,但是值是空的。是的,我知道我的代码将插入空白,但当我触发API时,它也是插入空白。
<?php
$post = '';
foreach($_POST as $k => $v){
$post .= $k.'='.$v.'&';
}
// save data into database
?>发布于 2018-01-30 20:37:19
webhook返回json,PHP不会将其解析为$_POST数组。
相反,您需要从以下位置获取字符串:
file_get_contents('php://input')这是你可以自己解析的。要获取数组,请执行以下操作:
$array = json_decode(file_get_contents('php://input'), true);https://stackoverflow.com/questions/48521476
复制相似问题