PHP://输入为空

时间:2017-02-05 18:01:13

标签: php bots telegram telegram-bot php-telegram-bot

我正在搞乱使用hook.io来编写一个自己的telegramm机器人来托管php脚本。我遇到的问题是file_get_contents(“php:// input”)似乎总是空的,因为如果我尝试做与更新有关的任何事情,机器人不会做出反应:

$updates = json_decode(file_get_contents('php://input') ,true);

if($updates['ok']){

  //loop over all messages
  foreach($updates['result'] as $key => $value){
     if($value['message']['text']==="/test"){
       $chat_id =   $value['message']['chat']['id'];
       $result = file_get_contents( $apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test');
     }
  }

}

有人能说出这个错误吗?

1 个答案:

答案 0 :(得分:2)

我用这种方式纠正了:

$updates = json_decode(file_get_contents('php://input') ,true);

if($updates['update_id']){

 if($updates['message']['text']==="/test"){
   $chat_id =   $updates['message']['chat']['id'];
   $result = file_get_contents( $apiURL . $apiToken . '/sendMessage?chat_id=' . $chat_id . '&text=test');
 }
}

消息总是一个,所以我删除了foreach