公司内部交流使用的企业微信,最近项目中要实现向员工发送企业微信通知,于是看了下企业微信的api,简单实现了下:
1. 其实就是一个HTTP请求,如下
请求方式:POST(HTTPS)
请求地址: https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN
文本消息请求参数实例如下
-
{ "touser" : "UserID1|UserID2|UserID3",//用户的ID, "toparty" : "PartyID1|PartyID2",//部门id "totag" : "TagID1 | TagID2",//标签id "msgtype" : "text",//消息类型 "agentid" : 1,//应用的ID,比如时公告还是通知什么一类的,可参考企业微信开发者文档 "text" : { //类型和内容 "content" : "你的快递已到,请携带工卡前往邮件中心领取。\n出发前可查看<a href=\"http://work.weixin.qq.com\">邮件中心视频实况</a>,聪明避开排队。" }, "safe":0//是否保密信息 } //其中 touser、toparty、totag不能同时为空
其他如图片类型,语音则可以参考开发者文档中的类型对应设置:企业微信-开发者文档
pom依赖
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<