Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 来自facebook messenger机器人的空消息_Php_Facebook_Facebook Messenger_Facebook Messenger Bot - Fatal编程技术网

Php 来自facebook messenger机器人的空消息

Php 来自facebook messenger机器人的空消息,php,facebook,facebook-messenger,facebook-messenger-bot,Php,Facebook,Facebook Messenger,Facebook Messenger Bot,我按照指南从中构建了一个facebook messenger机器人 但在我的软件里,我总是收到一个空洞的回应 这里是我的机器人代码: define('PAGE_TOKEN',"xxx"); define('VERIFY_TOKEN',"xxx"); if(isset($_GET['hub_mode']) && isset($_GET['hub_challenge']) && isset($_GET['hub_verify_token'])) { if

我按照指南从中构建了一个facebook messenger机器人

但在我的软件里,我总是收到一个空洞的回应

这里是我的机器人代码:



    define('PAGE_TOKEN',"xxx");
    define('VERIFY_TOKEN',"xxx");

    if(isset($_GET['hub_mode']) && isset($_GET['hub_challenge']) && isset($_GET['hub_verify_token'])) {
        if($_GET['hub_verify_token']==VERIFY_TOKEN && $_GET['hub_mode']=='subscribe') {
            echo $_GET['hub_challenge'];
        }
    }

    $input = json_decode(file_get_contents('php://input'), true);
    // Get the Senders Graph ID
    $sender = $input['entry'][0]['messaging'][0]['sender']['id'];
    // Get the returned message
    $message = $input['entry'][0]['messaging'][0]['message']['text'];

    error_log($input);
    error_log($sender);
    error_log($message);

验证阶段正常,但当我在错误日志文件中向我的机器人发送消息时,我发现只有空值:



    [Sun Aug 13 17:35:49.617919 2017] [:error] [pid 22501] [client 173.252.124.11:18834]
    [Sun Aug 13 17:35:49.617951 2017] [:error] [pid 22501] [client 173.252.124.11:18834]
    [Sun Aug 13 17:35:49.617972 2017] [:error] [pid 22501] [client 173.252.124.11:18834]

这里还有我的访问日志:



    173.252.124.30 - - [13/Aug/2017:17:35:48 +0200] "POST /webhook HTTP/1.1" 301 3621 "-" "-"
    173.252.124.11 - - [13/Aug/2017:17:35:49 +0200] "GET /webhook/ HTTP/1.1" 200 328 "-" "-"

那么为什么$input变量总是空的呢

173.252.124.30 - - [13/Aug/2017:17:35:48 +0200] "POST /webhook HTTP/1.1" 301 3621 "-" "-"
173.252.124.11 - - [13/Aug/2017:17:35:49 +0200] "GET /webhook/ HTTP/1.1" 200 328 "-" "-"
您的服务器使用301重定向来响应POST请求,因此客户端(Facebook)必须下一步发出GET请求,因此您不会看到更多的POST数据


看到第一个URL是
/webhook
,并被重定向到
/webhook/
,这很可能只是一个自动的尾部斜杠重定向,一旦在应用程序设置中用尾部斜杠指定了正确的URL,就应该进行修复。

谢谢!你救了我一天!我在
https://mydomain/webhook/index.php
现在我可以阅读这些信息了