聊天消息数据结构介绍
<p><font color="red">*<em>注意:
1、支持接口发送文本(普通文本、表情)、群公告、图片、链接、文件、小程序等消息,支持下方全部消息类型的消息回调或主动拉取。
2</em>、消息中包含的图片、语音、视频、文件等资源文件,平台会异步上传至存储服务器,回调地址在接收到消息时,可能尚未完成上传,如有文件资源转存的需求,当遇到文件不存在时可以等待几秒重试下载。**
</font></p>
<h2>消息类型(msg_type字段)</h2>
<table>
<thead>
<tr>
<th style="text-align: left;">参数名</th>
<th style="text-align: left;">解释</th>
</tr>
</thead>
<tbody>
<tr>
<td style="text-align: left;"><a href="#text">text</a></td>
<td style="text-align: left;">文本(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#announcement">announcement</a></td>
<td style="text-align: left;">群公告(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#picture">picture</a></td>
<td style="text-align: left;">图片(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#link">link</a></td>
<td style="text-align: left;">链接(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#voice">voice</a></td>
<td style="text-align: left;">语音(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#video">video</a></td>
<td style="text-align: left;">视频(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#file">file</a></td>
<td style="text-align: left;">文件(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#program">program</a></td>
<td style="text-align: left;">小程序(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#card">card</a></td>
<td style="text-align: left;">名片(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#channel">channel</a></td>
<td style="text-align: left;">视频号(支持发送)</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#merge">merge</a></td>
<td style="text-align: left;">聊天消息合集(<a href="<a href="https://www.showdoc.com.cn/yunzhenji/11490697483004869">支持转发</a>">https://www.showdoc.com.cn/yunzhenji/11490697483004869">支持转发</a></a>;)</td>
</tr>
<tr>
<td style="text-align: left;">voipinfo</td>
<td style="text-align: left;">音视频通话信息</td>
</tr>
<tr>
<td style="text-align: left;">system</td>
<td style="text-align: left;">系统消息</td>
</tr>
<tr>
<td style="text-align: left;">revoke</td>
<td style="text-align: left;">撤回</td>
</tr>
<tr>
<td style="text-align: left;">location</td>
<td style="text-align: left;">位置</td>
</tr>
<tr>
<td style="text-align: left;">redpacket</td>
<td style="text-align: left;">红包</td>
</tr>
<tr>
<td style="text-align: left;"><a href="#emotionpic">emotionpic</a></td>
<td style="text-align: left;">自定义表情</td>
</tr>
<tr>
<td style="text-align: left;">imgtext</td>
<td style="text-align: left;">图文消息</td>
</tr>
<tr>
<td style="text-align: left;">jielong</td>
<td style="text-align: left;">接龙</td>
</tr>
<tr>
<td style="text-align: left;">invite</td>
<td style="text-align: left;">群主号收到的进群确认消息</td>
</tr>
<tr>
<td style="text-align: left;">其他类型,包括数字类型</td>
<td style="text-align: left;">表示系统暂未支持,请忽略。</td>
</tr>
</tbody>
</table>
<h2>消息结构说明</h2>
<p><font color="red">*以下消息结构体[{}]为消息列表或回调通知中接收到的消息结构,同时该消息结构对应接口“<a href="<a href="https://www.showdoc.com.cn/yunzhenji/11490695962081036">发送消息/公告</a>”中的messages字段(发送消息时,消息对象{}中无需包含from_wxid、to_wxid和msg_time字段,仅需包含msg_type、content即可,如需定时发送可带delayed_time字段)</font>">https://www.showdoc.com.cn/yunzhenji/11490695962081036">发送消息/公告</a>”中的messages字段(发送消息时,消息对象{}中无需包含from_wxid、to_wxid和msg_time字段,仅需包含msg_type、content即可,如需定时发送可带delayed_time字段)</font></a>;</p>
<h2>消息结构体</h2>
<p><a id="text"></a></p>
<h4>文本消息(msg_type=text)</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;items&quot;:[
{
&quot;at_name&quot;:&quot;小王&quot;,//被@人的昵称//@所有人时,此字段传&quot;所有人&quot; (备注:@所有人 需要企微号是群主或管理员)
&quot;at_id&quot;:&quot;78xxxxx&quot;,//被@人的wxid//@所有人时,此字段传&quot;0&quot; (备注:@所有人 需要企微号是群主或管理员)
&quot;type&quot;:&quot;@&quot;//消息中要@别人时,使用此类型
},
{
&quot;text&quot;:&quot;这里是带表情的&quot;,
&quot;type&quot;:&quot;text&quot;
},
{
&quot;text&quot;:&quot;[呲牙]&quot;,
&quot;type&quot;:&quot;emotion&quot;
},
{
&quot;text&quot;:&quot;消息 &quot;,
&quot;type&quot;:&quot;text&quot;
}
]//最终这个结构发出去的消息为:“@小王 这里是带表情的[呲牙]消息”
},
&quot;from_wxid&quot;:&quot;发送者wxid&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;text&quot;,
&quot;to_wxid&quot;:&quot;接收者wxid(群ID格式-&gt;R:xxxx)&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>items</td>
<td>array</td>
<td>内容项</td>
</tr>
<tr>
<td>items[0].type</td>
<td>string</td>
<td>内容类型:text、@、emotion</td>
</tr>
<tr>
<td>items[0].text</td>
<td>string</td>
<td>文本内容</td>
</tr>
<tr>
<td>items[0].at_id</td>
<td>array</td>
<td>type为@时,被@人微信ID</td>
</tr>
<tr>
<td>items[0].at_name</td>
<td>array</td>
<td>type为@时,被@人昵称</td>
</tr>
</tbody>
</table>
<p><a id="announcement"></a></p>
<h4>群公告消息(msg_type=announcement)</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;text&quot;:&quot;xxxxxx&quot;
},
&quot;from_wxid&quot;:&quot;xxxxxxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;announcement&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxxxxxx&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>content</td>
<td>object</td>
<td>内容</td>
</tr>
<tr>
<td>content.text</td>
<td>string</td>
<td>公告内容</td>
</tr>
</tbody>
</table>
<p><a id="picture"></a></p>
<h4>图片消息(msg_type=picture)</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;url&quot;:&quot;\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/public\/wechatdata\/21\/1688850011888791\/20211116\/pic\/456f04784ca369d4e93ce6af7eeb4702.jpg&quot;
},
&quot;from_wxid&quot;:&quot;xxxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;picture&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxxx&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>string</td>
<td>图片链接</td>
</tr>
</tbody>
</table>
<p><a id="link"></a></p>
<h4>链接消息(msg_type=link)</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;cover&quot;:&quot;https:\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/u\/11647\/20211104\/5af03ac218749c32c58b9acc550416e6.jpg&quot;,
&quot;desc&quot;:&quot;从京都到“二次元”的10次文化巡礼&quot;,
&quot;title&quot;:&quot;透视日本&quot;,
&quot;url&quot;:&quot;http:\/\/ny.zdline.cn\/mobile\/pageShare\/index.html?id=2013&amp;parentUserId=788399&quot;
},
&quot;from_wxid&quot;:&quot;xxxxxxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;link&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxxxx&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>string</td>
<td>跳转链接</td>
</tr>
<tr>
<td>cover</td>
<td>string</td>
<td>封面链接</td>
</tr>
<tr>
<td>desc</td>
<td>string</td>
<td>描述</td>
</tr>
<tr>
<td>title</td>
<td>string</td>
<td>标题</td>
</tr>
</tbody>
</table>
<p><a id="voice"></a></p>
<h4>语音消息(msg_type=voice)</h4>
<p><font color="red">注意:发送语音消息,建议语音从聊天消息回调、通过聊天记录接口、或素材库获取,不建议自己拼接。</font></p>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;duration&quot;:3,//语音时长,1-60的整数
&quot;url&quot;:&quot;\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/public\/wechatdata\/21\/1688850011888791\/20211117\/voice\/26c761bf9327acac9250402861016d11.mp3&quot;,
&quot;text&quot;:&quot;xxxx&quot;//企微客户端上开启了语音自动转文本,则此处有转换后的文本内容,语音转文本回调逻辑:1秒内能转好的通过语音消息一起回调(回调类型type:chatMsg,消息类型msg_type:voice,文本字段:data[0].content.text);1秒内未转好的通过另一个回调类型voiceToText回调(回调类型:voiceToText,文本字段:data[0].text)。所以需要两部分组合起来使用。
},
&quot;from_wxid&quot;:&quot;xxxxxxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;voice&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxxx&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>是否必传</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>必传</td>
<td>string</td>
<td>链接</td>
</tr>
<tr>
<td>duration</td>
<td>必传</td>
<td>int</td>
<td>语音时长,1-60的整数</td>
</tr>
</tbody>
</table>
<p><a id="video"></a></p>
<h4>视频消息(msg_type=video)</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;url&quot;:&quot;\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/public\/wechatdata\/21\/1688851193635552\/20211116\/video\/39ee3aee38151d23d572c6156db0f627.mp4&quot;
},
&quot;from_wxid&quot;:&quot;xxxxxxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;video&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxx&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>string</td>
<td>视频链接</td>
</tr>
</tbody>
</table>
<p><a id="file"></a></p>
<h4>文件消息(msg_type=file)</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;title&quot;:&quot;公众号和多平台助手常见问题解答.pdf&quot;,
&quot;url&quot;:&quot;\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/public\/wechatdata\/21\/1688851193635552\/20211116\/file\/7fcdcc5c646e64253f00b7b55fdd4339\/公众号和多平台助手常见问题解答.pdf&quot;
},
&quot;from_wxid&quot;:&quot;xxxxxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;file&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxx&quot;
}
]</code></pre></li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>是否必传</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>url</td>
<td>必传</td>
<td>string</td>
<td>文件链接</td>
</tr>
<tr>
<td>title</td>
<td>必传</td>
<td>string</td>
<td>文件名称</td>
</tr>
<tr>
<td>ext</td>
<td>非必传</td>
<td>string</td>
<td>文件扩展名</td>
</tr>
<tr>
<td>desc</td>
<td>非必传</td>
<td>string</td>
<td>文件描述</td>
</tr>
<tr>
<td>size</td>
<td>非必传</td>
<td>string</td>
<td>文件大小(字节)</td>
</tr>
</tbody>
</table>
<p><a id="program"></a></p>
<h4>小程序消息(msg_type=program)</h4>
<ul>
<li>
<p>json结构体</p>
<pre><code>[
{
&quot;content&quot;:{
&quot;appName&quot;:&quot;gh_d10e072a11cf@app&quot;,
&quot;appid&quot;:&quot;&quot;,
&quot;cover&quot;:&quot;\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/public\/wechatdata\/90\/xxxx\/fans\/20211230\/xxxxx\/pic\/d708ac58a3d9e22f1202c0398760ef7c.jpg&quot;,
&quot;desc&quot;:&quot;&quot;,
&quot;name&quot;:&quot;xxxx&quot;,
&quot;org_content&quot;:{},//发送消息时该字段原封不动带上
&quot;title&quot;:&quot;xxxxxx&quot;,
&quot;pagepath&quot;:&quot;pages/router/router.html&quot;,
&quot;weapp_iconurl&quot;:&quot;http:\/\/mmbiz.qpic.cn\/mmbiz_png\/lnnDDnQPWKK8JSOS3l7jFT5vXicyXtoRozrxxxuSVjx7jXLc5ssssB1vibr6WViaEW6qCQVow4h8VI9UBAzZUdY6Kug\/640?wx_fmt=png&amp;wxfrom=200&quot;
},
&quot;from_wxid&quot;:&quot;xxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;program&quot;,
&quot;to_wxid&quot;:&quot;R:xxxx&quot;
}
]</code></pre>
</li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>appid</td>
<td>string</td>
<td>小程序appid</td>
</tr>
<tr>
<td>cover</td>
<td>string</td>
<td><font color="red">封面图(若要修改封面,就把org_content.wxurl置空,org_content中其他字段保持不变原封带上)</font></td>
</tr>
<tr>
<td>name</td>
<td>string</td>
<td>小程序名称</td>
</tr>
<tr>
<td>title</td>
<td>string</td>
<td>标题</td>
</tr>
<tr>
<td>weapp_iconurl</td>
<td>string</td>
<td>icon图片url</td>
</tr>
<tr>
<td>org_content</td>
<td>string</td>
<td><font color="red">小程序原始信息(通过平台企微号发送消息,从平台的消息回调通知中获取到相应消息里面包含的该字段值,或收录到素材库从素材库获取该字段)</font></td>
</tr>
</tbody>
</table>
<p><a id="card"></a></p>
<h4>名片(msg_type=card )</h4>
<ul>
<li>
<p>json结构体</p>
<pre><code>[
{
&quot;content&quot;:{
&quot;avatar&quot;:&quot;https:\/\/wework.qpic.cn\/bizmail\/6viapYdaCoCO8n73rTQZlAdF5Haj9gf9L566CuRhXGvnSQnh8QQnYGg\/0&quot;,
&quot;corp_name&quot;:&quot;xxxxx有限公司&quot;,
&quot;corp_wxid&quot;:&quot;xxxxx&quot;,
&quot;name_in_corp&quot;:&quot;&quot;,
&quot;nickname&quot;:&quot;xxxx&quot;,
&quot;wxid&quot;:&quot;xxxx&quot;
},
&quot;from_wxid&quot;:&quot;1688851971243841&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;card&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxx&quot;
}
]</code></pre>
</li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>corp_name</td>
<td>string</td>
<td>所属企业名称</td>
</tr>
<tr>
<td>nickname</td>
<td>string</td>
<td>企业微信昵称</td>
</tr>
<tr>
<td>wxid</td>
<td>string</td>
<td>企业微信wxid</td>
</tr>
<tr>
<td>avatar</td>
<td>string</td>
<td>头像</td>
</tr>
</tbody>
</table>
<p><a id="channel"></a></p>
<h4>视频号消息(msg_type=channel)</h4>
<ul>
<li>
<p>json结构体</p>
<pre><code>[
{
&quot;content&quot;:{
//其他字段原样带上
&quot;avatar&quot;:&quot;http:\/\/wx.qlogo.cn\/finderhead\/JCrjicctRMoenzjkH6sdUsm7SyMyZ2BibpSR581WoRHtx2LpiaJ53n0Fw\/0&quot;,
&quot;cover&quot;:&quot;\/\/qiyunbao.oss-cn-hangzhou.aliyuncs.com\/public\/wechatdata\/90\/21\/fans\/20220422\/1688851873049028\/pic\/0e4c241bf67dd7c404b7a8fa556db53509dd0358.jpg&quot;,
&quot;desc&quot;:&quot;天地以雨为笔\n为山河染上春天的青色\n#谷雨 #时代人文 #时代中国&quot;,
&quot;title&quot;:&quot;时代中国&quot;,
&quot;url&quot;:&quot;https:\/\/channels.weixin.qq.com\/web\/pages\/feed?eid=export%2FUzFfAgtgekIEAQAAAAAAhdYggC5eDgAAAAstQy6ubaLX4KHWvLEZgBPE0INAFxVWfPSDzNPgMIBuEHUcFfONdCcG-BdVUARO&quot;
},
&quot;from_wxid&quot;:&quot;xxxx&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;channel&quot;,
&quot;to_wxid&quot;:&quot;R:xxxx&quot;
}
]</code></pre>
</li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>avatar</td>
<td>string</td>
<td>视频号头像</td>
</tr>
<tr>
<td>cover</td>
<td>string</td>
<td>封面图</td>
</tr>
<tr>
<td>desc</td>
<td>string</td>
<td>描述</td>
</tr>
<tr>
<td>title</td>
<td>string</td>
<td>标题</td>
</tr>
<tr>
<td>url</td>
<td>string</td>
<td>视频号链接</td>
</tr>
<tr>
<td>org_content</td>
<td>string</td>
<td>视频号原始信息(通过平台企微号发送消息,从平台的消息回调通知中获取到相应消息里面包含的该字段值)</td>
</tr>
</tbody>
</table>
<p><a id="merge"></a></p>
<h4>聊天消息合集(msg_type=merge )</h4>
<ul>
<li>json结构体
<pre><code>[
{
&quot;content&quot;:{
&quot;msg_list&quot;:[{}],//该字段为数组,内部成员结构和格式,同本章节最开始部分介绍的消息结构体[{}]。
&quot;org_content&quot;:{},//取自企微号接收到的消息字段,无法自行拼接
&quot;org_wxid&quot;:&quot;R:xxx&quot;,
&quot;title&quot;:&quot;群聊&quot;,
},
&quot;from_wxid&quot;:&quot;1688851971243841&quot;,
&quot;msg_time&quot;:1667529457000,
&quot;msg_type&quot;:&quot;merge&quot;,
&quot;to_wxid&quot;:&quot;R:xxxxx&quot;
}
]</code></pre></li>
</ul>
<p><a id="emotionpic"></a></p>
<h4>表情包(msg_type=emotionpic )</h4>
<ul>
<li>
<p>json结构体</p>
<pre><code>[
{
&quot;msg_type&quot;:&quot;emotionpic&quot;,//发送该类型消息时,height、width、url三个字段不得为空,其他字段如下写死即可。
&quot;content&quot;:{
&quot;height&quot;:150,
&quot;width&quot;:150,
&quot;md5&quot;:&quot;&quot;,
&quot;org_content&quot;:{
&quot;cover&quot;:&quot;&quot;,
&quot;desc&quot;:&quot;动画表情&quot;,
&quot;p11&quot;:102,
&quot;package_id&quot;:&quot;&quot;,
&quot;text&quot;:&quot;&quot;
},
&quot;url&quot;:&quot;https://xxx&quot;
}
}
]</code></pre>
</li>
<li>content字段说明</li>
</ul>
<table>
<thead>
<tr>
<th>参数</th>
<th>类型</th>
<th>说明</th>
</tr>
</thead>
<tbody>
<tr>
<td>height</td>
<td>string</td>
<td>图片高度</td>
</tr>
<tr>
<td>width</td>
<td>string</td>
<td>图片宽度</td>
</tr>
<tr>
<td>url</td>
<td>string</td>
<td>图片地址</td>
</tr>
</tbody>
</table>