From 419b52b28e2b37ea7861f72675a30f2bcdea7c29 Mon Sep 17 00:00:00 2001 From: lgcareer <18610854716@163.com> Date: Thu, 4 Jul 2019 19:14:49 +0800 Subject: [PATCH] read Enterprise WeChat config test --- .../utils/EnterpriseWeChatUtilsTest.java | 57 +++++++++++-------- 1 file changed, 32 insertions(+), 25 deletions(-) diff --git a/escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java b/escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java index 2a45196aed..646d34ed7b 100644 --- a/escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java +++ b/escheduler-alert/src/test/java/cn/escheduler/alert/utils/EnterpriseWeChatUtilsTest.java @@ -16,11 +16,10 @@ */ package cn.escheduler.alert.utils; +import com.alibaba.fastjson.JSON; import org.junit.Assert; import org.junit.Test; -import com.alibaba.fastjson.JSON; - import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -33,24 +32,23 @@ import java.util.Collection; * enterprise.wechat.token.url * enterprise.wechat.push.url * enterprise.wechat.send.msg + * enterprise.wechat.agent.id + * enterprise.wechat.users */ public class EnterpriseWeChatUtilsTest { + private String agentId = PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_AGENT_ID); // app id + private Collection listUserId = Arrays.asList(PropertyUtils.getString(Constants.ENTERPRISE_WECHAT_USERS).split(",")); + // Please change - private String agentId = "1000002"; // app id private String partyId = "2"; private Collection listPartyId = Arrays.asList("2","4"); - private String userId = "test1"; - private Collection listUserId = Arrays.asList("test1","test2"); - @Test public void testSendSingleTeamWeChat() { - EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); - try { - String token = wx.getToken(); - String msg = wx.makeTeamSendMsg(partyId, agentId, "hello world"); - String resp = wx.sendQiyeWeixin("utf-8", msg, token); + String token = EnterpriseWeChatUtils.getToken(); + String msg = EnterpriseWeChatUtils.makeTeamSendMsg(partyId, agentId, "hello world"); + String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); String errmsg = JSON.parseObject(resp).getString("errmsg"); Assert.assertEquals(errmsg, "ok"); @@ -61,12 +59,11 @@ public class EnterpriseWeChatUtilsTest { @Test public void testSendMultiTeamWeChat() { - EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); try { - String token = wx.getToken(); - String msg = wx.makeTeamSendMsg(listPartyId, agentId, "hello world"); - String resp = wx.sendQiyeWeixin("utf-8", msg, token); + String token = EnterpriseWeChatUtils.getToken(); + String msg = EnterpriseWeChatUtils.makeTeamSendMsg(listPartyId, agentId, "hello world"); + String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); String errmsg = JSON.parseObject(resp).getString("errmsg"); Assert.assertEquals(errmsg, "ok"); @@ -77,12 +74,23 @@ public class EnterpriseWeChatUtilsTest { @Test public void testSendSingleUserWeChat() { - EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); - try { - String token = wx.getToken(); - String msg = wx.makeUserSendMsg(userId, agentId, "hello world"); - String resp = wx.sendQiyeWeixin("utf-8", msg, token); + String token = EnterpriseWeChatUtils.getToken(); + String msg = EnterpriseWeChatUtils.makeUserSendMsg(listUserId.stream().findFirst().get(), agentId, "您的会议室已经预定,稍后会同步到`邮箱` \n" + + ">**事项详情** \n" + + ">事 项:开会
" + + ">组织者:@miglioguan \n" + + ">参与者:@miglioguan、@kunliu、@jamdeezhou、@kanexiong、@kisonwang \n" + + "> \n" + + ">会议室:广州TIT 1楼 301 \n" + + ">日 期:2018年5月18日 \n" + + ">时 间:上午9:00-11:00 \n" + + "> \n" + + ">请准时参加会议。 \n" + + "> \n" + + ">如需修改会议信息,请点击:[修改会议信息](https://work.weixin.qq.com)\""); + + String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); String errmsg = JSON.parseObject(resp).getString("errmsg"); Assert.assertEquals(errmsg, "ok"); @@ -93,12 +101,11 @@ public class EnterpriseWeChatUtilsTest { @Test public void testSendMultiUserWeChat() { - EnterpriseWeChatUtils wx = new EnterpriseWeChatUtils(); - try { - String token = wx.getToken(); - String msg = wx.makeUserSendMsg(listUserId, agentId, "hello world"); - String resp = wx.sendQiyeWeixin("utf-8", msg, token); + String token = EnterpriseWeChatUtils.getToken(); + + String msg = EnterpriseWeChatUtils.makeUserSendMsg(listUserId, agentId, "hello world"); + String resp = EnterpriseWeChatUtils.sendEnterpriseWeChat("utf-8", msg, token); String errmsg = JSON.parseObject(resp).getString("errmsg"); Assert.assertEquals(errmsg, "ok");