$hubVerifyToken = 'YES-THIS-IS-MY-BOT';
$accessToken = "MY-HOPEFULLY-RIGHT-ACCESS-TOKEN-I-RENEWED-IT-SEVERAL-TIMES";
if ($_REQUEST['hub_verify_token'] === $hubVerifyToken) {
echo $_REQUEST['hub_challenge'];
exit;
}
$input = json_decode(file_get_contents('php://input'), true);
$sender = $input['entry'][0]['messaging'][0]['sender']['id'];
$message = $input['entry'][0]['messaging'][0]['message']['text'];
$answer = "Error";
if($message == "hi") {
$answer = "Hello";
}
$jsonData = '{
"recipient":{
"id":"' . $sender .'"
},
"message":{
"text":"' . $answer . '"
}
}';
$ch = curl_init('https://graph.facebook.com/v2.6/me/messages?access_token='.$accessToken);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json'));
$resp = curl_exec($ch);
我检查了$ resp,我发现它返回' false'? 但我完全不知道为什么......
你能帮帮我吗? 如果您需要更多信息,请评论。谢谢。