Telegram Bot内联查询 - 要查询的数组是什么?

时间:2016-01-19 08:17:41

标签: php telegram-bot

我在PHP中使用Telegram内联查询答案时遇到问题。 我使用此代码:

班级职能:

public function answerInlineQuery($inline_query_id, $results, $cache_time = null, $is_personal = false, $next_offset = null){
    $param = compact('inline_query_id', 'results', 'cache_time', 'is_personal', 'next_offset');
    return $this->sendRequest('answerInlineQuery', $param);
}

public function InlineQueryResultArticle($id, $title, $message_text, $parse_mode = null, $disable_web_page_preview = false, $url = null, $hide_url = false, $description = null, $thumb_url = null, $thumb_width = null, $thumb_height = null)
{
    $type = "article";
    $params = compact("type", "id", "title", "message_text", "parse_mode", "disable_web_page_preview", "url", "hide_url", "description", "thumb_url",
                      "thumb_width", "thumb_height");
    return json_encode($params);
}

private function sendRequest($method, $params)
{
    return json_decode(file_get_contents($this->baseURL . $method . '?' . http_build_query($params)), true);
}

bot.php 文件:

$t = new telegramBot("##########################");

$data = json_decode($_REQUEST['salam'], true);

//$_REQUEST['salam'] => This method is not the problem and returns JSON that is receive from the telegram server


$id1 = $t->InlineQueryResultArticle($data['inline_query']['id'], "onvan1111", "TeXte Message1");
$id2 = $t->InlineQueryResultArticle($data['inline_query']['id'], "onvan2222", "TeXte Message2", null, false, "http://icons.iconarchive.com/icons/custom-icon-design/flatastic-6/512/Horizontal-type-mask-Tool-icon.png", false, "short");
$id3 = $t->InlineQueryResultArticle($data['inline_query']['id'], "onvan3333", "TeXte Message3");


$res = array($id1,$id2,$id3);

$t->answerInlineQuery($data['inline_query']['id'], $res);

当我在我的机器人中发送内联查询时,我从PHP获取此日志:

<b>Warning</b>:  file_get_contents(https://api.telegram.org/bot#################/answerInlineQuery?inline_query_id=297302915958357271&amp;results=%5B%7B%22type%22%3A%22article%22%2C%22id%22%3A%22297302915958357271%2F0%22%2C%22title%22%3A%22onvan1111%22%2C%22message_text%22%3A%22TeXte+Message1%22%2C%22parse_mode%22%3Anull%2C%22disable_web_page_preview%22%3Afalse%2C%22url%22%3Anull%2C%22hide_url%22%3Afalse%2C%22description%22%3Anull%2C%22thumb_url%22%3Anull%2C%22thumb_width%22%3Anull%2C%22thumb_height%22%3Anull%7D%5D&amp;is_personal=0): failed to open stream: HTTP request failed! HTTP/1.1 400 Bad Request

我的代码在哪里有问题?

1 个答案:

答案 0 :(得分:1)

我找到了代码problam: InlineQueryResultArticle函数的结果 json $res在这一行:

$t->answerInlineQuery($data['inline_query']['id'], $res);

大多数是 json 编码:)