我正在使用 Google Cloudshell 平台创建一个经过 ssl 认证的 url 来托管 webhook。所以我最初开始使用 getupdates 来查找 chat_id 并发送机器人消息。以下代码旨在获取用户的聊天 ID,然后给他发短信 "text" ,工作正常。
<?php
$botToken = "insert bot token" ;
$website = "https://api.telegram.org/bot".$botToken ;
$update = file_get_contents($website."\getupdates");
$updateArray = json_decode($update, TRUE) ;
$chatId = $updateArray["result"][0]["message"]["chat"]["id"] ;
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=test") ;
?>
然后我使用 setwebhook 设置了一个 webhook 并修改了上面的代码。
<?php
$botToken = "insert bot token" ;
$website = "https://api.telegram.org/bot".$botToken ;
$update = file_get_contents("php://input");
$updateArray = json_decode($update, TRUE) ;
$chatId = $updateArray["result"][0]["message"]["chat"]["id"] ;
file_get_contents($website."/sendmessage?chat_id=".$chatId."&text=test") ;
?>
换句话说,我用 "php://input" 更改了 \getupdates。它没有用。
我想谷歌应用引擎可能不会自动签署其 ssl 证书,这可能就是 webhook 不起作用的原因。
任何帮助将不胜感激。
编辑: 为了回应下面的答案/评论,我尝试了 getWebhookinfo 方法并得到了
"url:" https://my_url.com " ,"has_custom_certificate":false, "pending_update_count":0, "max_connections":40