-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.py
45 lines (35 loc) · 1.14 KB
/
main.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
from bot import mybot
from werobot.contrib.flask import make_view
from flask import Flask,request,abort,send_file
import hashlib
import config as cfg
app = Flask(__name__)
app.add_url_rule(rule='/', # WeRoBot 挂载地址
endpoint='werobot', # Flask 的 endpoint
view_func=make_view(mybot),
methods=['GET', 'POST'])
@app.route('/',methods=['GET','POST'])
def wechat():
'''对接微信公众号'''
signature = request.args.get("signature")
timestamp = request.args.get("timestamp")
nonce = request.args.get("nonce")
echostr = request.args.get("echostr")
if not all([signature, timestamp, nonce]):
abort(400)
li = [cfg.token, timestamp, nonce]
li.sort()
tmp_str = "".join(li).encode('utf-8')
sign = hashlib.sha1(tmp_str).hexdigest()
if signature != sign:
abort(403)
else:
return echostr
@app.route('/hello/')
def hello():
return '<h1>欢迎来到系统之美</h1>'
@app.route('/favicon.ico')
def favicon():
return send_file('favicon.ico', mimetype='image/vnd.microsoft.icon')
if(__name__=="__main__"):
app.run()