This commit is contained in:
injetlee
2018-06-16 18:28:43 +08:00
parent 3568adb2e4
commit a5b61ddcfd
6 changed files with 197 additions and 3 deletions

View File

@@ -1,9 +1,13 @@
import falcon
from falcon import uri
from wechatpy.utils import check_signature
from wechatpy.exceptions import InvalidSignatureException
from wechatpy import parse_message
from wechatpy.replies import TextReply, ImageReply
from utils import img_download, img_upload
from face_id import access_api
class Connect(object):
@@ -25,18 +29,24 @@ class Connect(object):
xml = req.stream.read()
msg = parse_message(xml)
if msg.type == 'text':
print('hello')
reply = TextReply(content=msg.content, message=msg)
xml = reply.render()
resp.body = (xml)
resp.status = falcon.HTTP_200
elif msg.type == 'image':
reply = ImageReply(media_id=msg.media_id, message=msg)
name = img_download(msg.image, msg.source) # 下载图片
print(name)
r = access_api('images/' + name)
if r == '检测成功':
media_id = img_upload('image', 'faces/' + name) # 上传图片,得到 media_id
reply = ImageReply(media_id=media_id, message=msg)
else:
reply = TextReply(content='人脸检测失败请上传1M以下人脸清晰的照片', message=msg)
xml = reply.render()
resp.body = (xml)
resp.status = falcon.HTTP_200
app = falcon.API()
connect = Connect()
app.add_route('/connect', connect)