forked from ihmily/DouyinLiveRecorder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
msg_push.py
64 lines (55 loc) · 1.82 KB
/
msg_push.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
53
54
55
56
57
58
59
60
61
62
63
64
"""
Author: Hmily
Github:https://github.com/ihmily
Date: 2023-09-03 19:18:36
Copyright (c) 2023 by Hmily, All Rights Reserved.
"""
import json
import urllib.request
no_proxy_handler = urllib.request.ProxyHandler({})
opener = urllib.request.build_opener(no_proxy_handler)
headers = {
'Content-Type': 'application/json',
}
def dingtalk(url, content, phone_number=''):
json_data = {
'msgtype': 'text',
'text': {
'content': '直播间状态更新:\n' + content,
},
"at": {
"atMobiles": [
phone_number # 添加这个手机号,可以被@通知(必须要在群里)
],
# "atUserIds": [
# "user123"
# ],
# "isAtAll": False
},
}
data = json.dumps(json_data).encode('utf-8')
req = urllib.request.Request(url, data=data, headers=headers)
response = opener.open(req, timeout=10)
html_str = response.read().decode('utf-8')
# print(html_str)
return html_str
def xizhi(url, content):
json_data = {
'title': '直播间状态更新',
'content': content
}
data = json.dumps(json_data).encode('utf-8')
req = urllib.request.Request(url, data=data, headers=headers)
response = opener.open(req, timeout=10)
html_str = response.read().decode('utf-8')
# print(html_str)
return html_str
if __name__ == '__main__':
content = '张三 开播了!' # 推送内容
phone_number = '' # 被@用户的手机号码
# 替换成自己Webhook链接,参考文档:https://open.dingtalk.com/document/robots/custom-robot-access
webhook_api = ''
# dingtalk(webhook_api,content,phone_number)
# 替换成自己的单点推送接口,获取地址:https://xz.qqoq.net/#/admin/one
xizhi_api = ''
# xizhi(xizhi_api,content)