我正在尝试将calendly.com发送的数据发送到我的网络服务器。我正在连接到该网络服务器,并且可以使用
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch);
$myvars = 'first_name=' . $full_name . '&email=' . $thisemail;
但是,我很难将数据输入$myvars
. 我试过这个
$data = $_REQUEST['payload'];
$unescaped_data = stripslashes($data);
$obj = json_decode($unescaped_data);
$thisemail = $obj->invitee->email;
$full_name = $obj->invitee->name;
但是该变量不会填充。我也改变了
$data = $_REQUEST['payload']
到
$data = $_POST['payload']
我也尝试了一种完全不同的方法
$json = file_get_contents('php://input');
$request = json_decode($json, true);
$thisemail = $request["payload"]["invitee"]["email"];
当我只是放入虚拟字符串时$thisemail
,$full_name
它按预期工作。
我还读到这个数据是gzip
编码的。所以我也尝试过改变这个
$request = json_decode($json, true);
对此
$request = gzdecode($json);
但也没有效果。
这是数据应该是什么样子的片段
{
"event":"invitee.created",
"time":"2016-08-23T19:16:01Z",
"payload":{
"event_type":{
"kind":"1-on-1",
"slug":"event_type_name",
"name":"Event Type Name",
"duration":15
},
"event":{
"uuid":"BBBBBBBBBBBBBBBB",
"assigned_to":[
"Jane Sample Data"
],
"extended_assigned_to": [
"name": "Jane Sample Data",
"email": "user@example.com",
"primary": false
],
"start_time":"2016-08-23T12:00:00Z",
"start_time_pretty":"12:00pm - Tuesday, August 23, 2016",
"invitee_start_time":"2016-08-23T12:00:00Z",
"invitee_start_time_pretty":"12:00pm - Tuesday, August 23, 2016",
"end_time":"2016-08-23T12:15:00Z",
"end_time_pretty":"12:15pm - Tuesday, August 23, 2016",
"invitee_end_time":"2016-08-23T12:15:00Z",
"invitee_end_time_pretty":"12:15pm - Tuesday, August 23, 2016",
"created_at":"2016-08-23T00:00:00Z",
"location":"The Coffee Shop",
"canceled":false,
"canceler_name":null,
"cancel_reason":null,
"canceled_at":null
},
"invitee":{
"uuid":"AAAAAAAAAAAAAAAA",
"first_name":"Joe",
"last_name":"Sample Data",
"name":"Joe Sample Data",
"email":"not.a.real.email@example.com",
...