怎样使用群机械人
正在末端某个群组增加机械人以后,创立者能够正在机械人概略页瞅的该机械人独有的webhookurl。开辟者能够按如下分析a背那个地点倡议HTTP POST 恳求,便可完毕给该群组收收消息。上面举个简朴的例子.
假定 webhook是:https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=693a91f6-6xxx-4bc4-97a0-0ec2sifa5aaa
出格出格要留神:必然要庇护佳机械人的webhook地点,制止透露!没有要分享到github、专客等可被公然查阅之处,不然好人就能够用您的机械人去收残余消息了。
如下是用curl东西朝群组拉收文原消息的示例(留神要将url交流成您的机械人webhook地点,content必需是utf8编码):- curl'https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=693axxx6-7aoc-4bc4-97a0-0ec2sifa5aaa'\-H'Content-Type: application/json'\-d'
- {
- "msgtype": "text",
- "text": {
- "content": "hello world"
- }
- }'
复造代码 目前自界说机械人撑持文原(text)、markdown(markdown)、图片(image)、图文(news)四种消息范例。
机械人的text/markdown范例消息撑持正在content中使用<@userid>扩大语法去@群成员
消息 范例及数据格局
一、文原范例
- {"msgtype":"text","text":{"content":"广州旧日气候:29度,年夜部门多云,落雨几率:60%","mentioned_list":["wangqing","@all"],"mentioned_mobile_list":["13800001111","@all"]}}
复造代码参数 | 可否必挖 | 分析 | msgtype | 是 | 消息范例,此时牢固为text | content | 是 | 文原实质,最少没有超越2048个字节,必需是utf8编码 | mentioned_list | 可 | userid的列表,提醒群中的指定成员(@某个成员),@all暗示提醒统统人,假设开辟者获得没有到userid,能够使用mentioned_mobile_list | mentioned_mobile_list | 可 | 脚机号列表,提醒脚机号对于应的群成员(@某个成员),@all暗示提醒统统人 |
二、markdown范例
- {"msgtype":"markdown","markdown":{"content": "及时新删用户反应<font color="warning">132例</font>,请相干共事留神。\n
- >范例:<font color="co妹妹ent">用户反应</font>>一般用户反应:<font color="co妹妹ent">117例</font>>VIP用户反应:<font color="co妹妹ent">15例</font>"}}
复造代码参数 | 可否必挖 | 分析 | msgtype | 是 | 消息范例,此时牢固为markdown | content | 是 | markdown实质,最少没有超越4096个字节,必需是utf8编码 | 今朝撑持的markdown语法是以下的子散:- 题目 (撑持1至6级题目,留神#取笔墨中心要有空格)
- # 题目一
- ## 题目两
- ### 题目三
- #### 题目四
- ##### 题目五
- ###### 题目六
- 减细
- **bold**
- 链交
- [那是一个链交](http://work.weixin.qq.com/api/doc)
- 止内乱代码段(久没有撑持跨止)
- `code`
- 引用
- >引用 笔墨
- 字体色彩(只撑持3种内乱置色彩)
- <font color="info">绿色</font>
- <font color="co妹妹ent">灰色</font>
- <font color="warning">橙白色</font>
复造代码 三、图片范例
- {"msgtype":"image","image":{"base64":"DATA","md5":"MD5"}}
复造代码参数 | 可否必挖 | 分析 | msgtype | 是 | 消息范例,此时牢固为image | base64 | 是 | 图片实质的base64编码 | md5 | 是 | 图片实质(base64编码前)的md5值;杂两退造编码为base64的成果,没有照顾头部疑息(data:image/jpeg;base64,奸淫) | 注:图片(base64编码前)最年夜不克不及超越2M,撑持JPG,PNG格局
四、图文范例
- {"msgtype":"news","news":{"articles":[{"title":"中春节礼物付出","description":"今年中春节公司有豪礼相收","url":"www.qq.com","picurl":"http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png"}]}}
复造代码参数 | 可否必挖 | 分析 | msgtype | 是 | 消息范例,此时牢固为news | articles | 是 | 图文消息,一个图文消息撑持1到8条图文 | title | 是 | 题目,没有超越128个字节,超越会主动截断 | description | 可 | 描绘,没有超越512个字节,超越会主动截断 | url | 是 | 面打后跳转的链交。 | picurl | 可 | 图文消息的图片链交,撑持JPG、PNG格局,较佳的结果为年夜图 1068455,小图150150。 |
五、文献范例
- {"msgtype":"file","file":{"media_id":"3a8asd892asd8asd"}}
复造代码参数 | 可否必挖 | 分析 | msgtype | 是 | 消息范例,此时牢固为file | media_id | 是 | 文献id,颠末下文的文献上传交心获得 |
六、模版卡片范例
文原报告模版卡片
- {"msgtype":"template_card","template_card":{"card_type":"text_notice","source":{"icon_url":"https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0","desc":"企业微疑","desc_color":0},"main_title":{"title":"欢送使用企业微疑","desc":"您的密友在聘请您参加企业微疑"},"emphasis_content":{"title":"100","desc":"数据寄义"},"quote_area":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH","title":"引用文原题目","quote_text":"Jack:企业微疑果然很佳用~\nBalian:超等佳的一款硬件!"},"sub_title_text":"下载企业微疑借能抢白包!","horizontal_content_list":[{"keyname":"聘请人","value":"弛三"},{"keyname":"企微民网","value":"面打会见","type":1,"url":"https://work.weixin.qq.com/?from=openApi"},{"keyname":"企微下载","value":"企业微疑.apk","type":2,"media_id":"MEDIAID"}],"jump_list":[{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","title":"企业微疑民网"},{"type":2,"appid":"APPID","pagepath":"PAGEPATH","title":"跳转小法式"}],"card_action":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH"}}}
复造代码 恳求参数
参数 | 范例 | 可否必挖 | 分析 | msgtype | String | 是 | 消息范例,此时的消息范例牢固为template_card | template_card | Object | 是 | 具体的模版卡片参数 | template_card的参数分析
参数 | 范例 | 可否必挖 | 分析 | card_type | String | 是 | 模版卡片的模版范例,文原报告模版卡片的范例为text_notice | source | Object | 可 | 卡片滥觞款式疑息,没有需要滥觞款式可没有挖写 | source.icon_url | String | 可 | 滥觞图片的url | source.desc | String | 可 | 滥觞图片的描绘,倡议没有超越13个字 | source.desc_color | Int | 可 | 滥觞笔墨的色彩,今朝撑持:0(默认)灰色,1玄色,2白色,3绿色 | main_title | Object | 是 | 模版卡片的主要实质,包罗一级题目战题目帮助疑息 | main_title.title | String | 可 | 一级题目,倡议没有超越26个字。模版卡片主要实质的一级题目main_title.title战两级一般文原sub_title_text必需有一项挖写 | main_title.desc | String | 可 | 题目帮助疑息,倡议没有超越30个字 | emphasis_content | Object | 可 | 枢纽数据款式 | emphasis_content.title | String | 可 | 枢纽数据款式的数据实质,倡议没有超越10个字 | emphasis_content.desc | String | 可 | 枢纽数据款式的数据描绘实质,倡议没有超越15个字 | quote_area | Object | 可 | 引用文件款式,倡议没有取枢纽数据同用 | quote_area.type | Int | 可 | 引用文件款式地区面打工作,0或者没有挖代表不面打工作,1代表跳转url,2代表跳转女伶 href="https://www.taojin168.com/cloud/" target="_blank">小法式 | quote_area.url | String | 可 | 面打跳转的url,quote_area.type是1时必挖 | quote_area.appid | String | 可 | 面打跳转的小法式的appid,quote_area.type是2时必挖 | quote_area.pagepath | String | 可 | 面打跳转的小法式的pagepath,quote_area.type是2时选挖 | quote_area.title | String | 可 | 引用文件款式的题目 | quote_area.quote_text | String | 可 | 引用文件款式的引用案牍 | sub_title_text | String | 可 | 两级一般文原,倡议没有超越112个字。模版卡片主要实质的一级题目main_title.title战两级一般文原sub_title_text必需有一项挖写 | horizontal_content_list | Object[] | 可 | 两级题目+文原列表,该字段可为空数组,但是无数据的话需确认对于应字段可否必挖,列表少度没有超越6 | horizontal_content_list.type | Int | 可 | 链交范例,0或者没有挖代表是一般文原,1代表跳转url,2代表下载附件,3代表@职工 | horizontal_content_list.keyname | String | 是 | 两级题目,倡议没有超越5个字 | horizontal_content_list.value | String | 可 | 两级文原,假设horizontal_content_list.type是2,该字段代表文献称呼(要包罗文献范例),倡议没有超越26个字 | horizontal_content_list.url | String | 可 | 链交跳转的url,horizontal_content_list.type是1时必挖 | horizontal_content_list.media_id | String | 可 | 附件的media_id,horizontal_content_list.type是2时必挖 | horizontal_content_list.userid | String | 可 | 被@的成员的userid,horizontal_content_list.type是3时必挖 | jump_list | Object[] | 可 | 跳转指挥款式的列表,该字段可为空数组,但是无数据的话需确认对于应字段可否必挖,列表少度没有超越3 | jump_list.type | Int | 可 | 跳转链交范例,0或者没有挖代表没有是链交,1代表跳转url,2代表跳转小法式 | jump_list.title | String | 是 | 跳转链交款式的案牍实质,倡议没有超越13个字 | jump_list.url | String | 可 | 跳转链交的url,jump_list.type是1时必挖 | jump_list.appid | String | 可 | 跳转链交的小法式的appid,jump_list.type是2时必挖 | jump_list.pagepath | String | 可 | 跳转链交的小法式的pagepath,jump_list.type是2时选挖 | card_action | Object | 是 | 部分卡片的面打跳转工作,text_notice模版卡片中该字段为必挖项 | card_action.type | Int | 是 | 卡片跳转范例,1代表跳转url,2代表翻开小法式。text_notice模版卡片中该字段与值范畴为[1,2] | card_action.url | String | 可 | 跳转工作的url,card_action.type是1时必挖 | card_action.appid | String | 可 | 跳转工作的小法式的appid,card_action.type是2时必挖 | card_action.pagepath | String | 可 | 跳转工作的小法式的pagepath,card_action.type是2时选挖 | 图文展示模版卡片
- {"msgtype":"template_card","template_card":{"card_type":"news_notice","source":{"icon_url":"https://wework.qpic.cn/wwpic/252813_jOfDHtcISzuodLa_1629280209/0","desc":"企业微疑","desc_color":0},"main_title":{"title":"欢送使用企业微疑","desc":"您的密友在聘请您参加企业微疑"},"card_image":{"url":"https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0","aspect_ratio":2.25},"image_text_area":{"type":1,"url":"https://work.weixin.qq.com","title":"欢送使用企业微疑","desc":"您的密友在聘请您参加企业微疑","image_url":"https://wework.qpic.cn/wwpic/354393_4zpkKXd7SrGMvfg_1629280616/0"},"quote_area":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH","title":"引用文原题目","quote_text":"Jack:企业微疑果然很佳用~\nBalian:超等佳的一款硬件!"},"vertical_content_list":[{"title":"欣喜白包等您去拿","desc":"下载企业微疑借能抢白包!"}],"horizontal_content_list":[{"keyname":"聘请人","value":"弛三"},{"keyname":"企微民网","value":"面打会见","type":1,"url":"https://work.weixin.qq.com/?from=openApi"},{"keyname":"企微下载","value":"企业微疑.apk","type":2,"media_id":"MEDIAID"}],"jump_list":[{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","title":"企业微疑民网"},{"type":2,"appid":"APPID","pagepath":"PAGEPATH","title":"跳转小法式"}],"card_action":{"type":1,"url":"https://work.weixin.qq.com/?from=openApi","appid":"APPID","pagepath":"PAGEPATH"}}}
复造代码 恳求参数
参数 | 范例 | 可否必挖 | 分析 | msgtype | String | 是 | 模版卡片的消息范例为template_card | template_card | Object | 是 | 具体的模版卡片参数 | template_card的参数分析
参数 | 范例 | 可否必挖 | 分析 | card_type | String | 是 | 模版卡片的模版范例,图文展示模版卡片的范例为news_notice | source | Object | 可 | 卡片滥觞款式疑息,没有需要滥觞款式可没有挖写 | source.icon_url | String | 可 | 滥觞图片的url | source.desc | String | 可 | 滥觞图片的描绘,倡议没有超越13个字 | source.desc_color | Int | 可 | 滥觞笔墨的色彩,今朝撑持:0(默认)灰色,1玄色,2白色,3绿色 | main_title | Object | 是 | 模版卡片的主要实质,包罗一级题目战题目帮助疑息 | main_title.title | String | 是 | 一级题目,倡议没有超越26个字 | main_title.desc | String | 可 | 题目帮助疑息,倡议没有超越30个字 | card_image | Object | 是 | 图片款式 | card_image.url | String | 是 | 图片的url | card_image.aspect_ratio | Float | 可 | 图片的严下比,严下比要小于2.25,年夜于1.3,没有挖该参数默认1.3 | image_text_area | Object | 可 | 右图左文款式 | image_text_area.type | Int | 可 | 右图左文款式地区面打工作,0或者没有挖代表不面打工作,1代表跳转url,2代表跳转小法式 | image_text_area.url | String | 可 | 面打跳转的url,image_text_area.type是1时必挖 | image_text_area.appid | String | 可 | 面打跳转的小法式的appid,必需是取目前使用联系关系的小法式,image_text_area.type是2时必挖 | image_text_area.pagepath | String | 可 | 面打跳转的小法式的pagepath,image_text_area.type是2时选挖 | image_text_area.title | String | 可 | 右图左文款式的题目 | image_text_area.desc | String | 可 | 右图左文款式的描绘 | image_text_area.image_url | String | 是 | 右图左文款式的图片url | quote_area | Object | 可 | 引用文件款式,倡议没有取枢纽数据同用 | quote_area.type | Int | 可 | 引用文件款式地区面打工作,0或者没有挖代表不面打工作,1代表跳转url,2代表跳转小法式 | quote_area.url | String | 可 | 面打跳转的url,quote_area.type是1时必挖 | quote_area.appid | String | 可 | 面打跳转的小法式的appid,quote_area.type是2时必挖 | quote_area.pagepath | String | 可 | 面打跳转的小法式的pagepath,quote_area.type是2时选挖 | quote_area.title | String | 可 | 引用文件款式的题目 | quote_area.quote_text | String | 可 | 引用文件款式的引用案牍 | vertical_content_list | Object[] | 可 | 卡片两级笔直实质,该字段可为空数组,但是无数据的话需确认对于应字段可否必挖,列表少度没有超越4 | vertical_content_list.title | String | 是 | 卡片两级题目,倡议没有超越26个字 | vertical_content_list.desc | String | 可 | 两级一般文原,倡议没有超越112个字 | horizontal_content_list | Object[] | 可 | 两级题目+文原列表,该字段可为空数组,但是无数据的话需确认对于应字段可否必挖,列表少度没有超越6 | horizontal_content_list.type | Int | 可 | 模版卡片的两级题目疑息实质撑持的范例,1是url,2是文献附件 | horizontal_content_list.keyname | String | 是 | 两级题目,倡议没有超越5个字 | horizontal_content_list.value | String | 可 | 两级文原,假设horizontal_content_list.type是2,该字段代表文献称呼(要包罗文献范例),倡议没有超越26个字 | horizontal_content_list.url | String | 可 | 链交跳转的url,horizontal_content_list.type是1时必挖 | horizontal_content_list.media_id | String | 可 | 附件的media_id,horizontal_content_list.type是2时必挖 | jump_list | Object[] | 可 | 跳转指挥款式的列表,该字段可为空数组,但是无数据的话需确认对于应字段可否必挖,列表少度没有超越3 | jump_list.type | Int | 可 | 跳转链交范例,0或者没有挖代表没有是链交,1代表跳转url,2代表跳转小法式 | jump_list.title | String | 是 | 跳转链交款式的案牍实质,倡议没有超越13个字 | jump_list.url | String | 可 | 跳转链交的url,jump_list.type是1时必挖 | jump_list.appid | String | 可 | 跳转链交的小法式的appid,jump_list.type是2时必挖 | jump_list.pagepath | String | 可 | 跳转链交的小法式的pagepath,jump_list.type是2时选挖 | card_action | Object | 是 | 部分卡片的面打跳转工作,news_notice模版卡片中该字段为必挖项 | card_action.type | Int | 是 | 卡片跳转范例,1代表跳转url,2代表翻开小法式。news_notice模版卡片中该字段与值范畴为[1,2] | card_action.url | String | 可 | 跳转工作的url,card_action.type是1时必挖 | card_action.appid | String | 可 | 跳转工作的小法式的appid,card_action.type是2时必挖 | card_action.pagepath | String | 可 | 跳转工作的小法式的pagepath,card_action.type是2时选挖消息收收频次限定 | 每一个机械人收收的消息不克不及超越20条/分钟。
七、文献上传交心
艳材上传获得media_id,该media_id仅三天内乱有用
media_id只可是对于应上传文献的机械人能够使用
恳求方法:POST(HTTPS)
恳求地点:https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=KEY&type=TYPE
使用multipart/form-data POST上传文献, 文献标记名为”media”
参数分析:
参数 | 范例 | 可否必挖 | 分析 | key | 是 | 挪用交心凭据, | 机械人webhookurl中的key参数 | type | 是 | 牢固传file | POST的恳求包中,form-data中媒介文献标记,应包罗有 filename、filelength、content-type等疑息
filename标记文献展示的称呼。好比,使用该media_id收消息时,展示的文献名由该字段掌握
恳求示例:- POST https://qyapi.weixin.qq.com/cgi-bin/webhook/upload_media?key=693a91f6-7xxx-4bc4-97a0-0ec2sifa5aaa&type=file HTTP/1.1
- Content-Type: multipart/form-data;boundary=-------------------------acebdf13572468
- Content-Length: 220
- ---------------------------acebdf13572468
- Content-Disposition: form-data;name="media";filename="wework.txt";filelength=6
- Content-Type: application/octet-stream
- mytext
- ---------------------------acebdf13572468--
复造代码 前去数据:- {"errcode":0,"errmsg":"ok","type":"file","media_id":"1G6nrLmr5EC3MMb_-zK1dDdzmd0p7cNliYu9V5w7o8K0","created_at":"1380000000"}
复造代码 参数分析:
参数 | 分析 | type | 媒介文献范例,别离有图片(image)、语音(voice)、望频(video),一般文献(file) | media_id | 媒介文献上传后获得的唯一标记,3天内乱有用 | created_at | 媒介文献上传时间戳 | 上传的文献限定:请求文献巨细正在5B~20M之间 |