Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ 功能建议 ]发送企业微信消息带有url的优化 #1244

Closed
weideguo opened this issue Nov 23, 2021 · 1 comment
Closed

[ 功能建议 ]发送企业微信消息带有url的优化 #1244

weideguo opened this issue Nov 23, 2021 · 1 comment

Comments

@weideguo
Copy link
Collaborator

目前遇到的问题/使用障碍

发送企业微信消息时对url的处理不够优雅,尤其是对提交人主动终止工单处理有误

希望如何解决/实现它

补丁 sendmsg.py.20211124.patch

diff --git a/common/utils/sendmsg.py b/common/utils/sendmsg.py
index 8add6b7..7aace1d 100755
--- a/common/utils/sendmsg.py
+++ b/common/utils/sendmsg.py
@@ -1,5 +1,6 @@
 # -*- coding: UTF-8 -*-
 
+import re
 import email
 import smtplib
 import requests
@@ -191,10 +192,19 @@ class MsgSender(object):
     def send_qywx_webhook(self,qywx_webhook, msg):
 
         send_url = qywx_webhook
+
+        # 对链接进行转换
+        _msg = re.findall('https://.+(?=\n)|http://.+(?=\n)', msg)
+        for url in _msg:
+            # 防止如 [xxx](http://www.baidu.com)\n 的字符串被再次替换
+            if url.strip()[-1] != ")":
+                msg=msg.replace(url,'[请点击链接](%s)' % url)
+                
         data = {
             "msgtype": "markdown",
             "markdown": {
-                "content": msg.replace('工单地址:', '工单地址:[请点击链接](').replace('\n工单详情预览:', ')\n工单详情预览:')
+                # "content": msg.replace('工单地址:', '工单地址:[请点击链接](').replace('\n工单详情预览:', ')\n工单详情预览:')
+                "content": msg
             },
         }
         res = requests.post(url=send_url, json=data, timeout=5)

应用补丁
patch -p1 < sendmsg.py.20211124.patch

@LeoQuote
Copy link
Collaborator

你好, 请直接提交pr

weideguo added a commit to weideguo/Archery that referenced this issue Nov 24, 2021
weideguo added a commit to weideguo/Archery that referenced this issue Nov 24, 2021
hhyo added a commit that referenced this issue Nov 25, 2021
发送企业微信消息带有url的优化 (#1244)
@hhyo hhyo closed this as completed Jan 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants