-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwx_pusher.py
52 lines (46 loc) · 1.95 KB
/
wx_pusher.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import json
import requests
import sender
from msg_sender import MsgSender
class WxPusher(MsgSender):
"""
微信推送服务
接口文档:http://wxpusher.dingliqc.com/#part-1
支持一对多推送
支持HTML语法
"""
def __init__(self):
pass
def send_msg(self, to_user=None, title=None, content=None, **kwargs):
"""
WxPusher发送文本消息
:param to_user: 接收用户的ID,多个用户ID请用英文半角逗号分隔开。就是关注号,发送给你的那个ID。
:param title: 标题
:param content: 内容
:param kwargs: 消息携带的url,在微信里面点击可以直接打开这个url。为空会自动补充一个消息详情的链接,点击可以在网页中查看消息,方便复制。为了部分强迫症用户,可以传"nourl",这样就不会携带默认的url。
:return:
"""
if to_user is None:
to_user = sender.config.get_config('ids', 'wx_pusher')
if content is None:
content = title
url = "http://wxmsg.dingliqc.com/send"
detail_url = kwargs['url'] if 'url' in kwargs else 'nourl'
querystring = {"title": title, "msg": content, "userIds": to_user, "url": detail_url}
headers = {
'User-Agent': "PostmanRuntime/7.16.3",
'Accept': "*/*",
'Cache-Control': "no-cache",
'Postman-Token': "96cfdeea-dc0c-491f-9804-7c5a0f5133b5,cd30bd5f-c1f1-4308-82fd-319b3a0997bf",
'Host': "wxmsg.dingliqc.com",
'Accept-Encoding': "gzip, deflate",
'Connection': "keep-alive",
'cache-control': "no-cache"
}
response = requests.request("GET", url, headers=headers, params=querystring)
result = json.loads(response.text)
code = result['code']
if code != 200:
print("Wx Pusher Err - response[%s]" % response.text)
return False
return True