Php 如何使用URL创建答案内联查询
如何使用URL创建AnswerInlineQuery?我找不到该查询的更多详细信息,所有示例代码都是关于TelegramSDK的,我需要这样编码(URL帖子,而不是类) 我试过这个:Php 如何使用URL创建答案内联查询,php,bots,telegram,Php,Bots,Telegram,如何使用URL创建AnswerInlineQuery?我找不到该查询的更多详细信息,所有示例代码都是关于TelegramSDK的,我需要这样编码(URL帖子,而不是类) 我试过这个: $data = array(); $data['inline_query_id']= $inline_query_id;//sample : 1515027006022511114 $data['results']='[ { "type": "article", "id": "001",
$data = array();
$data['inline_query_id']= $inline_query_id;//sample : 1515027006022511114
$data['results']='[
{
"type": "article",
"id": "001",
"title": "UC Browser",
"message_text": "Text of the first message",
"parse_mode": "Markdown",
"disable_web_page_preview": true,
"url": "telegram.com",
"hide_url": true,
"description": "Optional. Short description of the result",
"thumb_url": "http://icons.iconarchive.com/icons/martz90/circle/64/uc-browser-icon.png",
"thumb_width": 64,
"thumb_height": 64
},
{
"type": "article",
"id": "002",
"title": "Bitcoin",
"message_text": "*Text of the second message*",
"parse_mode": "Markdown",
"disable_web_page_preview": true,
"url": "bitcoin.org",
"hide_url": true,
"description": "Short description of the result",
"thumb_url": "http://www.coinwarz.com/content/images/bitcoin-64x64.png",
"thumb_width": 64,
"thumb_height": 64
}
]';
$ch = curl_init();
$curlConfig = array(
CURLOPT_URL => 'https://api.telegram.org/bot' . TOKEN . '/answerInlineQuery',
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SAFE_UPLOAD => true,
CURLOPT_POSTFIELDS => 'params=' . json_encode($data),
CURLOPT_VERBOSE => true,
);
curl_setopt_array($ch, $curlConfig);
$result = curl_exec($ch);
curl_close($ch);
但结果是:
Result : {"ok":false,"error_code":400,"description":"Bad Request: QUERY_ID_INVALID"}
我也试过这个:
$mResult = '[
{
"type": "article",
"id": "001",
"title": "UC Browser",
"message_text": "Text of the first message",
"parse_mode": "Markdown",
"disable_web_page_preview": true,
"url": "telegram.com",
"hide_url": true,
"description": "Optional. Short description of the result",
"thumb_url": "http://icons.iconarchive.com/icons/martz90/circle/64/uc-browser-icon.png",
"thumb_width": 64,
"thumb_height": 64
},
{
"type": "article",
"id": "002",
"title": "Bitcoin",
"message_text": "*Text of the second message*",
"parse_mode": "Markdown",
"disable_web_page_preview": true,
"url": "bitcoin.org",
"hide_url": true,
"description": "Short description of the result",
"thumb_url": "http://www.coinwarz.com/content/images/bitcoin-64x64.png",
"thumb_width": 64,
"thumb_height": 64
}
]';
$url= "https://api.telegram.org/bot" . TOKEN . "/answerInlineQuery?inline_query_id=" . $inline_query_id . "&results=" . json_encode($mResult);
file_get_contents($url);
这将返回:
Result : {"ok":false,"error_code":400,"description":"Bad Request: QUERY_ID_INVALID"}
试试这个:
$mResult = [
[
"type" => "article",
"id" => "first",
"title" => "Hey",
"input_message_content" => ["message_text" => "Hello World"],
"parse_mode" => "Markdown",
]
];
$url= "https://api.telegram.org/bot" . TOKEN . "/answerInlineQuery?inline_query_id={$inline_query_id}&results=" . json_encode($mResult);
file_get_contents($url);
只是对上面给出的答案进行了更新,中有一点更改,没有名为
消息\文本
的字段,现在称为输入消息\内容
所以你可以试试这个
$inlineResult = [
[
"type" => "article",
"id" => rand(1, 100), //this has to be unique for each response
"title" => "TITLE",
"input_message_content" => [
"message_text" => "*Hello World*",
"parse_mode" => "Markdown",
],
] ];
$url= "https://api.telegram.org/bot" . TOKEN . "/answerInlineQuery?inline_query_id={$inline_query_id}&results=" . json_encode($inlineResult);
file_get_contents($url);