wechat-officeaccount
支持从微信服务号获取用户输入信息(含:正文,图片,视频,语音,事件),并通过zmq消息发送给订阅了config.json中woa_handler_id的代码处理,并将结果通过zmq消息发送会奔模块的等待函数
接收消息类型
- TextMessage
- ImageMessage
- VoiceMessage
- VideoMessage
- LocationMessage
- LinkMessage
- EventMessage
发送给消息处理程序的结构: { subscribe_id:消息处理程序zmq消息返回消息使用的key received_at:消息接收时间 openid:用户的openid号 msgtype:消息类型, ['text', 'image', 'video', 'voice', 'location', 'link', 'event' ] 之一 # 以下信息为是msgtype=='text' content: 正文 #### over # 以下信息为是msgtype in ['video', 'voice', 'image'] media_url:媒体的url,通过此url下载相应的图片,视频,voice等 #### over # 以下信息是msgtype=='position' location:{ # LocationMessage位置消息 latitude:纬度 longitude:经度 label:地址标签 } #### over event: # 以下信息为是msgtype == 'link' title:标题 description:描述 url:链接 }
回微信的消息类型
-
TextReply 消息属性 { msgtype: 'text' content:如果不需要回复微信的消息,content='success' }
-
ImageReply 消息属性 { msgtype:'image' media_file:图像文件的本地路径 }
-
VoiceReply 消息属性 { msgtype:'voice' media_file:图像文件的本地路径 }
-
VideoReply 消息属性 { msgtype:'video' media_file:图像文件的本地路径 }
-
ArticlesReply 消息属性 { msgtype:'video' articles:[ { 'title':标题 ‘description:描述 'image_url':图片url 'url':文章所在url } ] }
-
MusicReply 消息属性 { msgtype:'music' title:标题 description:描述 music_url:公网可访问的url hq_music_url:高质量链接 }
返回消息有以下属性
消息处理的例子
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)