Skip to content

Commit cec81fd

Browse files
committed
wechat01
1 parent 936b39b commit cec81fd

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

wechat/connect.py

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import falcon
2+
from wechatpy.utils import check_signature
3+
from wechatpy.exceptions import InvalidSignatureException
4+
from wechatpy import parse_message
5+
from wechatpy.replies import TextReply, ImageReply
6+
7+
8+
class Connect(object):
9+
10+
def on_get(self, req, resp):
11+
query_string = req.query_string
12+
query_list = query_string.split('&')
13+
b = {}
14+
for i in query_list:
15+
b[i.split('=')[0]] = i.split('=')[1]
16+
17+
try:
18+
check_signature(token='lengxiao', signature=b['signature'], timestamp=b['timestamp'], nonce=b['nonce'])
19+
resp.body = (b['echostr'])
20+
except InvalidSignatureException:
21+
pass
22+
resp.status = falcon.HTTP_200
23+
24+
def on_post(self, req, resp):
25+
xml = req.stream.read()
26+
msg = parse_message(xml)
27+
if msg.type == 'text':
28+
reply = TextReply(content=msg.content, message=msg)
29+
xml = reply.render()
30+
resp.body = (xml)
31+
resp.status = falcon.HTTP_200
32+
elif msg.type == 'image':
33+
reply = ImageReply(media_id=msg.media_id, message=msg)
34+
xml = reply.render()
35+
resp.body = (xml)
36+
resp.status = falcon.HTTP_200
37+
38+
39+
app = falcon.API()
40+
connect = Connect()
41+
app.add_route('/connect', connect)
42+

wechat/requirements.txt

498 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)