diff --git a/app/sage.py b/app/sage.py index b76833d..6caf392 100644 --- a/app/sage.py +++ b/app/sage.py @@ -36,9 +36,28 @@ __version__ = '0.0.1' async def run_zmq_proxy(app): task = asyncio.create_task(run_proxy()) app['zmq_proxy_task'] = task + task1 = asyncio.create_task(woa_msghande) yield + task1.cancel() task.cancel() + +async def woa_msghande(): + config = getConfig() + while True: + msgstr = await zmq_subscribe(config.woa_handler_id) + msgdic = json.loads(msgstr) + # 这里按照业务逻辑处理收到的msg + debug(f'received wechat msgs={msgstr}') + # 处理完成后 + retmsg = { + "msgtype": "text", # 要返回的消息类型 + “content": "收到" # 每个类型的消息所需要的数据 + } + retstr = json.dumps(retmsg, ensure_ascii=False) + debug(f'repy msg({retstr}) to wechat') + await zmq_publish(msgdic['subscribe_id'], retstr) + def init(): rf = RegisterFunction() set_globalvariable() diff --git a/conf/config.json b/conf/config.json index 1c59e5a..344f71f 100755 --- a/conf/config.json +++ b/conf/config.json @@ -1,7 +1,7 @@ { "password_key":"!@#$%^&*(*&^%$QWERTYUIqwertyui234567", "logopath": "$[workdir]$/conf/logo.png", - "subscrible_id":"woa_subscribe_type", + "woa_handler_id":"woa_subscribe_type", "logger":{ "name":"sage", "levelname":"clientinfo",