mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-04-05 17:38:05 +08:00
🎨 #2541 【企业微信】发送群聊机器人消息接口增加对文件类型的支持
This commit is contained in:
parent
19c311391e
commit
5da9fb30aa
@ -88,4 +88,13 @@ public interface WxCpGroupRobotService {
|
||||
* @throws WxErrorException 异常
|
||||
*/
|
||||
void sendNews(String webhookUrl, List<NewArticle> articleList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 发送文件类型的消息
|
||||
*
|
||||
* @param webhookUrl webhook地址
|
||||
* @param mediaId 文件id
|
||||
* @throws WxErrorException 异常
|
||||
*/
|
||||
void sendFile(String webhookUrl, String mediaId) throws WxErrorException;
|
||||
}
|
||||
|
@ -1,7 +1,6 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpGroupRobotService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
@ -14,8 +13,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import java.util.List;
|
||||
|
||||
import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType;
|
||||
import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType.MARKDOWN;
|
||||
import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType.TEXT;
|
||||
|
||||
/**
|
||||
* 企业微信群机器人消息发送api 实现
|
||||
@ -59,7 +56,7 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
@Override
|
||||
public void sendText(String webhookUrl, String content, List<String> mentionedList, List<String> mobileList) throws WxErrorException {
|
||||
this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage()
|
||||
.setMsgType(TEXT)
|
||||
.setMsgType(GroupRobotMsgType.TEXT)
|
||||
.setContent(content)
|
||||
.setMentionedList(mentionedList)
|
||||
.setMentionedMobileList(mobileList)
|
||||
@ -69,7 +66,7 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
@Override
|
||||
public void sendMarkdown(String webhookUrl, String content) throws WxErrorException {
|
||||
this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage()
|
||||
.setMsgType(MARKDOWN)
|
||||
.setMsgType(GroupRobotMsgType.MARKDOWN)
|
||||
.setContent(content)
|
||||
.toJson());
|
||||
}
|
||||
@ -89,4 +86,11 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
.setArticles(articleList).toJson());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendFile(String webhookUrl, String mediaId) throws WxErrorException {
|
||||
this.cpService.postWithoutToken(webhookUrl, new WxCpGroupRobotMessage()
|
||||
.setMsgType(GroupRobotMsgType.FILE)
|
||||
.setMediaId(mediaId).toJson());
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -57,6 +57,11 @@ public class WxCpGroupRobotMessage implements Serializable {
|
||||
*/
|
||||
private List<NewArticle> articles;
|
||||
|
||||
/**
|
||||
* 文件id
|
||||
*/
|
||||
private String mediaId;
|
||||
|
||||
public String toJson() {
|
||||
JsonObject messageJson = new JsonObject();
|
||||
messageJson.addProperty("msgtype", this.getMsgType());
|
||||
@ -112,6 +117,12 @@ public class WxCpGroupRobotMessage implements Serializable {
|
||||
messageJson.add("news", text);
|
||||
break;
|
||||
}
|
||||
case FILE: {
|
||||
JsonObject file = new JsonObject();
|
||||
file.addProperty("media_id", this.getMediaId());
|
||||
messageJson.add("file", file);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
|
||||
}
|
||||
|
@ -374,6 +374,12 @@ public class WxCpConsts {
|
||||
* 图文消息(点击跳转到外链).
|
||||
*/
|
||||
public static final String NEWS = "news";
|
||||
|
||||
/**
|
||||
* 文件类型消息.
|
||||
*/
|
||||
public static final String FILE = "file";
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user