0
私はbot(Facebookメッセンジャー)を開発中で、応答しません。 'file_get_contents'の値はnull/emptyを返します。Facebook Messenger Webhook JSON file_get_contents empty
$ update_response = file_get_contents( "php:// input");
まず、既存のページにアプリケーションを追加しましたが、機能しませんでした。 新しいページと新しいアプリケーションを作成しましたが、エラーは残りました。 私はそれがページまたはアプリケーションの設定かもしれないと思った。
何が間違っていますか?
<?php
require('parser.php');
define('BOT_TOKEN', 'FACEBOOK TOKEN');
define('VERIFY_TOKEN', 'MY TOKEN');
define('API_URL', 'https://graph.facebook.com/v2.6/me/messages?access_token='.BOT_TOKEN);
$hub_verify_token = null;
function processMessage($message) {
// processa a mensagem recebida
$sender = $message['sender']['id'];
$text = $message['message']['text'];//texto recebido na mensagem
if (isset($text)) {
\t \t if ($text === "Mega-Sena") {
\t \t sendMessage(array('recipient' => array('id' => $sender), 'message' => array("text" => getResult('megasena', $text))));
\t \t } else if ($text === "Quina") {
\t \t sendMessage(array('recipient' => array('id' => $sender), 'message' => array("text" => getResult('quina', $text))));
\t \t } else if ($text === "Lotomania") {
\t \t sendMessage(array('recipient' => array('id' => $sender), 'message' => array("text" => getResult('lotomania', $text))));
\t \t } else if ($text === "Lotofácil" || $text === "Lotofacil") {
\t \t sendMessage(array('recipient' => array('id' => $sender), 'message' => array("text" => getResult('lotofacil', $text))));
\t \t } else {
\t \t sendMessage(array('recipient' => array('id' => $sender), 'message' => array('text' => 'Olá! Eu sou um bot que informa os resultados das loterias da Caixa. Será que você ganhou dessa vez? Para começar, digite o nome do jogo (Lotomania, Quina, Mega ou Lotofácil) para o qual deseja ver o resultado.')));
\t \t }
}
}
function sendMessage($parameters) {
$options = array(
'http' => array(
'method' => 'POST',
'content' => json_encode($parameters),
'header'=> "Content-Type: application/json\r\n" .
"Accept: application/json\r\n"
)
);
$context = stream_context_create($options);
file_get_contents(API_URL, false, $context);
}
if(isset($_REQUEST['hub_challenge'])) {
$challenge = $_REQUEST['hub_challenge'];
$hub_verify_token = $_REQUEST['hub_verify_token'];
}
if ($hub_verify_token === VERIFY_TOKEN) {
echo $challenge;
}
$update_response = file_get_contents("php://input");
//-----VERIFY LOG-----//
$fh = fopen("log.txt", "w+");
fwrite($fh, $update_response);
fclose($fh);
$update = json_decode($update_response, true);
if (isset($update['entry'][0]['messaging'][0])) {
processMessage($update['entry'][0]['messaging'][0]);
}
?>
私はあなたの提案を試してみましたが、アプリケーションからの結果/リターンを得るためにnGrokを使用し始めました。 しかし、ページは何も返さず、データもエラーも返しません。 –
Webサーバーのアクセスログとエラーログには何が表示されますか?私はそれがnGrok経由でどのように動作するのか分かりません。実サーバを使用してみてください。最も簡単なアプローチは、AWSインスタンスを作成し、Let's Encrypt(無料)を使用してSSLをセットアップし、30分以内に結果を得ることです。 – Sanjay