Telegram 机器人 API 响应 403 Forbidden - 向机器人发送直接消息时
$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";
$data = [
'chat_id' => '5232750517',
'text' => 'Hello World'
];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .
http_build_query($data) );
错误信息
无法打开流:HTTP 请求失败! HTTP/1.1 403 禁止
然后我遵循这个解决方案 - Telegram bots API 响应 403 Forbidden
我的机器人用户名是@test247_bot 并将代码更改为:
$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";
$data = [
'chat_id' => '5232750517',
'text' => 'Hello World'
];
$response = file_get_contents("https://api.telegram.org/@test247_bot$apiToken/sendMessage?" .
http_build_query($data) );
但也没有工作,错误信息
无法打开流:HTTP 请求失败! HTTP/1.1 404
请帮忙
$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";
$data = [
'chat_id' => '5232750517',
'text' => 'Hello World'
];
$response = file_get_contents("https://api.telegram.org/bot$apiToken/sendMessage?" .
http_build_query($data) );
The error message
Failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
Then I am followed this solution - Telegram bots API responds 403 Forbidden
My bot username is @test247_bot and change the code to:
$apiToken = "5232750517:AAF7gbXCwZdfhSQeZZb53-2NhTm2xxNuT3U";
$data = [
'chat_id' => '5232750517',
'text' => 'Hello World'
];
$response = file_get_contents("https://api.telegram.org/@test247_bot$apiToken/sendMessage?" .
http_build_query($data) );
But also did not work, the error message
Failed to open stream: HTTP request failed! HTTP/1.1 404
Please help
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是构建URL的正确方法。
删除机器人的用户名。它只是“ bot”,然后是API令牌。
尝试:
That's not the correct way to build your URL.
Remove your bot's username. It is simply "bot" followed by api token instead.
Try: