Skip to content

Commit

Permalink
Merge pull request #1247 from weideguo/master
Browse files Browse the repository at this point in the history
发送企业微信消息带有url的优化 (#1244)
  • Loading branch information
hhyo committed Nov 25, 2021
2 parents b5d90df + eb326a5 commit e776988
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion common/utils/sendmsg.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# -*- coding: UTF-8 -*-

import re
import email
import smtplib
import requests
Expand Down Expand Up @@ -191,10 +192,18 @@ def send_wx2user(self, msg, user_list):
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.a.com)\n 的字符串被再次替换
if url.strip()[-1] != ")":
msg=msg.replace(url,'[请点击链接](%s)' % url)

data = {
"msgtype": "markdown",
"markdown": {
"content": msg.replace('工单地址:', '工单地址:[请点击链接](').replace('\n工单详情预览:', ')\n工单详情预览:')
"content": msg
},
}
res = requests.post(url=send_url, json=data, timeout=5)
Expand Down

0 comments on commit e776988

Please sign in to comment.