forked from chen310/NeteaseCloudMusicTasks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pushPlus.py
35 lines (28 loc) · 843 Bytes
/
pushPlus.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
# -*- coding: utf-8 -*-
import requests
import json
def getKey(data):
config = data['config']
if len(config['pushToken']) == 0:
return None
return (config['module'], config['pushToken'], config['topic'], config['template'])
def push(title, mdmsg, textmsg, config):
msg = mdmsg
token = config['pushToken']
topic = config['topic']
template = config['template']
if len(token) == 0:
return
url = 'http://www.pushplus.plus/send'
data = {
"token": token,
"title": title,
"content": msg
}
if len(topic) > 0:
data['topic'] = topic
if len(template) > 0:
data['template'] = template
body = json.dumps(data).encode(encoding='utf-8')
headers = {'Content-Type': 'application/json'}
requests.post(url, data=body, headers=headers)