V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
v6dp
V2EX  ›  Telegram

Telegram 发送消息 url 转义问题

  •  
  •   v6dp · 2018-06-09 17:59:31 +08:00 · 4932 次点击
    这是一个创建于 2119 天前的主题,其中的信息可能已经有所发展或是发生改变。

    情况是这样的: 使用 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 条回复    2018-06-09 19:42:57 +08:00
    Daniel65536
        1
    Daniel65536  
       2018-06-09 19:20:09 +08:00 via iPhone
    所以,你不会把%也转义了么……
    v6dp
        2
    v6dp  
    OP
       2018-06-09 19:27:33 +08:00
    @Daniel65536 抱歉,没有理解你的意思。能不能说得详细点。Telegram bot sendMessage 发送的 text 是连续的完整的可点击的链接,在 curl -X POST 后被自动替换了,你的意思是?求教。
    Daniel65536
        3
    Daniel65536  
       2018-06-09 19:32:04 +08:00 via iPhone
    % = %25
    %26 = %25%26
    Daniel65536
        4
    Daniel65536  
       2018-06-09 19:34:44 +08:00 via iPhone   ❤️ 1
    啊,是%2526 来着
    v6dp
        5
    v6dp  
    OP
       2018-06-09 19:42:57 +08:00
    @Daniel65536 感谢,接下来就是写个脚本进行自动替换了,比如链接中有空格或者加号,将其替换成 `%2520` ,有 `%` 将其替换成 `%25`。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3330 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 13:43 · PVG 21:43 · LAX 06:43 · JFK 09:43
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.