-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnotifyutils.py
More file actions
executable file
·43 lines (34 loc) · 1.09 KB
/
notifyutils.py
File metadata and controls
executable file
·43 lines (34 loc) · 1.09 KB
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
#! /usr/bin/python
"""
/******************************************************************************
pip install requests
******************************************************************************/
"""
import json
import time
import requests
import hashlib
import base64
import hmac
import config
import hashlib
import base64
import hmac
def gen_sign(timestamp, secret):
# 拼接timestamp和secret
string_to_sign = '{}\n{}'.format(timestamp, secret)
hmac_code = hmac.new(string_to_sign.encode("utf-8"), digestmod=hashlib.sha256).digest()
# 对结果进行base64处理
sign = base64.b64encode(hmac_code).decode('utf-8')
return sign
def send_notify(content):
timestamp = str(round(time.time()))
sign = gen_sign(timestamp, config.secret_string)
msg_type = "text"
at = '''<at user_id="all">所有人</at>'''
content = {"text": content + at}
msg = {"timestamp": timestamp, "sign": sign, "msg_type": msg_type, "content": content}
r = requests.post(config.url, data=json.dumps(msg))
return r
if __name__ == '__main__':
send_notify('价格提醒')