【问题标题】:Telegram Bot 'sendMessage' method isn't sending some stringsTelegram Bot 'sendMessage' 方法没有发送一些字符串
【发布时间】:2015-11-19 11:33:17
【问题描述】:

我遇到了一个我实际上不知道如何解决的问题。我正在使用 webhook 和我安装在我的 VPS 中的 PHP 服务器来玩电报的机器人 API。我有这段代码(因此,当有人与机器人聊天时,它会发送 $reply 字符串):

$reply = 'Marco Fu 0 - 0 Michael Holt';

// send reply
if(!empty($text)){
    $sendMessage =API_URL."sendmessage?chat_id=".$chatID."&text=".$reply;//."&parse_mode=Markdown&disable_web_page_preview=true";
    file_get_contents($sendMessage);
}

但是,我不知道为什么,当我发送那个特定的字符串并与机器人聊天时,它没有回复我。 (它应该用那个字符串回复我)

但是,如果我将字符串更改为marco fu 0 - 0 michael holt(所有字母均为小写),机器人会回复该字符串!这就像 enconding 问题或类似的问题,但我无法检测到确切的问题。

有什么想法吗?

谢谢!

【问题讨论】:

    标签: php telegram-bot


    【解决方案1】:

    我怀疑这是因为您没有对查询字符串进行编码。试试这个:

    $sendMessage =API_URL."sendmessage?chat_id=".$chatID."&text=".urlencode($reply);
    

    【讨论】:

    • 太棒了,这似乎解决了问题。非常感谢你,尼克!
    • 很高兴为您提供帮助。祝你好运。
    猜你喜欢
    • 2017-05-12
    • 2021-11-02
    • 1970-01-01
    • 2019-03-09
    • 1970-01-01
    • 2015-11-26
    • 1970-01-01
    • 2021-09-14
    • 2020-06-10
    相关资源
    最近更新 更多