1
0
mirror of synced 2025-12-23 02:18:07 +08:00

添加群发支持

This commit is contained in:
Daniel Qian
2014-08-25 11:01:09 +08:00
parent 71215bbe79
commit f326d7e72e
20 changed files with 682 additions and 60 deletions

View File

@@ -21,18 +21,18 @@ public class WxMessageRouterTest {
this.router = new WxMessageRouter();
router
.rule()
.msgType(WxConsts.MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
.handler(new WxEchoMessageHandler(sb, "COMBINE_4"))
.end()
.rule()
.msgType(WxConsts.MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
.handler(new WxEchoMessageHandler(sb, "COMBINE_3"))
.end()
.rule()
.msgType(WxConsts.MSG_TEXT).event(WxConsts.EVT_CLICK)
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK)
.handler(new WxEchoMessageHandler(sb, "COMBINE_2"))
.end()
.rule().msgType(WxConsts.MSG_TEXT).handler(new WxEchoMessageHandler(sb, WxConsts.MSG_TEXT)).end()
.rule().msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end()
.rule().event(WxConsts.EVT_CLICK).handler(new WxEchoMessageHandler(sb, WxConsts.EVT_CLICK)).end()
.rule().eventKey("KEY_1").handler(new WxEchoMessageHandler(sb, "KEY_1")).end()
.rule().content("CONTENT_1").handler(new WxEchoMessageHandler(sb, "CONTENT_1")).end()
@@ -54,7 +54,7 @@ public class WxMessageRouterTest {
@DataProvider(name="messages-1")
public Object[][] messages2() {
WxXmlMessage message1 = new WxXmlMessage();
message1.setMsgType(WxConsts.MSG_TEXT);
message1.setMsgType(WxConsts.XML_MSG_TEXT);
WxXmlMessage message2 = new WxXmlMessage();
message2.setEvent(WxConsts.EVT_CLICK);
@@ -69,22 +69,22 @@ public class WxMessageRouterTest {
message5.setContent("BLA");
WxXmlMessage c2 = new WxXmlMessage();
c2.setMsgType(WxConsts.MSG_TEXT);
c2.setMsgType(WxConsts.XML_MSG_TEXT);
c2.setEvent(WxConsts.EVT_CLICK);
WxXmlMessage c3 = new WxXmlMessage();
c3.setMsgType(WxConsts.MSG_TEXT);
c3.setMsgType(WxConsts.XML_MSG_TEXT);
c3.setEvent(WxConsts.EVT_CLICK);
c3.setEventKey("KEY_1");
WxXmlMessage c4 = new WxXmlMessage();
c4.setMsgType(WxConsts.MSG_TEXT);
c4.setMsgType(WxConsts.XML_MSG_TEXT);
c4.setEvent(WxConsts.EVT_CLICK);
c4.setEventKey("KEY_1");
c4.setContent("CONTENT_1");
return new Object[][] {
new Object[] { message1, WxConsts.MSG_TEXT + "," },
new Object[] { message1, WxConsts.XML_MSG_TEXT + "," },
new Object[] { message2, WxConsts.EVT_CLICK + "," },
new Object[] { message3, "KEY_1," },
new Object[] { message4, "CONTENT_1," },

View File

@@ -19,7 +19,7 @@ import org.testng.annotations.Test;
import chanjarster.weixin.bean.WxCustomMessage;
import chanjarster.weixin.bean.WxMenu;
import chanjarster.weixin.bean.WxMenu.WxMenuButton;
import chanjarster.weixin.bean.result.WxUploadResult;
import chanjarster.weixin.bean.result.WxMediaUploadResult;
import chanjarster.weixin.exception.WxErrorException;
import chanjarster.weixin.util.xml.XmlTransformer;
@@ -54,7 +54,7 @@ public class WxServiceTest {
public void sendCustomMessage() throws WxErrorException {
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
WxCustomMessage message = new WxCustomMessage();
message.setMsgtype(WxConsts.MSG_TEXT);
message.setMsgtype(WxConsts.CUSTOM_MSG_TEXT);
message.setTouser(configProvider.getOpenId());
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
@@ -79,7 +79,7 @@ public class WxServiceTest {
@Test(dependsOnMethods = { "testRefreshAccessToken" }, dataProvider="uploadMedia", enabled = true)
public void testUploadMedia1(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
WxUploadResult res = wxService.uploadMedia(mediaType, fileType, inputStream);
WxMediaUploadResult res = wxService.uploadMedia(mediaType, fileType, inputStream);
Assert.assertNotNull(res.getType());
Assert.assertNotNull(res.getCreated_at());
Assert.assertTrue(res.getMedia_id() != null || res.getThumb_media_id() != null);

View File

@@ -12,7 +12,7 @@ public class WxCustomMessageTest {
public void testTextReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
reply.setMsgtype(WxConsts.MSG_TEXT);
reply.setMsgtype(WxConsts.CUSTOM_MSG_TEXT);
reply.setContent("sfsfdsdf");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
}
@@ -20,7 +20,7 @@ public class WxCustomMessageTest {
public void testImageReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
reply.setMsgtype(WxConsts.MSG_IMAGE);
reply.setMsgtype(WxConsts.CUSTOM_MSG_IMAGE);
reply.setMedia_id("MEDIA_ID");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
}
@@ -28,7 +28,7 @@ public class WxCustomMessageTest {
public void testVoiceReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
reply.setMsgtype(WxConsts.MSG_VOICE);
reply.setMsgtype(WxConsts.CUSTOM_MSG_VOICE);
reply.setMedia_id("MEDIA_ID");
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
}
@@ -36,7 +36,7 @@ public class WxCustomMessageTest {
public void testVideoReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
reply.setMsgtype(WxConsts.MSG_VIDEO);
reply.setMsgtype(WxConsts.CUSTOM_MSG_VIDEO);
reply.setMedia_id("MEDIA_ID");
reply.setThumb_media_id("MEDIA_ID");
reply.setTitle("TITLE");
@@ -47,7 +47,7 @@ public class WxCustomMessageTest {
public void testMusicReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
reply.setMsgtype(WxConsts.MSG_MUSIC);
reply.setMsgtype(WxConsts.CUSTOM_MSG_MUSIC);
reply.setThumb_media_id("MEDIA_ID");
reply.setDescription("DESCRIPTION");
reply.setTitle("TITLE");
@@ -59,7 +59,7 @@ public class WxCustomMessageTest {
public void testNewsReply() {
WxCustomMessage reply = new WxCustomMessage();
reply.setTouser("OPENID");
reply.setMsgtype(WxConsts.MSG_NEWS);
reply.setMsgtype(WxConsts.CUSTOM_MSG_NEWS);
WxArticle article1 = new WxArticle();
article1.setUrl("URL");

View File

@@ -39,7 +39,7 @@ public class WxXmlMessageTest {
Assert.assertEquals(wxMessage.getToUserName(), "toUser");
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser");
Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l));
Assert.assertEquals(wxMessage.getMsgType(), WxConsts.MSG_TEXT);
Assert.assertEquals(wxMessage.getMsgType(), WxConsts.XML_MSG_TEXT);
Assert.assertEquals(wxMessage.getContent(), "this is a test");
Assert.assertEquals(wxMessage.getMsgId(), new Long(1234567890123456l));
Assert.assertEquals(wxMessage.getPicUrl(), "this is a url");
@@ -66,7 +66,7 @@ public class WxXmlMessageTest {
wxMessage.setToUserName("toUser");
wxMessage.setFromUserName("fromUser");
wxMessage.setCreateTime(new Long(1348831860l));
wxMessage.setMsgType(WxConsts.MSG_TEXT);
wxMessage.setMsgType(WxConsts.XML_MSG_TEXT);
wxMessage.setContent("this is a test");
wxMessage.setMsgId(new Long(1234567890123456l));
wxMessage.setPicUrl("this is a url");