1

我正在使用 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

4

1 回答 1

0

您可以通过以下方法找出问题:

检查getWebhookInfo方法,确保您的 webhook URL 正确,并且没有last_error_message字段。

将类似的数据发布到您的服务器,这里有一些您可以使用的数据curl -d JSON,只需将其复制并在您自己的服务器上运行即可。

最后,检查您的 CDN 配置(如果您已在该服务器上应用),暂时禁用泛洪或任何检查。

于 2017-06-26T08:50:29.860 回答