不要用电报中的URL + GET争论者创建键盘“inline_keyboard”

时间:2018-06-05 09:12:02

标签: php curl telegram telegram-bot php-telegram-bot

问题使用电报中的URL创建keyboard inline_keyboard 当我使用“&”时在地址网址中,keyboard没有创建电报?!!!!!!!

此代码有效:

$text = "server=164.132.117.18\nport=8585\nsecret=c53a3eae90544e68a37cbe41c5d31442";
$keyboard = array(
    'resize_keyboard' => true,
    'inline_keyboard' => array(
        array(
            array('text' => "Click for Connect", 'url' => "https://t.me/proxy?server=164.132.117.18port=8585secret=c53a3eae90544e68a37cbe41c5d31442")
        )
    )
);
$url = API_URL_KEY . "sendMessage?chat_id=" . CHAT_ID_USER . "&text=" . urlencode($text). "&reply_markup=" . json_encode($keyboard);
$ch = curl_init();
$optArray = array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
curl_exec($ch);
curl_close($ch);

但是,这段代码不起作用:

$text = "server=164.132.117.18\nport=8585\nsecret=c53a3eae90544e68a37cbe41c5d31442";
$keyboard = array(
    'resize_keyboard' => true,
    'inline_keyboard' => array(
        array(
            array('text' => "Click for Connect", 'url' => "https://t.me/proxy?server=164.132.117.18&port=8585&secret=c53a3eae90544e68a37cbe41c5d31442")
        )
    )
);
$url = API_URL_KEY . "sendMessage?chat_id=" . CHAT_ID_USER . "&text=" . urlencode($text). "&reply_markup=" . json_encode($keyboard);
$ch = curl_init();
$optArray = array(
    CURLOPT_URL => $url,
    CURLOPT_RETURNTRANSFER => true
);
curl_setopt_array($ch, $optArray);
curl_exec($ch);
curl_close($ch);

有没有人有解决方案?

1 个答案:

答案 0 :(得分:0)

尝试拨打您构建的网址时收到的错误代码为400 "Bad Request: can't parse reply keyboard markup JSON object"

尝试urlencode() $keyboard中找到的网址部分。

$keyboard = array(
    'resize_keyboard' => true,
    'inline_keyboard' => array(
        array(
            array('text' => "Click for Connect", 'url' => urlencode("https://t.me/proxy?server=164.132.117.18&port=8585&secret=c53a3eae90544e68a37cbe41c5d31442"))
        )
    )
);

这应该有用。