2026-03-02 08:53:20 +08:00
2026-03-01 15:04:07 +08:00
2026-03-01 15:05:51 +08:00
2026-03-02 08:53:20 +08:00

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)

Description
No description provided
Readme 252 KiB
Languages
Python 100%