2

我是 Telegram 的新手,我正在尝试用它迈出第一步。

我在这里找到了一个很好的教程https://www.youtube.com/watch?v=hJBYojK7DO4:我已经使用 PHP 和 SSL 配置了我的 Apache 2.4 并且一切正常,教程中的示例也是如此。

麻烦正在使用 setWebhook 方法....当我尝试放入浏览器时

https://api.telegram.org/<my_bot_code>/setWebHook?url=https://localhost/Telegram/MyYouTubeTutorialBot/YouTubeTutorialBot.php

回应是

{"ok":false,"error_code":400,"description":"Error: Bad webhook: Error: Ip is reserved"}

请注意,我使用的是自行生成的证书....

我在 api Telegram 文档(参考https://core.telegram.org/bots/faq#i-39m-having-problems-with-webhooks)中发现,

..... 要使用自签名证书,您需要使用 setWebhook 中的证书参数上传您的公钥证书。请作为 InputFile 上传,发送字符串将不起作用。

我不明白如何上传我的公钥证书文件....有什么例子吗?

问题可能是因为我使用localhost和本地 Apache的默认 IP 地址127.0.0.1 ?我是否应该使用每次连接到网络时都会更改的当前 IP 地址来更改我的 IP 地址(我正在使用互联网密钥将我连接到网络.....)?

非常感谢您提前

4

3 回答 3

8

使用以下简单的 html 代码

<html>
<body>

<form action="https://api.telegram.org/bot<BOT_TOCKEN>/setwebhook" method="post" enctype="multipart/form-data">
    Select Certificate to upload:
    <input type="file" name="certificate" id="fileToUpload">
	URL: <input type="text" name="url"  value="https://<YOURWEBSITE>/<YOUR_PHP_URL>"><br>
    <input type="submit" value="Upload Certificate" name="submit">
</form>

</body>
</html>

于 2017-02-21T18:16:59.563 回答
6

您的本地机器无法通过 Internet 访问,localhost或者您的本地 IP ( 127.0.0.1) 或本地网络 IP ( 192.168.1.2)
每台机器都有自己的localhost,因此电报的服务器 localhost 与您的不同,您
应该使用 aweb hostingVPS运行您的脚本并使用
我知道的地址一个免费的开发者VPS:heroku

于 2016-05-05T07:10:26.830 回答
2

以下库可让您轻松做到这一点(并快速设置机器人):

https://github.com/auino/php-telegram-bot-library

它本质上调用 Telegram 的setWebhook函数/页面,通过POST请求将自签名证书作为文件传递:

$data = array("url"=>$YOURCALLBACKURL,"certificate"=>"@$CERTIFICATEFILE");
$telegramurl = "https://api.telegram.org/bot$TOKEN/setWebhook";
// now you have to make a request on $telegramurl passing $data via POST (e.g. using curl library)

如果要使用php-telegram-bot-library,可以通过 install.php 文件轻松设置,或者使用以下代码(适用于 Linux,也应适用于 Windows 系统):

$bot = new telegram_bot($TOKEN);
$bot->set_webhook($WEBHOOKURL, $SSLCERTIFICATEFILE);
于 2015-10-31T11:07:08.307 回答