v6dp
V2EX  ›  Telegram

Telegram 发送消息 url 转义问题

  •  
  •   v6dp · Jun 9, 2018 · 6359 views
    This topic created in 3073 days ago, the information mentioned may be changed or developed.

    情况是这样的: 使用 curl -X POST,然后 Telegram Bot 给 Channel 发消息

    curl -X POST "https://api.telegram.org/bot<API Token>/sendMessage" -d "chat_id=<Chat ID>&disable_notification=true&text=https://www.netxautomation.com:8443/display/BMS20/HTTP2%3A+Using+the+HTTP+module+to+send+Telegram+messages"
    

    但是 Channel 那边收到的是

    https://www.netxautomation.com:8443/display/BMS20/HTTP2: Using the HTTP module to send Telegram messages
    

    而不是

    https://www.netxautomation.com:8443/display/BMS20/HTTP2%3A+Using+the+HTTP+module+to+send+Telegram+messages
    

    相当于它把 %3A 替换成了 :,把 + 替换成了 (空格)
    这就导致了你在 Channel 中无法直接点链接,因为它已经不是一个完整的可点击的链接了。
    搜 Goole 搜了好长时间,没有找到解决方法,不知道大家有没有类似问题的解决经验,求教。

    5 replies  •  2018-06-09 19:42:57 +08:00
    Daniel65536
    Daniel65536
    Jun 9, 2018 via iPhone
    1
    所以,你不会把%也转义了么……
    v6dp
    v6dp
    OP
    Jun 9, 2018
    2
    @Daniel65536 抱歉,没有理解你的意思。能不能说得详细点。Telegram bot sendMessage 发送的 text 是连续的完整的可点击的链接,在 curl -X POST 后被自动替换了,你的意思是?求教。
    Daniel65536
    Daniel65536
    Jun 9, 2018 via iPhone
    3
    % = %25
    %26 = %25%26
    Daniel65536
    Daniel65536
    Jun 9, 2018 via iPhone❤️1
    4
    啊,是%2526 来着
    v6dp
    v6dp
    OP
    Jun 9, 2018
    5
    @Daniel65536 感谢,接下来就是写个脚本进行自动替换了,比如链接中有空格或者加号,将其替换成 `%2520` ,有 `%` 将其替换成 `%25`。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   1497 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 01:21 · PVG 09:21 · LAX 17:21 · JFK 20:21
    ♥ Do have faith in what you're doing.