云真机

API接口文档


发消息给单个客户或客户群

<h5>简要描述</h5> <ul> <li>&lt;font color=&quot;red&quot;&gt;目前支持文本(普通文本、表情)、群公告、图片、链接、文件、小程序、语音、视频等类型的消息发送。发送消息数据结构见下方请求示例,具体字段描述及回调推送的详细消息结构参见“&lt;a href=&quot;<a href="https://www.showdoc.com.cn/yunzhenji/11490690012909560&quot;&gt;说明-聊天消息&lt;/a&gt;”)&lt;/font&gt">https://www.showdoc.com.cn/yunzhenji/11490690012909560&quot;&gt;说明-聊天消息&lt;/a&gt;”)&lt;/font&gt</a>;</li> </ul> <h5>请求URL</h5> <ul> <li><code>https://oapi-yzj.miaokol.com/wechat/sendMessage</code></li> </ul> <h5>请求方式</h5> <ul> <li>POST </li> </ul> <h5>请求参数</h5> <ul> <li>数据为json字符串,各字段说明如下</li> </ul> <table> <thead> <tr> <th style="text-align: left;">参数名</th> <th style="text-align: left;">必选</th> <th style="text-align: left;">类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">app_id</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>APP ID</td> </tr> <tr> <td style="text-align: left;">access_token</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>Access Token</td> </tr> <tr> <td style="text-align: left;">wxid</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>企微号wxid</td> </tr> <tr> <td style="text-align: left;">target_wxid</td> <td style="text-align: left;">是</td> <td style="text-align: left;">string</td> <td>客户wxid或客户群wxid</td> </tr> <tr> <td style="text-align: left;">messages</td> <td style="text-align: left;">是</td> <td style="text-align: left;">array</td> <td>消息数组,支持单次发送多条消息,单次最多5条。具体消息格式参见“&lt;a href=&quot;<a href="https://www.showdoc.com.cn/qybopen/7990161805486320&quot;&gt;说明-聊天消息&lt;/a&gt;”章节">https://www.showdoc.com.cn/qybopen/7990161805486320&quot;&gt;说明-聊天消息&lt;/a&gt;”章节</a></td> </tr> <tr> <td style="text-align: left;">messages[0].delayed_time</td> <td style="text-align: left;">否</td> <td style="text-align: left;">int</td> <td>消息发送时间戳(默认0,需要实现消息间隔时可用该字段,指定某条消息的发送时间,取值如:1641280299,表示该条消息于2022-01-04 15:11:39发送);另外为了避免企微号频繁发消息被限制,也可用该字段错开消息发送时间</td> </tr> <tr> <td style="text-align: left;">messages[0].api_send_id</td> <td style="text-align: left;">否</td> <td style="text-align: left;">int或string</td> <td>用于通过API发送消息的消息记录与智域管家.云真机回调消息的关联,此处带了该参数,&lt;a href=&quot;<a href="https://www.showdoc.com.cn/yunzhenji/11490693160849765&quot;&gt;消息回调&lt;/a&gt;会带回">https://www.showdoc.com.cn/yunzhenji/11490693160849765&quot;&gt;消息回调&lt;/a&gt;会带回</a>。</td> </tr> </tbody> </table> <h5>请求示例</h5> <pre><code>POST /wechat/sendMessage HTTP/1.1 Host:oapi-yzj.miaokol.com Content-Type: application/json; charset=UTF-8 { &amp;quot;app_id&amp;quot;: &amp;quot;xxx&amp;quot;, &amp;quot;access_token&amp;quot;: &amp;quot;xxx&amp;quot;, &amp;quot;wxid&amp;quot;: &amp;quot;16xxx&amp;quot;, &amp;quot;target_wxid&amp;quot;: &amp;quot;7xxx&amp;quot;, &amp;quot;messages&amp;quot;: [//数组,支持单次发送多条消息,单次最多5条,下面仅为说明发送消息的字段、格式。 { &amp;quot;msg_type&amp;quot;: &amp;quot;text&amp;quot;,//文本,type类型说明,参见参见“说明-聊天消息”部分 &amp;quot;content&amp;quot;: { &amp;quot;items&amp;quot;: [ { &amp;quot;type&amp;quot;: &amp;quot;text&amp;quot;, &amp;quot;text&amp;quot;: &amp;quot;test&amp;quot; } ] }, &amp;quot;delayed_time&amp;quot;: 1641280299 }, { &amp;quot;msg_type&amp;quot;: &amp;quot;announcement&amp;quot;,//群公告 &amp;quot;content&amp;quot;: { &amp;quot;text&amp;quot;: &amp;quot;xxx&amp;quot; }, &amp;quot;delayed_time&amp;quot;: 1641280299 }, { &amp;quot;msg_type&amp;quot;: &amp;quot;picture&amp;quot;,//图片 &amp;quot;content&amp;quot;: { &amp;quot;url&amp;quot;: &amp;quot;xxxxxxxxx&amp;quot; }, &amp;quot;delayed_time&amp;quot;: 1641280299 }, { &amp;quot;msg_type&amp;quot;: &amp;quot;link&amp;quot;,//链接 &amp;quot;content&amp;quot;: { &amp;quot;cover&amp;quot;: &amp;quot;xx&amp;quot;, &amp;quot;desc&amp;quot;: &amp;quot;xxx&amp;quot;, &amp;quot;title&amp;quot;: &amp;quot;xx&amp;quot;, &amp;quot;url&amp;quot;: &amp;quot;xxxx&amp;quot; }, &amp;quot;delayed_time&amp;quot;: 1641280299 }, { &amp;quot;msg_type&amp;quot;: &amp;quot;file&amp;quot;,//文件 &amp;quot;content&amp;quot;: { &amp;quot;title&amp;quot;: &amp;quot;xx&amp;quot;, &amp;quot;url&amp;quot;: &amp;quot;xxxx&amp;quot; }, &amp;quot;delayed_time&amp;quot;: 1641280299 }, { &amp;quot;msg_type&amp;quot;:&amp;quot;voice&amp;quot;,//发语音需要使用微信的语音消息:1、收录在素材库里的语音;2、推送或主动拉取的来自企微上报聊天消息里的语音; &amp;quot;content&amp;quot;:{ &amp;quot;url&amp;quot;:&amp;quot;xxxxx.mp3&amp;quot;, &amp;quot;duration&amp;quot;:60,//语音时长,1-60整数 &amp;quot;org_content&amp;quot;:&amp;quot;&amp;quot;//来自微信语音消息 }, &amp;quot;delayed_time&amp;quot;: 1641280299 } ] } </code></pre> <h5>响应示例</h5> <pre><code>HTTP/1.1 200 OK Content-Type: application/json; charset=UTF-8 {     &amp;quot;data&amp;quot;:[//数组,数组长度同messages         {             &amp;quot;idx&amp;quot;:0,//0表示messages中的第一条消息,以此类推             &amp;quot;api_send_svrid&amp;quot;:&amp;quot;168xxx,7xxx,1675997660116ABKocO&amp;quot;,//系统生成的发送消息ID             &amp;quot;api_send_id&amp;quot;:&amp;quot;116&amp;quot;//发送时带了该参数,此处才有返回         }     ],     &amp;quot;errcode&amp;quot;:0 } </code></pre> <h5>响应说明</h5> <table> <thead> <tr> <th style="text-align: left;">参数名</th> <th style="text-align: left;">类型</th> <th>说明</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">errcode</td> <td style="text-align: left;">int</td> <td>0表示经过了数据初步校验,不表示消息已经发送成功;非0表示初步校验不通过,错误信息见message字段</td> </tr> <tr> <td style="text-align: left;">data</td> <td style="text-align: left;">object[]</td> <td>响应数据</td> </tr> <tr> <td style="text-align: left;">data[x].idx</td> <td style="text-align: left;">int</td> <td>0表示messages中的第一条消息,以此类推</td> </tr> <tr> <td style="text-align: left;">data[x].api_send_svrid</td> <td style="text-align: left;">string</td> <td>系统生成的发送消息ID</td> </tr> <tr> <td style="text-align: left;">data[x].api_send_id</td> <td style="text-align: left;">string</td> <td>发送时带了该参数,此处才有返回</td> </tr> </tbody> </table> <p>&lt;font color=&quot;red&quot;&gt;注意:&lt;/font&gt; 1、此处errcode返回0,不表示消息已经发送成功了,只有data中返回的idx个数与请求参数messages的个数一致时,才表示请求参数通过了初步校验,消息已经异步交给企微客户端执行;messages中的多条消息,是每条单独执行发送的。</p> <p>2、消息经过第一步校验成功交给企微客户端执行之后,默认发送成功,但真正要判断成功与否,要依赖回调事件“聊天消息发送失败 (chatMsgSendFail)”,有失败回调表示失败,否则表示成功。消息文档地址见:&lt;a href=&quot;<a href="https://www.showdoc.com.cn/yunzhenji/11490693160849765&quot;&gt;https://www.showdoc.com.cn/yunzhenji/11490693160849765&lt;/a&gt">https://www.showdoc.com.cn/yunzhenji/11490693160849765&quot;&gt;https://www.showdoc.com.cn/yunzhenji/11490693160849765&lt;/a&gt</a>;。</p> <p>3、关于回调事件“聊天消息(chatMsg)”和“聊天消息发送失败 (chatMsgSendFail)” 只要经过了第一步的校验,消息交给了企微客户端执行,无论企微客户端执行成功与否,都会有回调事件“聊天消息(chatMsg)”,所以有该回调不代表消息发送成功,只是默认发送成功。只有当后续没有收到“聊天消息发送失败 (chatMsgSendFail)”的回调才能表示消息真正发送成功。这2个回调都有参数api_send_svrid和api_send_id(请求时传了才有),可以用于与接口请求时的用户端的发送记录做关联。</p>

页面列表

ITEM_HTML