来自API的回调响应未更新

时间:2018-09-12 14:58:31

标签: php

我在服务器的API回调网址中收到了以下json格式的响应。

{
    "sessionId": "2_MX4xMzExMjU3MX5-MTQ3MDI1NzY3OTkxOH45QXRr",
    "projectId": "123456",
    "event": "connectionCreated",
    "timestamp": 1470257688309,
    "connection": {
        "id": "c053fcc8-c681-41d5-8ec2-7a9e1434a21e",
        "createdAt": 1470257688143,
        "data": "TOKENDATA"
    }
}

我尝试了以下代码来访问它并将其保存在DB中:

<?php
$str = file_get_contents('php://input'); 
if ($str) {    
// decode JSON
$json = json_decode($str, true);
// get the data
$Session_ID = $json['sessionId'];
$start_time = $json['connection']['createdAt'];

include_once('inc/connection.inc.php'); 
$sql = "INSERT INTO sessmonitor() 
        VALUES (:sessid,:time)";
$q = $conn->prepare($sql);
$q->execute(array(':sessid'=> $Session_ID,
':time'=> $start_time
)
); 
$conn = null;
}
?>

我没有收到任何更新并收到错误: 未定义索引:连接

请问我在做什么错?

0 个答案:

没有答案