mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
批量格式化代码
This commit is contained in:
@@ -1,16 +1,15 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Module;
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
|
||||
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
public class ApiTestModule implements Module {
|
||||
|
||||
public static <T> T fromXml(Class<T> clazz, InputStream is) {
|
||||
@@ -23,9 +22,9 @@ public class ApiTestModule implements Module {
|
||||
@Override
|
||||
public void configure(Binder binder) {
|
||||
try (InputStream is1 = ClassLoader
|
||||
.getSystemResourceAsStream("test-config.xml")) {
|
||||
.getSystemResourceAsStream("test-config.xml")) {
|
||||
WxXmlCpInMemoryConfigStorage config = fromXml(
|
||||
WxXmlCpInMemoryConfigStorage.class, is1);
|
||||
WxXmlCpInMemoryConfigStorage.class, is1);
|
||||
WxCpServiceImpl wxService = new WxCpServiceImpl();
|
||||
wxService.setWxCpConfigStorage(config);
|
||||
|
||||
@@ -72,10 +71,10 @@ public class ApiTestModule implements Module {
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " > WxXmlCpConfigStorage{" +
|
||||
"userId='" + this.userId + '\'' +
|
||||
", departmentId='" + this.departmentId + '\'' +
|
||||
", tagId='" + this.tagId + '\'' +
|
||||
'}';
|
||||
"userId='" + this.userId + '\'' +
|
||||
", departmentId='" + this.departmentId + '\'' +
|
||||
", tagId='" + this.tagId + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,13 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试部门接口
|
||||
|
||||
@@ -1,22 +1,18 @@
|
||||
package me.chanjar.weixin.cp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
|
||||
/**
|
||||
* 测试多媒体文件上传下载
|
||||
*
|
||||
@@ -35,13 +31,13 @@ public class WxCpMediaAPITest {
|
||||
@Test(dataProvider = "uploadMedia")
|
||||
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
|
||||
try (InputStream inputStream = ClassLoader
|
||||
.getSystemResourceAsStream(fileName);) {
|
||||
.getSystemResourceAsStream(fileName);) {
|
||||
WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType,
|
||||
inputStream);
|
||||
inputStream);
|
||||
Assert.assertNotNull(res.getType());
|
||||
Assert.assertNotNull(res.getCreatedAt());
|
||||
Assert.assertTrue(
|
||||
res.getMediaId() != null || res.getThumbMediaId() != null);
|
||||
res.getMediaId() != null || res.getThumbMediaId() != null);
|
||||
|
||||
if (res.getMediaId() != null) {
|
||||
this.media_ids.add(res.getMediaId());
|
||||
@@ -55,10 +51,10 @@ public class WxCpMediaAPITest {
|
||||
@DataProvider
|
||||
public Object[][] uploadMedia() {
|
||||
return new Object[][]{
|
||||
new Object[]{WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, "mm.jpeg"},
|
||||
new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, "mm.mp3"},
|
||||
new Object[]{WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, "mm.mp4"},
|
||||
new Object[]{WxConsts.MEDIA_FILE, TestConstants.FILE_JPG, "mm.jpeg"}
|
||||
new Object[]{WxConsts.MEDIA_IMAGE, TestConstants.FILE_JPG, "mm.jpeg"},
|
||||
new Object[]{WxConsts.MEDIA_VOICE, TestConstants.FILE_MP3, "mm.mp3"},
|
||||
new Object[]{WxConsts.MEDIA_VIDEO, TestConstants.FILE_MP4, "mm.mp4"},
|
||||
new Object[]{WxConsts.MEDIA_FILE, TestConstants.FILE_JPG, "mm.jpeg"}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,9 +5,8 @@ import me.chanjar.weixin.common.session.StandardSessionManager;
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@@ -22,33 +21,33 @@ public class WxCpMessageRouterTest {
|
||||
@Test(enabled = false)
|
||||
public void prepare(boolean async, StringBuffer sb, WxCpMessageRouter router) {
|
||||
router
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
|
||||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_4"))
|
||||
.end()
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
|
||||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_3"))
|
||||
.end()
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK)
|
||||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_2"))
|
||||
.end()
|
||||
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end()
|
||||
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EVT_CLICK)).end()
|
||||
.rule().async(async).eventKey("KEY_1").handler(new WxEchoCpMessageHandler(sb, "KEY_1")).end()
|
||||
.rule().async(async).content("CONTENT_1").handler(new WxEchoCpMessageHandler(sb, "CONTENT_1")).end()
|
||||
.rule().async(async).rContent(".*bc.*").handler(new WxEchoCpMessageHandler(sb, "abcd")).end()
|
||||
.rule().async(async).matcher(new WxCpMessageMatcher() {
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
|
||||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_4"))
|
||||
.end()
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
|
||||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_3"))
|
||||
.end()
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK)
|
||||
.handler(new WxEchoCpMessageHandler(sb, "COMBINE_2"))
|
||||
.end()
|
||||
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoCpMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end()
|
||||
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoCpMessageHandler(sb, WxConsts.EVT_CLICK)).end()
|
||||
.rule().async(async).eventKey("KEY_1").handler(new WxEchoCpMessageHandler(sb, "KEY_1")).end()
|
||||
.rule().async(async).content("CONTENT_1").handler(new WxEchoCpMessageHandler(sb, "CONTENT_1")).end()
|
||||
.rule().async(async).rContent(".*bc.*").handler(new WxEchoCpMessageHandler(sb, "abcd")).end()
|
||||
.rule().async(async).matcher(new WxCpMessageMatcher() {
|
||||
@Override
|
||||
public boolean match(WxCpXmlMessage message) {
|
||||
return "strangeformat".equals(message.getFormat());
|
||||
}
|
||||
}).handler(new WxEchoCpMessageHandler(sb, "matcher")).end()
|
||||
.rule().async(async).handler(new WxEchoCpMessageHandler(sb, "ALL")).end();
|
||||
.rule().async(async).handler(new WxEchoCpMessageHandler(sb, "ALL")).end();
|
||||
}
|
||||
|
||||
@Test(dataProvider = "messages-1")
|
||||
@@ -138,16 +137,16 @@ public class WxCpMessageRouterTest {
|
||||
|
||||
|
||||
return new Object[][]{
|
||||
new Object[]{message1, WxConsts.XML_MSG_TEXT + ","},
|
||||
new Object[]{message2, WxConsts.EVT_CLICK + ","},
|
||||
new Object[]{message3, "KEY_1,"},
|
||||
new Object[]{message4, "CONTENT_1,"},
|
||||
new Object[]{message5, "ALL,"},
|
||||
new Object[]{message6, "abcd,"},
|
||||
new Object[]{message7, "matcher,"},
|
||||
new Object[]{c2, "COMBINE_2,"},
|
||||
new Object[]{c3, "COMBINE_3,"},
|
||||
new Object[]{c4, "COMBINE_4,"}
|
||||
new Object[]{message1, WxConsts.XML_MSG_TEXT + ","},
|
||||
new Object[]{message2, WxConsts.EVT_CLICK + ","},
|
||||
new Object[]{message3, "KEY_1,"},
|
||||
new Object[]{message4, "CONTENT_1,"},
|
||||
new Object[]{message5, "ALL,"},
|
||||
new Object[]{message6, "abcd,"},
|
||||
new Object[]{message7, "matcher,"},
|
||||
new Object[]{c2, "COMBINE_2,"},
|
||||
new Object[]{c3, "COMBINE_3,"},
|
||||
new Object[]{c4, "COMBINE_4,"}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -162,7 +161,7 @@ public class WxCpMessageRouterTest {
|
||||
ism.setBackgroundProcessorDelay(1);
|
||||
|
||||
return new Object[][]{
|
||||
new Object[]{ism}
|
||||
new Object[]{ism}
|
||||
};
|
||||
|
||||
}
|
||||
@@ -174,8 +173,8 @@ public class WxCpMessageRouterTest {
|
||||
final WxCpMessageRouter router = new WxCpMessageRouter(null);
|
||||
router.setSessionManager(ism);
|
||||
router
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).end();
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).end();
|
||||
|
||||
WxCpXmlMessage msg = new WxCpXmlMessage();
|
||||
msg.setFromUserName("abc");
|
||||
@@ -194,8 +193,8 @@ public class WxCpMessageRouterTest {
|
||||
final WxCpMessageRouter router = new WxCpMessageRouter(null);
|
||||
router.setSessionManager(ism);
|
||||
router
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).end();
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).end();
|
||||
|
||||
WxCpXmlMessage msg = new WxCpXmlMessage();
|
||||
msg.setFromUserName("abc");
|
||||
@@ -208,8 +207,8 @@ public class WxCpMessageRouterTest {
|
||||
final WxCpMessageRouter router = new WxCpMessageRouter(null);
|
||||
router.setSessionManager(ism);
|
||||
router
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).end();
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).end();
|
||||
|
||||
WxCpXmlMessage msg = new WxCpXmlMessage();
|
||||
msg.setFromUserName("abc");
|
||||
@@ -228,8 +227,8 @@ public class WxCpMessageRouterTest {
|
||||
final WxCpMessageRouter router = new WxCpMessageRouter(null);
|
||||
router.setSessionManager(ism);
|
||||
router
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).end();
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).next()
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).end();
|
||||
|
||||
WxCpXmlMessage msg = new WxCpXmlMessage();
|
||||
msg.setFromUserName("abc");
|
||||
@@ -248,7 +247,7 @@ public class WxCpMessageRouterTest {
|
||||
final WxCpMessageRouter router = new WxCpMessageRouter(null);
|
||||
router.setSessionManager(ism);
|
||||
router
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).end();
|
||||
.rule().async(false).handler(new WxSessionMessageHandler()).end();
|
||||
|
||||
WxCpXmlMessage msg = new WxCpXmlMessage();
|
||||
msg.setFromUserName("abc");
|
||||
@@ -262,7 +261,7 @@ public class WxCpMessageRouterTest {
|
||||
final WxCpMessageRouter router = new WxCpMessageRouter(null);
|
||||
router.setSessionManager(ism);
|
||||
router
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).end();
|
||||
.rule().async(true).handler(new WxSessionMessageHandler()).end();
|
||||
|
||||
WxCpXmlMessage msg = new WxCpXmlMessage();
|
||||
msg.setFromUserName("abc");
|
||||
|
||||
@@ -4,9 +4,8 @@ import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@@ -5,9 +5,8 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
@@ -6,10 +6,8 @@ import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenuButton;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
/**
|
||||
* 测试菜单
|
||||
@@ -78,9 +76,9 @@ public class WxMenuAPITest {
|
||||
button3.getSubButtons().add(button33);
|
||||
|
||||
return new Object[][]{
|
||||
new Object[]{
|
||||
menu
|
||||
}
|
||||
new Object[]{
|
||||
menu
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
/**
|
||||
* 基础API测试
|
||||
|
||||
@@ -4,8 +4,7 @@ import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.common.util.http.RequestExecutor;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
@@ -22,7 +21,7 @@ public class WxCpBusyRetryTest {
|
||||
@Override
|
||||
public synchronized <T, E> T executeInternal(
|
||||
RequestExecutor<T, E> executor, String uri, E data)
|
||||
throws WxErrorException {
|
||||
throws WxErrorException {
|
||||
this.log.info("Executed");
|
||||
WxError error = new WxError();
|
||||
error.setErrorCode(-1);
|
||||
@@ -33,7 +32,7 @@ public class WxCpBusyRetryTest {
|
||||
service.setMaxRetryTimes(3);
|
||||
service.setRetrySleepMillis(500);
|
||||
return new Object[][]{
|
||||
new Object[]{service}
|
||||
new Object[]{service}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,8 +5,7 @@ import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
/***
|
||||
* 测试发送消息
|
||||
@@ -30,11 +29,11 @@ public class WxCpMessageAPITest {
|
||||
this.wxService.messageSend(message1);
|
||||
|
||||
WxCpMessage message2 = WxCpMessage
|
||||
.TEXT()
|
||||
.agentId(configStorage.getAgentId())
|
||||
.toUser(configStorage.getUserId())
|
||||
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
|
||||
.build();
|
||||
.TEXT()
|
||||
.agentId(configStorage.getAgentId())
|
||||
.toUser(configStorage.getUserId())
|
||||
.content("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>")
|
||||
.build();
|
||||
this.wxService.messageSend(message2);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,11 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
||||
import me.chanjar.weixin.cp.bean.article.MpnewsArticle;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import me.chanjar.weixin.cp.bean.article.NewArticle;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
@Test
|
||||
public class WxCpMessageTest {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import me.chanjar.weixin.common.api.WxConsts;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@Test
|
||||
public class WxCpXmlMessageTest {
|
||||
@@ -10,49 +10,49 @@ public class WxCpXmlMessageTest {
|
||||
public void testFromXml() {
|
||||
|
||||
String xml = "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
|
||||
+ "<CreateTime>1348831860</CreateTime>"
|
||||
+ "<MsgType><![CDATA[text]]></MsgType>"
|
||||
+ "<Content><![CDATA[this is a test]]></Content>"
|
||||
+ "<MsgId>1234567890123456</MsgId>"
|
||||
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
|
||||
+ "<MediaId><![CDATA[media_id]]></MediaId>"
|
||||
+ "<Format><![CDATA[Format]]></Format>"
|
||||
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
|
||||
+ "<Location_X>23.134521</Location_X>"
|
||||
+ "<Location_Y>113.358803</Location_Y>"
|
||||
+ "<Scale>20</Scale>"
|
||||
+ "<Label><![CDATA[位置信息]]></Label>"
|
||||
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
|
||||
+ "<Url><![CDATA[url]]></Url>"
|
||||
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
|
||||
+ "<Event><![CDATA[subscribe]]></Event>"
|
||||
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
|
||||
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
|
||||
+ "<Latitude>23.137466</Latitude>"
|
||||
+ "<Longitude>113.352425</Longitude>"
|
||||
+ "<Precision>119.385040</Precision>"
|
||||
+ "<ScanCodeInfo>"
|
||||
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
|
||||
+ " <ScanResult><![CDATA[1]]></ScanResult>"
|
||||
+ "</ScanCodeInfo>"
|
||||
+ "<SendPicsInfo>"
|
||||
+ " <Count>1</Count>\n"
|
||||
+ " <PicList>"
|
||||
+ " <item>"
|
||||
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
|
||||
+ " </item>"
|
||||
+ " </PicList>"
|
||||
+ "</SendPicsInfo>"
|
||||
+ "<SendLocationInfo>"
|
||||
+ " <Location_X><![CDATA[23]]></Location_X>\n"
|
||||
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
|
||||
+ " <Scale><![CDATA[15]]></Scale>\n"
|
||||
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
|
||||
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
|
||||
+ "</SendLocationInfo>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName> "
|
||||
+ "<CreateTime>1348831860</CreateTime>"
|
||||
+ "<MsgType><![CDATA[text]]></MsgType>"
|
||||
+ "<Content><![CDATA[this is a test]]></Content>"
|
||||
+ "<MsgId>1234567890123456</MsgId>"
|
||||
+ "<PicUrl><![CDATA[this is a url]]></PicUrl>"
|
||||
+ "<MediaId><![CDATA[media_id]]></MediaId>"
|
||||
+ "<Format><![CDATA[Format]]></Format>"
|
||||
+ "<ThumbMediaId><![CDATA[thumb_media_id]]></ThumbMediaId>"
|
||||
+ "<Location_X>23.134521</Location_X>"
|
||||
+ "<Location_Y>113.358803</Location_Y>"
|
||||
+ "<Scale>20</Scale>"
|
||||
+ "<Label><![CDATA[位置信息]]></Label>"
|
||||
+ "<Description><![CDATA[公众平台官网链接]]></Description>"
|
||||
+ "<Url><![CDATA[url]]></Url>"
|
||||
+ "<Title><![CDATA[公众平台官网链接]]></Title>"
|
||||
+ "<Event><![CDATA[subscribe]]></Event>"
|
||||
+ "<EventKey><![CDATA[qrscene_123123]]></EventKey>"
|
||||
+ "<Ticket><![CDATA[TICKET]]></Ticket>"
|
||||
+ "<Latitude>23.137466</Latitude>"
|
||||
+ "<Longitude>113.352425</Longitude>"
|
||||
+ "<Precision>119.385040</Precision>"
|
||||
+ "<ScanCodeInfo>"
|
||||
+ " <ScanType><![CDATA[qrcode]]></ScanType>"
|
||||
+ " <ScanResult><![CDATA[1]]></ScanResult>"
|
||||
+ "</ScanCodeInfo>"
|
||||
+ "<SendPicsInfo>"
|
||||
+ " <Count>1</Count>\n"
|
||||
+ " <PicList>"
|
||||
+ " <item>"
|
||||
+ " <PicMd5Sum><![CDATA[1b5f7c23b5bf75682a53e7b6d163e185]]></PicMd5Sum>"
|
||||
+ " </item>"
|
||||
+ " </PicList>"
|
||||
+ "</SendPicsInfo>"
|
||||
+ "<SendLocationInfo>"
|
||||
+ " <Location_X><![CDATA[23]]></Location_X>\n"
|
||||
+ " <Location_Y><![CDATA[113]]></Location_Y>\n"
|
||||
+ " <Scale><![CDATA[15]]></Scale>\n"
|
||||
+ " <Label><![CDATA[ 广州市海珠区客村艺苑路 106号]]></Label>\n"
|
||||
+ " <Poiname><![CDATA[wo de poi]]></Poiname>\n"
|
||||
+ "</SendLocationInfo>"
|
||||
+ "</xml>";
|
||||
WxCpXmlMessage wxMessage = WxCpXmlMessage.fromXml(xml);
|
||||
Assert.assertEquals(wxMessage.getToUserName(), "toUser");
|
||||
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser");
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@Test
|
||||
public class WxCpXmlOutImageMessageTest {
|
||||
@@ -14,12 +14,12 @@ public class WxCpXmlOutImageMessageTest {
|
||||
m.setToUserName("to");
|
||||
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[image]]></MsgType>"
|
||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[image]]></MsgType>"
|
||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
@@ -27,21 +27,21 @@ public class WxCpXmlOutImageMessageTest {
|
||||
public void testBuild() {
|
||||
WxCpXmlOutImageMessage m = WxCpXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[image]]></MsgType>"
|
||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[image]]></MsgType>"
|
||||
+ "<Image><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Image>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@Test
|
||||
public class WxCpXmlOutNewsMessageTest {
|
||||
@@ -21,26 +21,26 @@ public class WxCpXmlOutNewsMessageTest {
|
||||
m.addArticle(item);
|
||||
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[news]]></MsgType>"
|
||||
+ " <Articles>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " </Articles>"
|
||||
+ " <ArticleCount>2</ArticleCount>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[news]]></MsgType>"
|
||||
+ " <Articles>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " </Articles>"
|
||||
+ " <ArticleCount>2</ArticleCount>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
@@ -53,41 +53,41 @@ public class WxCpXmlOutNewsMessageTest {
|
||||
item.setUrl("url");
|
||||
|
||||
WxCpXmlOutNewsMessage m = WxCpXmlOutMessage.NEWS()
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.addArticle(item)
|
||||
.addArticle(item)
|
||||
.build();
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.addArticle(item)
|
||||
.addArticle(item)
|
||||
.build();
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[news]]></MsgType>"
|
||||
+ " <Articles>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " </Articles>"
|
||||
+ " <ArticleCount>2</ArticleCount>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[news]]></MsgType>"
|
||||
+ " <Articles>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " <item>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[description]]></Description>"
|
||||
+ " <PicUrl><![CDATA[picUrl]]></PicUrl>"
|
||||
+ " <Url><![CDATA[url]]></Url>"
|
||||
+ " </item>"
|
||||
+ " </Articles>"
|
||||
+ " <ArticleCount>2</ArticleCount>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@Test
|
||||
public class WxCpXmlOutTextMessageTest {
|
||||
@@ -14,12 +14,12 @@ public class WxCpXmlOutTextMessageTest {
|
||||
m.setToUserName("to");
|
||||
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[text]]></MsgType>"
|
||||
+ "<Content><![CDATA[content]]></Content>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[text]]></MsgType>"
|
||||
+ "<Content><![CDATA[content]]></Content>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
@@ -27,21 +27,21 @@ public class WxCpXmlOutTextMessageTest {
|
||||
public void testBuild() {
|
||||
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build();
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[text]]></MsgType>"
|
||||
+ "<Content><![CDATA[content]]></Content>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[text]]></MsgType>"
|
||||
+ "<Content><![CDATA[content]]></Content>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@Test
|
||||
public class WxCpXmlOutVideoMessageTest {
|
||||
@@ -16,48 +16,48 @@ public class WxCpXmlOutVideoMessageTest {
|
||||
m.setToUserName("toUser");
|
||||
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[video]]></MsgType>"
|
||||
+ "<Video>"
|
||||
+ "<MediaId><![CDATA[media_id]]></MediaId>"
|
||||
+ "<Title><![CDATA[title]]></Title>"
|
||||
+ "<Description><![CDATA[ddfff]]></Description>"
|
||||
+ "</Video> "
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[video]]></MsgType>"
|
||||
+ "<Video>"
|
||||
+ "<MediaId><![CDATA[media_id]]></MediaId>"
|
||||
+ "<Title><![CDATA[title]]></Title>"
|
||||
+ "<Description><![CDATA[ddfff]]></Description>"
|
||||
+ "</Video> "
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
public void testBuild() {
|
||||
WxCpXmlOutVideoMessage m = WxCpXmlOutMessage.VIDEO()
|
||||
.mediaId("media_id")
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.title("title")
|
||||
.description("ddfff")
|
||||
.build();
|
||||
.mediaId("media_id")
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.title("title")
|
||||
.description("ddfff")
|
||||
.build();
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[video]]></MsgType>"
|
||||
+ "<Video>"
|
||||
+ "<MediaId><![CDATA[media_id]]></MediaId>"
|
||||
+ "<Title><![CDATA[title]]></Title>"
|
||||
+ "<Description><![CDATA[ddfff]]></Description>"
|
||||
+ "</Video> "
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[video]]></MsgType>"
|
||||
+ "<Video>"
|
||||
+ "<MediaId><![CDATA[media_id]]></MediaId>"
|
||||
+ "<Title><![CDATA[title]]></Title>"
|
||||
+ "<Description><![CDATA[ddfff]]></Description>"
|
||||
+ "</Video> "
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package me.chanjar.weixin.cp.bean;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.*;
|
||||
import org.testng.annotations.*;
|
||||
|
||||
@Test
|
||||
public class WxCpXmlOutVoiceMessageTest {
|
||||
@@ -14,12 +14,12 @@ public class WxCpXmlOutVoiceMessageTest {
|
||||
m.setToUserName("to");
|
||||
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[voice]]></MsgType>"
|
||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[voice]]></MsgType>"
|
||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
@@ -27,21 +27,21 @@ public class WxCpXmlOutVoiceMessageTest {
|
||||
public void testBuild() {
|
||||
WxCpXmlOutVoiceMessage m = WxCpXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
|
||||
String expected = "<xml>"
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[voice]]></MsgType>"
|
||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
|
||||
+ "</xml>";
|
||||
+ "<ToUserName><![CDATA[to]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[from]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[voice]]></MsgType>"
|
||||
+ "<Voice><MediaId><![CDATA[ddfefesfsdfef]]></MediaId></Voice>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ class WxCpDemoInMemoryConfigStorage extends WxCpInMemoryConfigStorage {
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SimpleWxConfigProvider [appidOrCorpid=" + this.corpId + ", corpSecret=" + this.corpSecret + ", accessToken=" + this.accessToken
|
||||
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
|
||||
+ ", expiresTime=" + this.expiresTime + ", token=" + this.token + ", aesKey=" + this.aesKey + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,5 @@
|
||||
package me.chanjar.weixin.cp.demo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import me.chanjar.weixin.common.session.WxSessionManager;
|
||||
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
|
||||
import me.chanjar.weixin.cp.api.WxCpMessageHandler;
|
||||
@@ -17,6 +9,13 @@ import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpXmlOutTextMessage;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
import org.eclipse.jetty.servlet.ServletHolder;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
public class WxCpDemoServer {
|
||||
|
||||
@@ -44,9 +43,9 @@ public class WxCpDemoServer {
|
||||
|
||||
private static void initWeixin() throws IOException {
|
||||
try (InputStream is1 = ClassLoader
|
||||
.getSystemResourceAsStream("test-config.xml")) {
|
||||
.getSystemResourceAsStream("test-config.xml")) {
|
||||
WxCpDemoInMemoryConfigStorage config = WxCpDemoInMemoryConfigStorage
|
||||
.fromXml(is1);
|
||||
.fromXml(is1);
|
||||
|
||||
wxCpConfigStorage = config;
|
||||
wxCpService = new WxCpServiceImpl();
|
||||
@@ -55,11 +54,11 @@ public class WxCpDemoServer {
|
||||
WxCpMessageHandler handler = new WxCpMessageHandler() {
|
||||
@Override
|
||||
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
|
||||
Map<String, Object> context, WxCpService wxService,
|
||||
WxSessionManager sessionManager) {
|
||||
Map<String, Object> context, WxCpService wxService,
|
||||
WxSessionManager sessionManager) {
|
||||
WxCpXmlOutTextMessage m = WxCpXmlOutMessage.TEXT().content("测试加密消息")
|
||||
.fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName()).build();
|
||||
.fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName()).build();
|
||||
return m;
|
||||
}
|
||||
};
|
||||
@@ -67,22 +66,22 @@ public class WxCpDemoServer {
|
||||
WxCpMessageHandler oauth2handler = new WxCpMessageHandler() {
|
||||
@Override
|
||||
public WxCpXmlOutMessage handle(WxCpXmlMessage wxMessage,
|
||||
Map<String, Object> context, WxCpService wxService,
|
||||
WxSessionManager sessionManager) {
|
||||
Map<String, Object> context, WxCpService wxService,
|
||||
WxSessionManager sessionManager) {
|
||||
String href = "<a href=\""
|
||||
+ wxService.oauth2buildAuthorizationUrl(
|
||||
wxCpConfigStorage.getOauth2redirectUri(), null)
|
||||
+ "\">测试oauth2</a>";
|
||||
+ wxService.oauth2buildAuthorizationUrl(
|
||||
wxCpConfigStorage.getOauth2redirectUri(), null)
|
||||
+ "\">测试oauth2</a>";
|
||||
return WxCpXmlOutMessage.TEXT().content(href)
|
||||
.fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName()).build();
|
||||
.fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName()).build();
|
||||
}
|
||||
};
|
||||
|
||||
wxCpMessageRouter = new WxCpMessageRouter(wxCpService);
|
||||
wxCpMessageRouter.rule().async(false).content("哈哈") // 拦截内容为“哈哈”的消息
|
||||
.handler(handler).end().rule().async(false).content("oauth")
|
||||
.handler(oauth2handler).end();
|
||||
.handler(handler).end().rule().async(false).content("oauth")
|
||||
.handler(oauth2handler).end();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ public class WxCpEndpointServlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
@@ -55,7 +55,7 @@ public class WxCpEndpointServlet extends HttpServlet {
|
||||
}
|
||||
|
||||
WxCpXmlMessage inMessage = WxCpXmlMessage
|
||||
.fromEncryptedXml(request.getInputStream(), this.wxCpConfigStorage, timestamp, nonce, msgSignature);
|
||||
.fromEncryptedXml(request.getInputStream(), this.wxCpConfigStorage, timestamp, nonce, msgSignature);
|
||||
WxCpXmlOutMessage outMessage = this.wxCpMessageRouter.route(inMessage);
|
||||
if (outMessage != null) {
|
||||
response.getWriter().write(outMessage.toEncryptedXml(this.wxCpConfigStorage));
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package me.chanjar.weixin.cp.demo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import java.io.IOException;
|
||||
import java.util.Arrays;
|
||||
|
||||
public class WxCpOAuth2Servlet extends HttpServlet {
|
||||
private static final long serialVersionUID = 1L;
|
||||
@@ -21,7 +20,7 @@ public class WxCpOAuth2Servlet extends HttpServlet {
|
||||
|
||||
@Override
|
||||
protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||
throws IOException {
|
||||
throws IOException {
|
||||
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
Reference in New Issue
Block a user