1

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

+0

您可以使用'/ webhookinfo'方法获取更多信息。请张贴这个结果。 – creyD

+0

@creyD所以这给了一个“url:”https.url“,”has_custom_certificate“:false,”pending_update_count“:0,”max_connections“:40 – rah4927

+0

是的,url不对,你必须用'/setwebhook'方法。例如:'/ setwebhook?url = https:// www.google.de'记录在[这里](https://core.telegram.org/bots/api#setwebhook)。 – creyD

回答

0

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

检查getWebhookInfo方法,确保您的网络挂接网址是正确的,并没有last_error_message

0。

向您的服务器发送类似数据,here是一些数据,您可以在curl -d JSON中使用,只需将其复制并在您自己的服务器上运行即可。

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

+0

谢谢你的回答。 getWebhookInfo产生“url:”https.url“,”has_custom_certificate“:false,”pending_update_count“:0,”max_connections“:40 – rah4927

+0

问题,我相信是,与app引擎的app.yaml文件,我需要添加在一个安全的参数。 – rah4927