-2

我想创建一个电报机器人,我写了这个代码,我还设置了 Webhook,这个代码将电报机器人的 Json 响应返回给它自己,但我不知道为什么它不工作.. 任何帮助和指南都会受到赞赏。

$token = 'my token';
// read incoming info and grab the chatID 
$json = file_get_contents('php://input');
$telegram = urldecode ($json);
$results = json_decode($telegram); 




// send reply
$url = 'https://api.telegram.org/bot'.$token.'/sendMessage?chat_id=80853440&text='.$json;
 file_get_contents($url);
4

1 回答 1

0

GET 请求是有限的。尝试使用 curl 进行 POST 请求或编写包含 chat_id 的数组,...
然后使用

$arrayname["method"] = "sendMessage"; //Req method for example sendMessage
echo json_encode($arrayname);

请阅读Telegram Apiphp.net了解更多信息。

于 2017-05-29T17:58:44.777 回答