diff --git a/README.md b/README.md index 734c984..87e09e8 100644 --- a/README.md +++ b/README.md @@ -89,4 +89,25 @@ 返回消息有以下属性 +## 消息处理的例子 +``` +import asyncio +from appPublic.jsonConfig import getConfig +from appPublic.zmqapi import zmq_publish, zmq_subscribe +import json + +async def woa_msghandle(): + config = getConfig() + config.woa_handler_id + while True: + msgstr = await zmq_subscribe(config.woa_handler_id) + msgdic = json.loads(msgstr) + # 这里按照业务逻辑处理收到的msg + # 处理完成后 + retmsg = { + "msgtype": "text", # 要返回的消息类型 + “content": "收到" # 每个类型的消息所需要的数据 + } + retstr = json.dumps(retmsg, ensure_ascii=False) + await zmq_publish(msgdic['subscribe_id'], retstr)