【发布时间】:2017-06-26 04:30:19
【问题描述】:
我正在使用 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") ;
?>
换句话说,我将 \getupdates 更改为 "php://input" 。它没有没有工作。
我想谷歌应用程序引擎可能不会自动签署其 ssl 证书,这可能就是 webhook 不起作用的原因。
任何帮助将不胜感激。
编辑:为了回应下面的答案/评论,我尝试了 getWebhookinfo 方法并得到了
"url:"https://my_url.com","has_custom_certificate":false, "pending_update_count":0, "max_connections":40
【问题讨论】:
-
您可以使用
/webhookinfo方法获取更多信息。请发布此结果。 -
@creyD 所以这给出了一个 "url:"https.url" ,"has_custom_certificate":false, "pending_update_count":0, "max_connections":40
-
是的,网址不正确。您必须使用
/setwebhook方法对此进行调整。示例:/setwebhook?url=https://www.google.de记录在 here。 -
@creyD 不,我故意用愚蠢的“https:url”替换了我的实际网址;但是, "has_custom_certificate":false 声明似乎暗示它还没有 ssl 证书。我试图找到如何从谷歌应用引擎获取 ssl 证书但失败了。
-
不,
has_custom_certificate = false没问题,与 SSL 无关。但是,是的,您需要一个 https 地址,否则它无法正常工作。我猜你已经尝试过this..
标签: php google-app-engine ssl-certificate telegram-bot php-telegram-bot