mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
🎨 #1722 企业微信增加互联企业发送应用消息的接口,并重构消息相关类的包结构
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpAppChatMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpChat;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
||||
|
||||
/**
|
||||
* 消息推送接口.
|
||||
@@ -14,12 +15,26 @@ public interface WxCpMessageService {
|
||||
/**
|
||||
* <pre>
|
||||
* 发送消息
|
||||
* 详情请见: http://qydev.weixin.qq.com/wiki/index.php?title=%E5%8F%91%E9%80%81%E6%8E%A5%E5%8F%A3%E8%AF%B4%E6%98%8E
|
||||
* 详情请见: https://work.weixin.qq.com/api/doc/90000/90135/90236
|
||||
* </pre>
|
||||
*
|
||||
* @param message 要发送的消息对象
|
||||
* @return the wx cp message send result
|
||||
* @throws WxErrorException the wx error exception
|
||||
*/
|
||||
WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException;
|
||||
WxCpMessageSendResult send(WxCpMessage message) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 互联企业的应用支持推送文本、图片、视频、文件、图文等类型。
|
||||
*
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/linkedcorp/message/send?access_token=ACCESS_TOKEN
|
||||
* 文章地址:https://work.weixin.qq.com/api/doc/90000/90135/90250
|
||||
* </pre>
|
||||
*
|
||||
* @param message 要发送的消息对象
|
||||
* @return the wx cp message send result
|
||||
* @throws WxErrorException the wx error exception
|
||||
*/
|
||||
WxCpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException;
|
||||
}
|
||||
|
||||
@@ -8,8 +8,6 @@ import me.chanjar.weixin.common.util.http.MediaUploadRequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.common.util.http.RequestHttp;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMaJsCode2SessionResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
|
||||
import me.chanjar.weixin.cp.api.WxCpChatService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpAppChatMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpAppChatMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpChat;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
package me.chanjar.weixin.cp.api.impl;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpGroupRobotService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpGroupRobotMessage;
|
||||
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpGroupRobotMessage;
|
||||
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType;
|
||||
import static me.chanjar.weixin.cp.constant.WxCpConsts.GroupRobotMsgType.*;
|
||||
|
||||
/**
|
||||
* 微信群机器人消息发送api 实现
|
||||
*
|
||||
@@ -30,7 +32,7 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
@Override
|
||||
public void sendText(String content, List<String> mentionedList, List<String> mobileList) throws WxErrorException {
|
||||
WxCpGroupRobotMessage message = new WxCpGroupRobotMessage()
|
||||
.setMsgType(WxConsts.GroupRobotMsgType.TEXT)
|
||||
.setMsgType(TEXT)
|
||||
.setContent(content)
|
||||
.setMentionedList(mentionedList)
|
||||
.setMentionedMobileList(mobileList);
|
||||
@@ -40,7 +42,7 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
@Override
|
||||
public void sendMarkDown(String content) throws WxErrorException {
|
||||
WxCpGroupRobotMessage message = new WxCpGroupRobotMessage()
|
||||
.setMsgType(WxConsts.GroupRobotMsgType.MARKDOWN)
|
||||
.setMsgType(MARKDOWN)
|
||||
.setContent(content);
|
||||
cpService.postWithoutToken(this.getApiUrl(), message.toJson());
|
||||
}
|
||||
@@ -48,7 +50,7 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
@Override
|
||||
public void sendImage(String base64, String md5) throws WxErrorException {
|
||||
WxCpGroupRobotMessage message = new WxCpGroupRobotMessage()
|
||||
.setMsgType(WxConsts.GroupRobotMsgType.IMAGE)
|
||||
.setMsgType(GroupRobotMsgType.IMAGE)
|
||||
.setBase64(base64)
|
||||
.setMd5(md5);
|
||||
cpService.postWithoutToken(this.getApiUrl(), message.toJson());
|
||||
@@ -57,7 +59,7 @@ public class WxCpGroupRobotServiceImpl implements WxCpGroupRobotService {
|
||||
@Override
|
||||
public void sendNews(List<NewArticle> articleList) throws WxErrorException {
|
||||
WxCpGroupRobotMessage message = new WxCpGroupRobotMessage()
|
||||
.setMsgType(WxConsts.GroupRobotMsgType.NEWS)
|
||||
.setMsgType(GroupRobotMsgType.NEWS)
|
||||
.setArticles(articleList);
|
||||
cpService.postWithoutToken(this.getApiUrl(), message.toJson());
|
||||
}
|
||||
|
||||
@@ -4,8 +4,9 @@ import lombok.RequiredArgsConstructor;
|
||||
import me.chanjar.weixin.common.error.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageService;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessageSendResult;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpLinkedCorpMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.message.WxCpMessageSendResult;
|
||||
import me.chanjar.weixin.cp.constant.WxCpApiPathConsts;
|
||||
|
||||
/**
|
||||
@@ -19,7 +20,7 @@ public class WxCpMessageServiceImpl implements WxCpMessageService {
|
||||
private final WxCpService cpService;
|
||||
|
||||
@Override
|
||||
public WxCpMessageSendResult messageSend(WxCpMessage message) throws WxErrorException {
|
||||
public WxCpMessageSendResult send(WxCpMessage message) throws WxErrorException {
|
||||
Integer agentId = message.getAgentId();
|
||||
if (null == agentId) {
|
||||
message.setAgentId(this.cpService.getWxCpConfigStorage().getAgentId());
|
||||
@@ -28,4 +29,15 @@ public class WxCpMessageServiceImpl implements WxCpMessageService {
|
||||
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
|
||||
.getApiUrl(WxCpApiPathConsts.Message.MESSAGE_SEND), message.toJson()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException {
|
||||
Integer agentId = message.getAgentId();
|
||||
if (null == agentId) {
|
||||
message.setAgentId(this.cpService.getWxCpConfigStorage().getAgentId());
|
||||
}
|
||||
|
||||
return WxCpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
|
||||
.getApiUrl(WxCpApiPathConsts.Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user