如何正确运行这个php电报机器人代码? [关闭]

问题描述 投票:-5回答:1

我有一些纯PHP代码在Telegram中启动机器人:

<?php
const TOKEN = "<some token>";

$url = "https://api.telegram.org/bot" . TOKEN . '/getUpdates';

$response = json_decode(file_get_contents($url), JSON_OBJECT_AS_ARRAY);
// echo $response;
// var_dump($response);

$lastUpdateId = 934084308;

$params = [
    'offset' => $lastUpdateId + 1
];

$output = $url . '?' . http_build_query[$params];

echo $output;

if ($response['ok']) {
    foreach ($response['result'] as $update) {
        echo $update['message']['text'];
    }
}

我得到的错误如下:

警告:使用未定义的常量http_build_query - 在第20行的C:\ xampp \ htdocs \ php \ test_bot \ bot.php中假定为'http_build_query'(这将在未来的PHP版本中引发错误)

警告:第20行https://api.telegram.org/bot756467164:AAFXMfZI1N6OBQ-dCiPRAFpE7pOd-i1spTg/getUpdates?t/starthi!Im上的C:\ xampp \ htdocs \ php \ test_bot \ bot.php中的非法偏移类型

当我研究http_build_query函数并且没有看到任何错误时,我的代码有什么问题?

php telegram-bot
1个回答
1
投票

更改

http_build_query[$params];

http_build_query($params);

© www.soinside.com 2019 - 2024. All rights reserved.