【问题标题】:PHP://Input is EmptyPHP://输入为空
【发布时间】:2017-06-22 15:55:53
【问题描述】:

我正在使用 hook.io 为电报编写一个自己的机器人来托管 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');
     }
  }

}

谁能告诉我这个有什么问题?

【问题讨论】:

  • 你想在你的后端做 POST 吗?如果不是电报的查询 php://input 还是空的?

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


【解决方案1】:

我是这样改正的:

$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

【讨论】:

  • 谢谢,我没想到。我还发现 Hook.io 删除了 'php:\\input' 的内容并将它们粘贴到 $Hook 数组中。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-02
  • 2023-03-08
  • 2021-11-21
  • 2022-06-16
  • 2016-08-10
相关资源
最近更新 更多