1
0
mirror of synced 2025-12-23 10:39:27 +08:00

🆕 #1720 增加企业微信群机器人消息发送接口

* #1720 增加群机器人的消息类型

* #1720 增加文件流生成base64方法,用于图片转base64,群机器人图片消息发送测试

* #1720 增加群机器人消息推送地址webhook/send

* #1720 增加群机器人webhook_key配置属性

* #1720 增加群机器人消息推送接口服务、不需要自动带accessToken的post请求接口

* #1720 新增微信群机器人消息发送api

* #1720 新增微信群机器人消息发送api单元测试

* #1720 新增微信群机器人消息发送api单元测试配置、新增属性webhook配置

Co-authored-by: yang ran <yangran@xytdt.com>
This commit is contained in:
xyz9025
2020-08-21 22:30:17 +08:00
committed by GitHub
parent 17c20422e2
commit 6f953862df
14 changed files with 427 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
package me.chanjar.weixin.cp.api;
import com.google.inject.Inject;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.cp.bean.article.NewArticle;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
import java.io.InputStream;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static org.testng.Assert.*;
/**
* 微信群机器人消息发送api 单元测试
*
* @author yr
* @date 2020-08-20
*/
@Slf4j
@Guice(modules = ApiTestModule.class)
public class WxCpGroupRobotServiceTest {
@Inject
protected WxCpService wxService;
private WxCpGroupRobotService robotService;
@BeforeTest
public void setup() {
robotService = wxService.getGroupRobotService();
}
@Test
public void testSendText() throws WxErrorException {
robotService.sendText("Hello World", null, null);
}
@Test
public void testSendMarkDown() throws WxErrorException {
String content = "实时新增用户反馈<font color=\"warning\">132例</font>,请相关同事注意。\n" +
">类型:<font color=\"comment\">用户反馈</font> \n" +
">普通用户反馈:<font color=\"comment\">117例</font> \n" +
">VIP用户反馈:<font color=\"comment\">15例</font>";
robotService.sendMarkDown(content);
}
@Test
public void testSendImage() throws WxErrorException {
InputStream inputStream = getClass().getClassLoader().getResourceAsStream("mm.jpeg");
assert inputStream != null;
String base64 = FileUtils.imageToBase64ByStream(inputStream);
String md5 = "1cb2e787063d66e24f5f89e7fc267a4d";
robotService.sendImage(base64, md5);
}
@Test
public void testSendNews() throws WxErrorException {
NewArticle article = new NewArticle("图文消息测试","hello world","http://www.baidu.com","http://res.mail.qq.com/node/ww/wwopenmng/images/independent/doc/test_pic_msg1.png");
robotService.sendNews(Stream.of(article).collect(Collectors.toList()));
}
}

View File

@@ -10,4 +10,5 @@
<departmentId>企业号通讯录的某个部门id</departmentId>
<tagId>企业号通讯录里的某个tagid</tagId>
<oauth2redirectUri>网页授权获取用户信息回调地址</oauth2redirectUri>
<webhookKey>webhook链接地址的key值</webhookKey>
</xml>

View File

@@ -7,6 +7,7 @@
<class name="me.chanjar.weixin.cp.api.WxCpBaseAPITest"/>
<class name="me.chanjar.weixin.cp.api.WxCpMessageAPITest"/>
<class name="me.chanjar.weixin.cp.api.WxCpMessageRouterTest"/>
<class name="me.chanjar.weixin.cp.api.WxCpGroupRobotServiceTest"/>
</classes>
</test>