我正在使用Google Cloudshell平台创建一个ssl认证的网址来托管webhook。所以我最初开始使用getupdates来查找chat_id并发送bot信息。下面的代码旨在获取用户的聊天ID,然后将其文本“文本”,可以正常工作。电报setwebhook没有收到更新
<?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“:假的, ”pending_update_count“:0, ”MAX_CONNECTIONS“ :40
您可以使用'/ webhookinfo'方法获取更多信息。请张贴这个结果。 – creyD
@creyD所以这给了一个“url:”https.url“,”has_custom_certificate“:false,”pending_update_count“:0,”max_connections“:40 – rah4927
是的,url不对,你必须用'/setwebhook'方法。例如:'/ setwebhook?url = https:// www.google.de'记录在[这里](https://core.telegram.org/bots/api#setwebhook)。 – creyD