mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-02-16 13:26:23 +08:00
微信企业号
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.InputStream;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
|
||||
import me.chanjar.weixin.mp.api.WxConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxInMemoryConfigStorage;
|
||||
import me.chanjar.weixin.mp.api.WxServiceImpl;
|
||||
|
||||
import com.google.inject.Binder;
|
||||
import com.google.inject.Module;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
public class ApiTestModule implements Module {
|
||||
|
||||
@Override
|
||||
public void configure(Binder binder) {
|
||||
try {
|
||||
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
|
||||
WxXmlConfigStorage config = fromXml(WxXmlConfigStorage.class, is1);
|
||||
WxServiceImpl wxService = new WxServiceImpl();
|
||||
wxService.setWxConfigStorage(config);
|
||||
|
||||
binder.bind(WxServiceImpl.class).toInstance(wxService);
|
||||
binder.bind(WxConfigStorage.class).toInstance(config);
|
||||
} catch (JAXBException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> T fromXml(Class<T> clazz, InputStream is) throws JAXBException {
|
||||
Unmarshaller um = JAXBContext.newInstance(clazz).createUnmarshaller();
|
||||
InputSource inputSource = new InputSource(is);
|
||||
inputSource.setEncoding("utf-8");
|
||||
T object = (T) um.unmarshal(inputSource);
|
||||
return object;
|
||||
}
|
||||
|
||||
@XmlRootElement(name = "xml")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
public static class WxXmlConfigStorage extends WxInMemoryConfigStorage {
|
||||
|
||||
protected String openId;
|
||||
|
||||
public String getOpenId() {
|
||||
return openId;
|
||||
}
|
||||
public void setOpenId(String openId) {
|
||||
this.openId = openId;
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SimpleWxConfigProvider [appId=" + appId + ", secret=" + secret + ", accessToken=" + accessToken
|
||||
+ ", expiresIn=" + expiresIn + ", token=" + token + ", openId=" + openId + "]";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 基础API测试
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "baseAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxBaseAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
public void testRefreshAccessToken() throws WxErrorException {
|
||||
WxConfigStorage configStorage = wxService.wxConfigStorage;
|
||||
String before = configStorage.getAccessToken();
|
||||
wxService.accessTokenRefresh();
|
||||
|
||||
String after = configStorage.getAccessToken();
|
||||
|
||||
Assert.assertNotEquals(before, after);
|
||||
Assert.assertTrue(StringUtils.isNotBlank(after));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxCustomMessage;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/***
|
||||
* 测试发送客服消息
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups="customMessageAPI", dependsOnGroups = "baseAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxCustomMessageAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
public void testSendCustomMessage() throws WxErrorException {
|
||||
ApiTestModule.WxXmlConfigStorage configStorage = (ApiTestModule.WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
WxCustomMessage message = new WxCustomMessage();
|
||||
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
|
||||
message.setToUser(configStorage.getOpenId());
|
||||
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||
|
||||
wxService.customMessageSend(message);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxGroup;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试分组接口
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
@Test(groups = "groupAPI", dependsOnGroups = "baseAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxGroupAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
protected WxGroup group;
|
||||
|
||||
public void testGroupCreate() throws WxErrorException {
|
||||
WxGroup res = wxService.groupCreate("测试分组1");
|
||||
Assert.assertEquals(res.getName(), "测试分组1");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods="testGroupCreate")
|
||||
public void testGroupGet() throws WxErrorException {
|
||||
List<WxGroup> groupList = wxService.groupGet();
|
||||
Assert.assertNotNull(groupList);
|
||||
Assert.assertTrue(groupList.size() > 0);
|
||||
for (WxGroup g : groupList) {
|
||||
group = g;
|
||||
Assert.assertNotNull(g.getName());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
|
||||
public void getGroupUpdate() throws WxErrorException {
|
||||
group.setName("分组改名");
|
||||
wxService.groupUpdate(group);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,166 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMassGroupMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMassNews;
|
||||
import me.chanjar.weixin.mp.bean.WxMassNews.WxMassNewsArticle;
|
||||
import me.chanjar.weixin.mp.bean.WxMassOpenIdsMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMassVideo;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMassSendResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMassUploadResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试群发消息
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI", "groupAPI"})
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMassMessageAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
@Test
|
||||
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
|
||||
// 发送群发消息
|
||||
ApiTestModule.WxXmlConfigStorage configProvider = (ApiTestModule.WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage();
|
||||
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
|
||||
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||
massMessage.getToUsers().add(configProvider.getOpenId());
|
||||
|
||||
WxMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
Assert.assertNotNull(massResult.getMsgId());
|
||||
}
|
||||
|
||||
@Test(dataProvider="massMessages")
|
||||
public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
|
||||
// 发送群发消息
|
||||
ApiTestModule.WxXmlConfigStorage configProvider = (ApiTestModule.WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
WxMassOpenIdsMessage massMessage = new WxMassOpenIdsMessage();
|
||||
massMessage.setMsgType(massMsgType);
|
||||
massMessage.setMediaId(mediaId);
|
||||
massMessage.getToUsers().add(configProvider.getOpenId());
|
||||
|
||||
WxMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
Assert.assertNotNull(massResult.getMsgId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testTextMassGroupMessageSend() throws WxErrorException {
|
||||
WxMassGroupMessage massMessage = new WxMassGroupMessage();
|
||||
massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT);
|
||||
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||
massMessage.setGroupId(wxService.groupGet().get(0).getId());
|
||||
|
||||
WxMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
Assert.assertNotNull(massResult.getMsgId());
|
||||
}
|
||||
|
||||
@Test(dataProvider="massMessages")
|
||||
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
|
||||
WxMassGroupMessage massMessage = new WxMassGroupMessage();
|
||||
massMessage.setMsgtype(massMsgType);
|
||||
massMessage.setMediaId(mediaId);
|
||||
massMessage.setGroupId(wxService.groupGet().get(0).getId());
|
||||
|
||||
WxMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
Assert.assertNotNull(massResult.getMsgId());
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] massMessages() throws WxErrorException, IOException {
|
||||
Object[][] messages = new Object[4][];
|
||||
/*
|
||||
* 视频素材
|
||||
*/
|
||||
{
|
||||
// 上传视频到媒体库
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.mp4");
|
||||
WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream);
|
||||
Assert.assertNotNull(uploadMediaRes);
|
||||
Assert.assertNotNull(uploadMediaRes.getMediaId());
|
||||
|
||||
// 把视频变成可被群发的媒体
|
||||
WxMassVideo video = new WxMassVideo();
|
||||
video.setTitle("测试标题");
|
||||
video.setDescription("测试描述");
|
||||
video.setMediaId(uploadMediaRes.getMediaId());
|
||||
WxMassUploadResult uploadResult = wxService.massVideoUpload(video);
|
||||
Assert.assertNotNull(uploadResult);
|
||||
Assert.assertNotNull(uploadResult.getMediaId());
|
||||
messages[0] = new Object[] { WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() };
|
||||
}
|
||||
/**
|
||||
* 图片素材
|
||||
*/
|
||||
{
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg");
|
||||
WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
|
||||
Assert.assertNotNull(uploadMediaRes);
|
||||
Assert.assertNotNull(uploadMediaRes.getMediaId());
|
||||
messages[1] = new Object[] { WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() };
|
||||
}
|
||||
/**
|
||||
* 语音素材
|
||||
*/
|
||||
{
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.mp3");
|
||||
WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream);
|
||||
Assert.assertNotNull(uploadMediaRes);
|
||||
Assert.assertNotNull(uploadMediaRes.getMediaId());
|
||||
messages[2] = new Object[] { WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() };
|
||||
}
|
||||
/**
|
||||
* 图文素材
|
||||
*/
|
||||
{
|
||||
// 上传照片到媒体库
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg");
|
||||
WxMediaUploadResult uploadMediaRes = wxService.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
|
||||
Assert.assertNotNull(uploadMediaRes);
|
||||
Assert.assertNotNull(uploadMediaRes.getMediaId());
|
||||
|
||||
// 上传图文消息
|
||||
WxMassNews news = new WxMassNews();
|
||||
WxMassNewsArticle article1 = new WxMassNewsArticle();
|
||||
article1.setTitle("标题1");
|
||||
article1.setContent("内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1内容1");
|
||||
article1.setThumbMediaId(uploadMediaRes.getMediaId());
|
||||
news.addArticle(article1);
|
||||
|
||||
WxMassNewsArticle article2 = new WxMassNewsArticle();
|
||||
article2.setTitle("标题2");
|
||||
article2.setContent("内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2内容2");
|
||||
article2.setThumbMediaId(uploadMediaRes.getMediaId());
|
||||
article2.setShowCoverPic(true);
|
||||
article2.setAuthor("作者2");
|
||||
article2.setContentSourceUrl("www.baidu.com");
|
||||
article2.setDigest("摘要2");
|
||||
news.addArticle(article2);
|
||||
|
||||
WxMassUploadResult massUploadResult = wxService.massNewsUpload(news);
|
||||
Assert.assertNotNull(massUploadResult);
|
||||
Assert.assertNotNull(uploadMediaRes.getMediaId());
|
||||
messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() };
|
||||
}
|
||||
return messages;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.result.WxMediaUploadResult;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试多媒体文件上传下载
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups="mediaAPI", dependsOnGroups="baseAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMediaAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
private List<String> media_ids = new ArrayList<String>();
|
||||
|
||||
@Test(dataProvider="uploadMedia")
|
||||
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
|
||||
WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream);
|
||||
Assert.assertNotNull(res.getType());
|
||||
Assert.assertNotNull(res.getCreatedAt());
|
||||
Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null);
|
||||
|
||||
if (res.getMediaId() != null) {
|
||||
media_ids.add(res.getMediaId());
|
||||
}
|
||||
if (res.getThumbMediaId() != null) {
|
||||
media_ids.add(res.getThumbMediaId());
|
||||
}
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] uploadMedia() {
|
||||
return new Object[][] {
|
||||
new Object[] { WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, "mm.jpeg" },
|
||||
new Object[] { WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, "mm.mp3" },
|
||||
new Object[] { WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, "mm.mp4" },
|
||||
new Object[] { WxConsts.MEDIA_THUMB, WxConsts.FILE_JPG, "mm.jpeg" }
|
||||
};
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia")
|
||||
public void testDownloadMedia(String media_id) throws WxErrorException {
|
||||
wxService.mediaDownload(media_id);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] downloadMedia() {
|
||||
Object[][] params = new Object[this.media_ids.size()][];
|
||||
for (int i = 0; i < this.media_ids.size(); i++) {
|
||||
params[i] = new Object[] { this.media_ids.get(i) };
|
||||
}
|
||||
return params;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,91 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import javax.xml.bind.JAXBException;
|
||||
|
||||
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.mp.bean.WxMenu;
|
||||
import me.chanjar.weixin.mp.bean.WxMenu.WxMenuButton;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
/**
|
||||
* 测试菜单
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups="menuAPI", dependsOnGroups="baseAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMenuAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
@Test(dataProvider = "menu")
|
||||
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
|
||||
wxService.menuCreate(wxMenu);
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testCreateMenu"})
|
||||
public void testGetMenu() throws WxErrorException {
|
||||
Assert.assertNotNull(wxService.menuGet());
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods = { "testGetMenu"})
|
||||
public void testDeleteMenu() throws WxErrorException {
|
||||
wxService.menuDelete();
|
||||
}
|
||||
|
||||
@DataProvider(name="menu")
|
||||
public Object[][] getMenu() throws JAXBException {
|
||||
WxMenu menu = new WxMenu();
|
||||
WxMenuButton button1 = new WxMenuButton();
|
||||
button1.setType(WxConsts.BUTTON_CLICK);
|
||||
button1.setName("今日歌曲");
|
||||
button1.setKey("V1001_TODAY_MUSIC");
|
||||
|
||||
WxMenuButton button2 = new WxMenuButton();
|
||||
button2.setType(WxConsts.BUTTON_CLICK);
|
||||
button2.setName("歌手简介");
|
||||
button2.setKey("V1001_TODAY_SINGER");
|
||||
|
||||
WxMenuButton button3 = new WxMenuButton();
|
||||
button3.setName("菜单");
|
||||
|
||||
menu.getButtons().add(button1);
|
||||
menu.getButtons().add(button2);
|
||||
menu.getButtons().add(button3);
|
||||
|
||||
WxMenuButton button31 = new WxMenuButton();
|
||||
button31.setType(WxConsts.BUTTON_VIEW);
|
||||
button31.setName("搜索");
|
||||
button31.setUrl("http://www.soso.com/");
|
||||
|
||||
WxMenuButton button32 = new WxMenuButton();
|
||||
button32.setType(WxConsts.BUTTON_VIEW);
|
||||
button32.setName("视频");
|
||||
button32.setUrl("http://v.qq.com/");
|
||||
|
||||
WxMenuButton button33 = new WxMenuButton();
|
||||
button33.setType(WxConsts.BUTTON_CLICK);
|
||||
button33.setName("赞一下我们");
|
||||
button33.setKey("V1001_GOOD");
|
||||
|
||||
button3.getSubButtons().add(button31);
|
||||
button3.getSubButtons().add(button32);
|
||||
button3.getSubButtons().add(button33);
|
||||
|
||||
return new Object[][] {
|
||||
new Object[] {
|
||||
menu
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import me.chanjar.weixin.mp.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.api.WxMessageHandler;
|
||||
import me.chanjar.weixin.mp.api.WxMessageRouter;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
|
||||
/**
|
||||
* 测试消息路由器
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test
|
||||
public class WxMessageRouterTest {
|
||||
|
||||
@Test(enabled = false)
|
||||
public void prepare(boolean async, StringBuffer sb, WxMessageRouter router) {
|
||||
router
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1").content("CONTENT_1")
|
||||
.handler(new WxEchoMessageHandler(sb, "COMBINE_4"))
|
||||
.end()
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK).eventKey("KEY_1")
|
||||
.handler(new WxEchoMessageHandler(sb, "COMBINE_3"))
|
||||
.end()
|
||||
.rule()
|
||||
.async(async)
|
||||
.msgType(WxConsts.XML_MSG_TEXT).event(WxConsts.EVT_CLICK)
|
||||
.handler(new WxEchoMessageHandler(sb, "COMBINE_2"))
|
||||
.end()
|
||||
.rule().async(async).msgType(WxConsts.XML_MSG_TEXT).handler(new WxEchoMessageHandler(sb, WxConsts.XML_MSG_TEXT)).end()
|
||||
.rule().async(async).event(WxConsts.EVT_CLICK).handler(new WxEchoMessageHandler(sb, WxConsts.EVT_CLICK)).end()
|
||||
.rule().async(async).eventKey("KEY_1").handler(new WxEchoMessageHandler(sb, "KEY_1")).end()
|
||||
.rule().async(async).content("CONTENT_1").handler(new WxEchoMessageHandler(sb, "CONTENT_1")).end()
|
||||
.rule().async(async).rContent(".*bc.*").handler(new WxEchoMessageHandler(sb, "abcd")).end()
|
||||
.rule().async(async).handler(new WxEchoMessageHandler(sb, "ALL")).end();
|
||||
;
|
||||
}
|
||||
|
||||
@Test(dataProvider="messages-1")
|
||||
public void testSync(WxXmlMessage message, String expected) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
WxMessageRouter router = new WxMessageRouter();
|
||||
prepare(false, sb, router);
|
||||
router.route(message);
|
||||
Assert.assertEquals(sb.toString(), expected);
|
||||
}
|
||||
|
||||
@Test(dataProvider="messages-1")
|
||||
public void testAsync(WxXmlMessage message, String expected) throws InterruptedException {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
WxMessageRouter router = new WxMessageRouter();
|
||||
prepare(true, sb, router);
|
||||
router.route(message);
|
||||
Thread.sleep(500l);
|
||||
Assert.assertEquals(sb.toString(), expected);
|
||||
}
|
||||
|
||||
public void testConcurrency() throws InterruptedException {
|
||||
final WxMessageRouter router = new WxMessageRouter();
|
||||
router.rule().handler(new WxMessageHandler() {
|
||||
@Override
|
||||
public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map<String, Object> context) {
|
||||
return null;
|
||||
}
|
||||
}).end();
|
||||
|
||||
final WxXmlMessage m = new WxXmlMessage();
|
||||
Runnable r = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
router.route(m);
|
||||
try {
|
||||
Thread.sleep(1000l);
|
||||
} catch (InterruptedException e) {
|
||||
}
|
||||
}
|
||||
};
|
||||
for (int i = 0; i < 10; i++) {
|
||||
new Thread(r).start();
|
||||
}
|
||||
|
||||
Thread.sleep(1000l * 2);
|
||||
}
|
||||
@DataProvider(name="messages-1")
|
||||
public Object[][] messages2() {
|
||||
WxXmlMessage message1 = new WxXmlMessage();
|
||||
message1.setMsgType(WxConsts.XML_MSG_TEXT);
|
||||
|
||||
WxXmlMessage message2 = new WxXmlMessage();
|
||||
message2.setEvent(WxConsts.EVT_CLICK);
|
||||
|
||||
WxXmlMessage message3 = new WxXmlMessage();
|
||||
message3.setEventKey("KEY_1");
|
||||
|
||||
WxXmlMessage message4 = new WxXmlMessage();
|
||||
message4.setContent("CONTENT_1");
|
||||
|
||||
WxXmlMessage message5 = new WxXmlMessage();
|
||||
message5.setContent("BLA");
|
||||
|
||||
WxXmlMessage message6 = new WxXmlMessage();
|
||||
message6.setContent("abcd");
|
||||
|
||||
WxXmlMessage c2 = new WxXmlMessage();
|
||||
c2.setMsgType(WxConsts.XML_MSG_TEXT);
|
||||
c2.setEvent(WxConsts.EVT_CLICK);
|
||||
|
||||
WxXmlMessage c3 = new WxXmlMessage();
|
||||
c3.setMsgType(WxConsts.XML_MSG_TEXT);
|
||||
c3.setEvent(WxConsts.EVT_CLICK);
|
||||
c3.setEventKey("KEY_1");
|
||||
|
||||
WxXmlMessage c4 = new WxXmlMessage();
|
||||
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.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[] { c2, "COMBINE_2," },
|
||||
new Object[] { c3, "COMBINE_3," },
|
||||
new Object[] { c4, "COMBINE_4," }
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
public static class WxEchoMessageHandler implements WxMessageHandler {
|
||||
|
||||
private StringBuffer sb;
|
||||
private String echoStr;
|
||||
|
||||
public WxEchoMessageHandler(StringBuffer sb, String echoStr) {
|
||||
this.sb = sb;
|
||||
this.echoStr = echoStr;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map<String, Object> context) {
|
||||
sb.append(this.echoStr).append(',');
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.result.WxQrCodeTicket;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
@Test(groups = "qrCodeAPI", dependsOnGroups = { "baseAPI" })
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxQrCodeAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
public void testQrCodeCreateTmpTicket() throws WxErrorException {
|
||||
WxQrCodeTicket ticket = wxService.qrCodeCreateTmpTicket(1, null);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() != -1);
|
||||
}
|
||||
|
||||
public void testQrCodeCreateLastTicket() throws WxErrorException {
|
||||
WxQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() == -1);
|
||||
}
|
||||
|
||||
public void testQrCodePicture() throws WxErrorException {
|
||||
WxQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1);
|
||||
File file = wxService.qrCodePicture(ticket);
|
||||
Assert.assertNotNull(file);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试短连接
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
@Test(groups = "shortURLAPI", dependsOnGroups = { "baseAPI" })
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxShortUrlAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
public void testShortUrl() throws WxErrorException {
|
||||
String shortUrl = wxService.shortUrl("www.baidu.com");
|
||||
Assert.assertNotNull(shortUrl);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,56 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule.WxXmlConfigStorage;
|
||||
import me.chanjar.weixin.mp.bean.result.WxUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxUserList;
|
||||
import me.chanjar.weixin.mp.exception.WxErrorException;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "userAPI", dependsOnGroups = { "baseAPI", "groupAPI" })
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxUserAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxServiceImpl wxService;
|
||||
|
||||
public void testUserUpdateRemark() throws WxErrorException {
|
||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
wxService.userUpdateRemark(configProvider.getOpenId(), "测试备注名");
|
||||
}
|
||||
|
||||
public void testUserInfo() throws WxErrorException {
|
||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
WxUser user = wxService.userInfo(configProvider.getOpenId(), null);
|
||||
Assert.assertNotNull(user);
|
||||
}
|
||||
|
||||
public void testUserList() throws WxErrorException {
|
||||
WxUserList wxUserList = wxService.userList(null);
|
||||
Assert.assertNotNull(wxUserList);
|
||||
Assert.assertFalse(wxUserList.getCount() == -1);
|
||||
Assert.assertFalse(wxUserList.getTotal() == -1);
|
||||
Assert.assertFalse(wxUserList.getOpenIds().size() == -1);
|
||||
}
|
||||
|
||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
||||
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
long groupid = wxService.userGetGroup(configStorage.getOpenId());
|
||||
Assert.assertTrue(groupid != -1l);
|
||||
}
|
||||
|
||||
public void getGroupMoveUser() throws WxErrorException {
|
||||
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||
wxService.userUpdateGroup(configStorage.getOpenId(), wxService.groupGet().get(3).getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,19 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxAccessToken;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxAccessTokenTest {
|
||||
|
||||
public void testFromJson() {
|
||||
|
||||
String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}";
|
||||
WxAccessToken wxError = WxAccessToken.fromJson(json);
|
||||
Assert.assertEquals(wxError.getAccessToken(), "ACCESS_TOKEN");
|
||||
Assert.assertTrue(wxError.getExpiresIn() == 7200);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxCustomMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.WxCustomMessage.WxArticle;
|
||||
|
||||
@Test
|
||||
public class WxCustomMessageTest {
|
||||
|
||||
public void testTextReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
|
||||
reply.setContent("sfsfdsdf");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
||||
}
|
||||
|
||||
public void testTextBuild() {
|
||||
WxCustomMessage reply = WxCustomMessage.TEXT().toUser("OPENID").content("sfsfdsdf").build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"text\",\"text\":{\"content\":\"sfsfdsdf\"}}");
|
||||
}
|
||||
|
||||
public void testImageReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.CUSTOM_MSG_IMAGE);
|
||||
reply.setMediaId("MEDIA_ID");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
|
||||
public void testImageBuild() {
|
||||
WxCustomMessage reply = WxCustomMessage.IMAGE().toUser("OPENID").mediaId("MEDIA_ID").build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"image\",\"image\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
|
||||
public void testVoiceReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.CUSTOM_MSG_VOICE);
|
||||
reply.setMediaId("MEDIA_ID");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
|
||||
public void testVoiceBuild() {
|
||||
WxCustomMessage reply = WxCustomMessage.VOICE().toUser("OPENID").mediaId("MEDIA_ID").build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"voice\",\"voice\":{\"media_id\":\"MEDIA_ID\"}}");
|
||||
}
|
||||
|
||||
public void testVideoReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.CUSTOM_MSG_VIDEO);
|
||||
reply.setMediaId("MEDIA_ID");
|
||||
reply.setThumbMediaId("MEDIA_ID");
|
||||
reply.setTitle("TITLE");
|
||||
reply.setDescription("DESCRIPTION");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
|
||||
}
|
||||
|
||||
public void testVideoBuild() {
|
||||
WxCustomMessage reply = WxCustomMessage.VIDEO().toUser("OPENID").title("TITLE").mediaId("MEDIA_ID").thumbMediaId("MEDIA_ID").description("DESCRIPTION").build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"video\",\"video\":{\"media_id\":\"MEDIA_ID\",\"thumb_media_id\":\"MEDIA_ID\",\"title\":\"TITLE\",\"description\":\"DESCRIPTION\"}}");
|
||||
}
|
||||
|
||||
public void testMusicReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.CUSTOM_MSG_MUSIC);
|
||||
reply.setThumbMediaId("MEDIA_ID");
|
||||
reply.setDescription("DESCRIPTION");
|
||||
reply.setTitle("TITLE");
|
||||
reply.setMusicUrl("MUSIC_URL");
|
||||
reply.setHqMusicUrl("HQ_MUSIC_URL");
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
|
||||
}
|
||||
|
||||
public void testMusicBuild() {
|
||||
WxCustomMessage reply = WxCustomMessage.MUSIC()
|
||||
.toUser("OPENID")
|
||||
.title("TITLE")
|
||||
.thumbMediaId("MEDIA_ID")
|
||||
.description("DESCRIPTION")
|
||||
.musicUrl("MUSIC_URL")
|
||||
.hqMusicUrl("HQ_MUSIC_URL")
|
||||
.build();
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"music\",\"music\":{\"title\":\"TITLE\",\"description\":\"DESCRIPTION\",\"thumb_media_id\":\"MEDIA_ID\",\"musicurl\":\"MUSIC_URL\",\"hqmusicurl\":\"HQ_MUSIC_URL\"}}");
|
||||
}
|
||||
|
||||
public void testNewsReply() {
|
||||
WxCustomMessage reply = new WxCustomMessage();
|
||||
reply.setToUser("OPENID");
|
||||
reply.setMsgType(WxConsts.CUSTOM_MSG_NEWS);
|
||||
|
||||
WxArticle article1 = new WxArticle();
|
||||
article1.setUrl("URL");
|
||||
article1.setPicUrl("PIC_URL");
|
||||
article1.setDescription("Is Really A Happy Day");
|
||||
article1.setTitle("Happy Day");
|
||||
reply.getArticles().add(article1);
|
||||
|
||||
WxArticle article2 = new WxArticle();
|
||||
article2.setUrl("URL");
|
||||
article2.setPicUrl("PIC_URL");
|
||||
article2.setDescription("Is Really A Happy Day");
|
||||
article2.setTitle("Happy Day");
|
||||
reply.getArticles().add(article2);
|
||||
|
||||
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}");
|
||||
}
|
||||
|
||||
public void testNewsBuild() {
|
||||
WxArticle article1 = new WxArticle();
|
||||
article1.setUrl("URL");
|
||||
article1.setPicUrl("PIC_URL");
|
||||
article1.setDescription("Is Really A Happy Day");
|
||||
article1.setTitle("Happy Day");
|
||||
|
||||
WxArticle article2 = new WxArticle();
|
||||
article2.setUrl("URL");
|
||||
article2.setPicUrl("PIC_URL");
|
||||
article2.setDescription("Is Really A Happy Day");
|
||||
article2.setTitle("Happy Day");
|
||||
|
||||
WxCustomMessage reply = WxCustomMessage.NEWS().toUser("OPENID").addArticle(article1).addArticle(article2).build();
|
||||
|
||||
Assert.assertEquals(reply.toJson(), "{\"touser\":\"OPENID\",\"msgtype\":\"news\",\"articles\":[{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"},{\"title\":\"Happy Day\",\"description\":\"Is Really A Happy Day\",\"url\":\"URL\",\"picurl\":\"PIC_URL\"}]}");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.result.WxError;
|
||||
|
||||
@Test
|
||||
public class WxErrorTest {
|
||||
|
||||
public void testFromJson() {
|
||||
|
||||
String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\" }";
|
||||
WxError wxError = WxError.fromJson(json);
|
||||
Assert.assertTrue(wxError.getErrorCode() == 40003);
|
||||
Assert.assertEquals(wxError.getErrorMsg(), "invalid openid");
|
||||
|
||||
}
|
||||
|
||||
public void testFromBadJson1() {
|
||||
|
||||
String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\", \"media_id\": \"12323423dsfafsf232f\" }";
|
||||
WxError wxError = WxError.fromJson(json);
|
||||
Assert.assertTrue(wxError.getErrorCode() == 40003);
|
||||
Assert.assertEquals(wxError.getErrorMsg(), "invalid openid");
|
||||
|
||||
}
|
||||
|
||||
public void testFromBadJson2() {
|
||||
|
||||
String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}";
|
||||
WxError wxError = WxError.fromJson(json);
|
||||
Assert.assertTrue(wxError.getErrorCode() == 0);
|
||||
Assert.assertEquals(wxError.getErrorMsg(), null);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,112 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMenu;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxMenu.WxMenuButton;
|
||||
|
||||
@Test
|
||||
public class WxMenuTest {
|
||||
|
||||
@Test(dataProvider="wxReturnMenu")
|
||||
public void testFromJson(String json) {
|
||||
WxMenu menu = WxMenu.fromJson(json);
|
||||
Assert.assertEquals(menu.getButtons().size(), 3);
|
||||
}
|
||||
|
||||
@Test(dataProvider="wxPushMenu")
|
||||
public void testToJson(String json) {
|
||||
WxMenu menu = new WxMenu();
|
||||
WxMenuButton button1 = new WxMenuButton();
|
||||
button1.setType("click");
|
||||
button1.setName("今日歌曲");
|
||||
button1.setKey("V1001_TODAY_MUSIC");
|
||||
|
||||
WxMenuButton button2 = new WxMenuButton();
|
||||
button2.setType("click");
|
||||
button2.setName("歌手简介");
|
||||
button2.setKey("V1001_TODAY_SINGER");
|
||||
|
||||
WxMenuButton button3 = new WxMenuButton();
|
||||
button3.setName("菜单");
|
||||
|
||||
menu.getButtons().add(button1);
|
||||
menu.getButtons().add(button2);
|
||||
menu.getButtons().add(button3);
|
||||
|
||||
WxMenuButton button31 = new WxMenuButton();
|
||||
button31.setType("view");
|
||||
button31.setName("搜索");
|
||||
button31.setUrl("http://www.soso.com/");
|
||||
|
||||
WxMenuButton button32 = new WxMenuButton();
|
||||
button32.setType("view");
|
||||
button32.setName("视频");
|
||||
button32.setUrl("http://v.qq.com/");
|
||||
|
||||
WxMenuButton button33 = new WxMenuButton();
|
||||
button33.setType("click");
|
||||
button33.setName("赞一下我们");
|
||||
button33.setKey("V1001_GOOD");
|
||||
|
||||
button3.getSubButtons().add(button31);
|
||||
button3.getSubButtons().add(button32);
|
||||
button3.getSubButtons().add(button33);
|
||||
|
||||
Assert.assertEquals(menu.toJson(), json);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
public Object[][] wxReturnMenu() {
|
||||
Object[][] res = menuJson();
|
||||
String json = "{ \"menu\" : " + res[0][0] + " }";
|
||||
return new Object[][] {
|
||||
new Object[] { json }
|
||||
};
|
||||
}
|
||||
|
||||
@DataProvider(name="wxPushMenu")
|
||||
public Object[][] menuJson() {
|
||||
String json =
|
||||
"{"
|
||||
+"\"button\":["
|
||||
+"{"
|
||||
+"\"type\":\"click\","
|
||||
+"\"name\":\"今日歌曲\","
|
||||
+"\"key\":\"V1001_TODAY_MUSIC\""
|
||||
+"},"
|
||||
+"{"
|
||||
+"\"type\":\"click\","
|
||||
+"\"name\":\"歌手简介\","
|
||||
+"\"key\":\"V1001_TODAY_SINGER\""
|
||||
+"},"
|
||||
+"{"
|
||||
+"\"name\":\"菜单\","
|
||||
+"\"sub_button\":["
|
||||
+"{"
|
||||
+"\"type\":\"view\","
|
||||
+"\"name\":\"搜索\","
|
||||
+"\"url\":\"http://www.soso.com/\""
|
||||
+"},"
|
||||
+"{"
|
||||
+"\"type\":\"view\","
|
||||
+"\"name\":\"视频\","
|
||||
+"\"url\":\"http://v.qq.com/\""
|
||||
+"},"
|
||||
+"{"
|
||||
+"\"type\":\"click\","
|
||||
+"\"name\":\"赞一下我们\","
|
||||
+"\"key\":\"V1001_GOOD\""
|
||||
+"}"
|
||||
+"]"
|
||||
+"}"
|
||||
+"]"
|
||||
+"}";
|
||||
return new Object[][] {
|
||||
new Object[] { json }
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,92 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.api.WxConsts;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlMessageTest {
|
||||
|
||||
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>";
|
||||
WxXmlMessage wxMessage = WxXmlMessage.fromXml(xml);
|
||||
Assert.assertEquals(wxMessage.getToUserName(), "toUser");
|
||||
Assert.assertEquals(wxMessage.getFromUserName(), "fromUser");
|
||||
Assert.assertEquals(wxMessage.getCreateTime(), new Long(1348831860l));
|
||||
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");
|
||||
Assert.assertEquals(wxMessage.getMediaId(), "media_id");
|
||||
Assert.assertEquals(wxMessage.getFormat(), "Format");
|
||||
Assert.assertEquals(wxMessage.getThumbMediaId(), "thumb_media_id");
|
||||
Assert.assertEquals(wxMessage.getLocationX(), new Double(23.134521d));
|
||||
Assert.assertEquals(wxMessage.getLocationY(), new Double(113.358803d));
|
||||
Assert.assertEquals(wxMessage.getScale(), new Double(20));
|
||||
Assert.assertEquals(wxMessage.getLabel(), "位置信息");
|
||||
Assert.assertEquals(wxMessage.getDescription(), "公众平台官网链接");
|
||||
Assert.assertEquals(wxMessage.getUrl(), "url");
|
||||
Assert.assertEquals(wxMessage.getTitle(), "公众平台官网链接");
|
||||
Assert.assertEquals(wxMessage.getEvent(), "subscribe");
|
||||
Assert.assertEquals(wxMessage.getEventKey(), "qrscene_123123");
|
||||
Assert.assertEquals(wxMessage.getTicket(), "TICKET");
|
||||
Assert.assertEquals(wxMessage.getLatitude(), new Double(23.137466));
|
||||
Assert.assertEquals(wxMessage.getLongitude(), new Double(113.352425));
|
||||
Assert.assertEquals(wxMessage.getPrecision(), new Double(119.385040));
|
||||
Assert.assertEquals(wxMessage.getScanCodeInfo().getScanType(), "qrcode");
|
||||
Assert.assertEquals(wxMessage.getScanCodeInfo().getScanResult(), "1");
|
||||
Assert.assertEquals(wxMessage.getSendPicsInfo().getCount(), new Long(1l));
|
||||
Assert.assertEquals(wxMessage.getSendPicsInfo().getPicList().get(0).getPicMd5Sum(), "1b5f7c23b5bf75682a53e7b6d163e185");
|
||||
Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationX(), "23");
|
||||
Assert.assertEquals(wxMessage.getSendLocationInfo().getLocationY(), "113");
|
||||
Assert.assertEquals(wxMessage.getSendLocationInfo().getScale(), "15");
|
||||
Assert.assertEquals(wxMessage.getSendLocationInfo().getLabel(), " 广州市海珠区客村艺苑路 106号");
|
||||
Assert.assertEquals(wxMessage.getSendLocationInfo().getPoiname(), "wo de poi");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutImageMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlOutImageMessageTest {
|
||||
|
||||
public void test() {
|
||||
WxXmlOutImageMessage m = new WxXmlOutImageMessage();
|
||||
m.setMediaId("ddfefesfsdfef");
|
||||
m.setCreateTime(1122l);
|
||||
m.setFromUserName("from");
|
||||
m.setToUserName("to");
|
||||
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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", ""));
|
||||
}
|
||||
|
||||
public void testBuild() {
|
||||
WxXmlOutImageMessage m = WxXmlOutMessage.IMAGE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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>", "")
|
||||
);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMusicMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlOutMusicMessageTest {
|
||||
|
||||
public void test() {
|
||||
WxXmlOutMusicMessage m = new WxXmlOutMusicMessage();
|
||||
m.setTitle("title");
|
||||
m.setDescription("ddfff");
|
||||
m.setHqMusicUrl("hQMusicUrl");
|
||||
m.setMusicUrl("musicUrl");
|
||||
m.setThumbMediaId("thumbMediaId");
|
||||
m.setCreateTime(1122l);
|
||||
m.setFromUserName("fromUser");
|
||||
m.setToUserName("toUser");
|
||||
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[music]]></MsgType>"
|
||||
+ "<Music>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[ddfff]]></Description>"
|
||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>"
|
||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>"
|
||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>"
|
||||
+ " </Music>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
public void testBuild() {
|
||||
WxXmlOutMusicMessage m = WxXmlOutMessage.MUSIC()
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.title("title")
|
||||
.description("ddfff")
|
||||
.hqMusicUrl("hQMusicUrl")
|
||||
.musicUrl("musicUrl")
|
||||
.thumbMediaId("thumbMediaId")
|
||||
.build();
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[music]]></MsgType>"
|
||||
+ "<Music>"
|
||||
+ " <Title><![CDATA[title]]></Title>"
|
||||
+ " <Description><![CDATA[ddfff]]></Description>"
|
||||
+ " <ThumbMediaId><![CDATA[thumbMediaId]]></ThumbMediaId>"
|
||||
+ " <MusicUrl><![CDATA[musicUrl]]></MusicUrl>"
|
||||
+ " <HQMusicUrl><![CDATA[hQMusicUrl]]></HQMusicUrl>"
|
||||
+ " </Music>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMewsMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlOutNewsMessageTest {
|
||||
|
||||
public void test() {
|
||||
WxXmlOutMewsMessage m = new WxXmlOutMewsMessage();
|
||||
m.setCreateTime(1122l);
|
||||
m.setFromUserName("fromUser");
|
||||
m.setToUserName("toUser");
|
||||
|
||||
WxXmlOutMewsMessage.Item item = new WxXmlOutMewsMessage.Item();
|
||||
item.setDescription("description");
|
||||
item.setPicUrl("picUrl");
|
||||
item.setTitle("title");
|
||||
item.setUrl("url");
|
||||
m.addArticle(item);
|
||||
m.addArticle(item);
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[news]]></MsgType>"
|
||||
+ " <ArticleCount>2</ArticleCount>"
|
||||
+ " <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>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(m.toXml().replaceAll("\\s", ""), expected.replaceAll("\\s", ""));
|
||||
}
|
||||
|
||||
public void testBuild() {
|
||||
WxXmlOutMewsMessage.Item item = new WxXmlOutMewsMessage.Item();
|
||||
item.setDescription("description");
|
||||
item.setPicUrl("picUrl");
|
||||
item.setTitle("title");
|
||||
item.setUrl("url");
|
||||
|
||||
WxXmlOutMewsMessage m = WxXmlOutMessage.NEWS()
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.addArticle(item)
|
||||
.addArticle(item)
|
||||
.build();
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<xml>"
|
||||
+ "<ToUserName><![CDATA[toUser]]></ToUserName>"
|
||||
+ "<FromUserName><![CDATA[fromUser]]></FromUserName>"
|
||||
+ "<CreateTime>1122</CreateTime>"
|
||||
+ "<MsgType><![CDATA[news]]></MsgType>"
|
||||
+ " <ArticleCount>2</ArticleCount>"
|
||||
+ " <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>"
|
||||
+ "</xml>";
|
||||
System.out.println(m.toXml());
|
||||
Assert.assertEquals(
|
||||
m
|
||||
.toXml()
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", ""),
|
||||
expected
|
||||
.replaceAll("\\s", "")
|
||||
.replaceAll("<CreateTime>.*?</CreateTime>", "")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutTextMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlOutTextMessageTest {
|
||||
|
||||
public void test() {
|
||||
WxXmlOutTextMessage m = new WxXmlOutTextMessage();
|
||||
m.setContent("content");
|
||||
m.setCreateTime(1122l);
|
||||
m.setFromUserName("from");
|
||||
m.setToUserName("to");
|
||||
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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", ""));
|
||||
}
|
||||
|
||||
public void testBuild() {
|
||||
WxXmlOutTextMessage m = WxXmlOutMessage.TEXT().content("content").fromUser("from").toUser("to").build();
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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>", "")
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutVideoMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlOutVideoMessageTest {
|
||||
|
||||
public void test() {
|
||||
WxXmlOutVideoMessage m = new WxXmlOutVideoMessage();
|
||||
m.setMediaId("media_id");
|
||||
m.setTitle("title");
|
||||
m.setDescription("ddfff");
|
||||
m.setCreateTime(1122l);
|
||||
m.setFromUserName("fromUser");
|
||||
m.setToUserName("toUser");
|
||||
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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() {
|
||||
WxXmlOutVideoMessage m = WxXmlOutMessage.VIDEO()
|
||||
.mediaId("media_id")
|
||||
.fromUser("fromUser")
|
||||
.toUser("toUser")
|
||||
.title("title")
|
||||
.description("ddfff")
|
||||
.build();
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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>", "")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,52 @@
|
||||
package me.chanjar.weixin.mp.bean;
|
||||
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutVoiceMessage;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
@Test
|
||||
public class WxXmlOutVoiceMessageTest {
|
||||
|
||||
public void test() {
|
||||
WxXmlOutVoiceMessage m = new WxXmlOutVoiceMessage();
|
||||
m.setMediaId("ddfefesfsdfef");
|
||||
m.setCreateTime(1122l);
|
||||
m.setFromUserName("from");
|
||||
m.setToUserName("to");
|
||||
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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", ""));
|
||||
}
|
||||
|
||||
public void testBuild() {
|
||||
WxXmlOutVoiceMessage m = WxXmlOutMessage.VOICE().mediaId("ddfefesfsdfef").fromUser("from").toUser("to").build();
|
||||
String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>"
|
||||
+ "<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>", "")
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package me.chanjar.weixin.mp.demo;
|
||||
|
||||
import me.chanjar.weixin.mp.api.WxInMemoryConfigStorage;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import javax.xml.bind.JAXBContext;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import javax.xml.bind.Unmarshaller;
|
||||
import javax.xml.bind.annotation.XmlAccessType;
|
||||
import javax.xml.bind.annotation.XmlAccessorType;
|
||||
import javax.xml.bind.annotation.XmlRootElement;
|
||||
import java.io.InputStream;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
@XmlRootElement(name = "xml")
|
||||
@XmlAccessorType(XmlAccessType.FIELD)
|
||||
class WxTestConfigStorage extends WxInMemoryConfigStorage {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "SimpleWxConfigProvider [appId=" + appId + ", secret=" + secret + ", accessToken=" + accessToken
|
||||
+ ", expiresIn=" + expiresIn + ", token=" + token + ", aesKey=" + aesKey + "]";
|
||||
}
|
||||
|
||||
|
||||
public static WxTestConfigStorage fromXml(InputStream is) throws JAXBException {
|
||||
Unmarshaller um = JAXBContext.newInstance(WxTestConfigStorage.class).createUnmarshaller();
|
||||
InputSource inputSource = new InputSource(is);
|
||||
inputSource.setEncoding("utf-8");
|
||||
return (WxTestConfigStorage) um.unmarshal(inputSource);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package me.chanjar.weixin.mp.demo;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.servlet.ServletHandler;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxTestServer {
|
||||
public static void main(String[] args) throws Exception {
|
||||
Server server = new Server(8080);
|
||||
|
||||
ServletHandler handler = new ServletHandler();
|
||||
server.setHandler(handler);
|
||||
|
||||
handler.addServletWithMapping(WxTestServlet.class, "/*");
|
||||
server.start();
|
||||
server.join();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,117 @@
|
||||
package me.chanjar.weixin.mp.demo;
|
||||
|
||||
import me.chanjar.weixin.mp.api.*;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxXmlOutTextMessage;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import javax.xml.bind.JAXBException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxTestServlet extends HttpServlet {
|
||||
|
||||
protected WxService wxService;
|
||||
protected WxConfigStorage wxConfigStorage;
|
||||
protected WxMessageRouter wxMessageRouter;
|
||||
|
||||
@Override public void init() throws ServletException {
|
||||
//
|
||||
super.init();
|
||||
try {
|
||||
InputStream is1 = ClassLoader.getSystemResourceAsStream("test-config.xml");
|
||||
WxTestConfigStorage config = WxTestConfigStorage.fromXml(is1);
|
||||
|
||||
wxConfigStorage = config;
|
||||
wxService = new WxServiceImpl();
|
||||
wxService.setWxConfigStorage(config);
|
||||
|
||||
WxMessageHandler handler = new WxMessageHandler() {
|
||||
@Override public WxXmlOutMessage handle(WxXmlMessage wxMessage, Map<String, Object> context) {
|
||||
WxXmlOutTextMessage m
|
||||
= WxXmlOutMessage.TEXT().content("测试加密消息").fromUser(wxMessage.getToUserName())
|
||||
.toUser(wxMessage.getFromUserName()).build();
|
||||
return m;
|
||||
}
|
||||
};
|
||||
|
||||
wxMessageRouter = new WxMessageRouter();
|
||||
wxMessageRouter
|
||||
.rule()
|
||||
.async(false)
|
||||
.content("哈哈") // 拦截内容为“哈哈”的消息
|
||||
.handler(handler)
|
||||
.end();
|
||||
|
||||
} catch (JAXBException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
@Override protected void service(HttpServletRequest request, HttpServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
|
||||
String signature = request.getParameter("signature");
|
||||
String nonce = request.getParameter("nonce");
|
||||
String timestamp = request.getParameter("timestamp");
|
||||
|
||||
response.setContentType("text/html;charset=utf-8");
|
||||
response.setStatus(HttpServletResponse.SC_OK);
|
||||
|
||||
if (!wxService.checkSignature(timestamp, nonce, signature)) {
|
||||
// 消息签名不正确,说明不是公众平台发过来的消息
|
||||
response.getWriter().println("非法请求");
|
||||
return;
|
||||
}
|
||||
|
||||
String echostr = request.getParameter("echostr");
|
||||
if (StringUtils.isNotBlank(echostr)) {
|
||||
// 说明是一个仅仅用来验证的请求,回显echostr
|
||||
response.getWriter().println(echostr);
|
||||
return;
|
||||
}
|
||||
|
||||
String encryptType = StringUtils.isBlank(request.getParameter("encrypt_type")) ?
|
||||
"raw" :
|
||||
request.getParameter("encrypt_type");
|
||||
|
||||
WxXmlMessage inMessage = null;
|
||||
|
||||
if ("raw".equals(encryptType)) {
|
||||
// 明文传输的消息
|
||||
inMessage = WxXmlMessage.fromXml(request.getInputStream());
|
||||
} else if ("aes".equals(encryptType)) {
|
||||
// 是aes加密的消息
|
||||
String msgSignature = request.getParameter("msg_signature");
|
||||
inMessage = WxXmlMessage.fromEncryptedXml(
|
||||
request.getInputStream(),
|
||||
wxConfigStorage,
|
||||
timestamp, nonce, msgSignature);
|
||||
} else {
|
||||
response.getWriter().println("不可识别的加密类型");
|
||||
return;
|
||||
}
|
||||
|
||||
WxXmlOutMessage outMessage = wxMessageRouter.route(inMessage);
|
||||
|
||||
if (outMessage != null) {
|
||||
if ("raw".equals(encryptType)) {
|
||||
response.getWriter().write(outMessage.toXml());
|
||||
} else if ("aes".equals(encryptType)) {
|
||||
response.getWriter().write(outMessage.toEncryptedXml(wxConfigStorage));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,95 @@
|
||||
package me.chanjar.weixin.mp.util.crypto;
|
||||
|
||||
import me.chanjar.weixin.mp.util.crypto.WxCryptUtil;
|
||||
import org.testng.annotations.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.w3c.dom.Element;
|
||||
import org.w3c.dom.NodeList;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.SAXException;
|
||||
|
||||
import javax.xml.parsers.DocumentBuilder;
|
||||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import javax.xml.parsers.ParserConfigurationException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringReader;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
|
||||
@Test
|
||||
public class WxCryptUtilTest {
|
||||
String encodingAesKey = "abcdefghijklmnopqrstuvwxyz0123456789ABCDEFG";
|
||||
String token = "pamtest";
|
||||
String timestamp = "1409304348";
|
||||
String nonce = "xxxxxx";
|
||||
String appId = "wxb11529c136998cb6";
|
||||
String randomStr = "aaaabbbbccccdddd";
|
||||
|
||||
String xmlFormat = "<xml><ToUserName><![CDATA[toUser]]></ToUserName><Encrypt><![CDATA[%1$s]]></Encrypt></xml>";
|
||||
String replyMsg = "我是中文abcd123";
|
||||
|
||||
String afterAesEncrypt = "jn1L23DB+6ELqJ+6bruv21Y6MD7KeIfP82D6gU39rmkgczbWwt5+3bnyg5K55bgVtVzd832WzZGMhkP72vVOfg==";
|
||||
|
||||
String replyMsg2 = "<xml><ToUserName><![CDATA[oia2Tj我是中文jewbmiOUlr6X-1crbLOvLw]]></ToUserName><FromUserName><![CDATA[gh_7f083739789a]]></FromUserName><CreateTime>1407743423</CreateTime><MsgType><![CDATA[video]]></MsgType><Video><MediaId><![CDATA[eYJ1MbwPRJtOvIEabaxHs7TX2D-HV71s79GUxqdUkjm6Gs2Ed1KF3ulAOA9H1xG0]]></MediaId><Title><![CDATA[testCallBackReplyVideo]]></Title><Description><![CDATA[testCallBackReplyVideo]]></Description></Video></xml>";
|
||||
String afterAesEncrypt2 = "jn1L23DB+6ELqJ+6bruv23M2GmYfkv0xBh2h+XTBOKVKcgDFHle6gqcZ1cZrk3e1qjPQ1F4RsLWzQRG9udbKWesxlkupqcEcW7ZQweImX9+wLMa0GaUzpkycA8+IamDBxn5loLgZpnS7fVAbExOkK5DYHBmv5tptA9tklE/fTIILHR8HLXa5nQvFb3tYPKAlHF3rtTeayNf0QuM+UW/wM9enGIDIJHF7CLHiDNAYxr+r+OrJCmPQyTy8cVWlu9iSvOHPT/77bZqJucQHQ04sq7KZI27OcqpQNSto2OdHCoTccjggX5Z9Mma0nMJBU+jLKJ38YB1fBIz+vBzsYjrTmFQ44YfeEuZ+xRTQwr92vhA9OxchWVINGC50qE/6lmkwWTwGX9wtQpsJKhP+oS7rvTY8+VdzETdfakjkwQ5/Xka042OlUb1/slTwo4RscuQ+RdxSGvDahxAJ6+EAjLt9d8igHngxIbf6YyqqROxuxqIeIch3CssH/LqRs+iAcILvApYZckqmA7FNERspKA5f8GoJ9sv8xmGvZ9Yrf57cExWtnX8aCMMaBropU/1k+hKP5LVdzbWCG0hGwx/dQudYR/eXp3P0XxjlFiy+9DMlaFExWUZQDajPkdPrEeOwofJb";
|
||||
|
||||
public void testNormal() throws ParserConfigurationException, SAXException, IOException {
|
||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
|
||||
String encryptedXml = pc.encrypt(replyMsg);
|
||||
|
||||
System.out.println(encryptedXml);
|
||||
|
||||
DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
|
||||
Document document = documentBuilder.parse(new InputSource(new StringReader(encryptedXml)));
|
||||
|
||||
Element root = document.getDocumentElement();
|
||||
String cipherText = root.getElementsByTagName("Encrypt").item(0).getTextContent();
|
||||
String msgSignature = root.getElementsByTagName("MsgSignature").item(0).getTextContent();
|
||||
String timestamp = root.getElementsByTagName("TimeStamp").item(0).getTextContent();
|
||||
String nonce = root.getElementsByTagName("Nonce").item(0).getTextContent();
|
||||
|
||||
String messageText = String.format(xmlFormat, cipherText);
|
||||
|
||||
// 第三方收到公众号平台发送的消息
|
||||
String plainMessage = pc.decrypt(cipherText);
|
||||
|
||||
System.out.println(plainMessage);
|
||||
assertEquals(plainMessage, replyMsg);
|
||||
}
|
||||
|
||||
public void testAesEncrypt() {
|
||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
|
||||
assertEquals(pc.encrypt(randomStr, replyMsg), afterAesEncrypt);
|
||||
}
|
||||
|
||||
public void testAesEncrypt2() {
|
||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
|
||||
assertEquals(pc.encrypt(randomStr, replyMsg2), afterAesEncrypt2);
|
||||
}
|
||||
|
||||
public void testValidateSignatureError() throws ParserConfigurationException, SAXException,
|
||||
IOException {
|
||||
try {
|
||||
WxCryptUtil pc = new WxCryptUtil(token, encodingAesKey, appId);
|
||||
String afterEncrpt = pc.encrypt(replyMsg);
|
||||
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
|
||||
DocumentBuilder db = dbf.newDocumentBuilder();
|
||||
StringReader sr = new StringReader(afterEncrpt);
|
||||
InputSource is = new InputSource(sr);
|
||||
Document document = db.parse(is);
|
||||
|
||||
Element root = document.getDocumentElement();
|
||||
NodeList nodelist1 = root.getElementsByTagName("Encrypt");
|
||||
|
||||
String encrypt = nodelist1.item(0).getTextContent();
|
||||
String fromXML = String.format(xmlFormat, encrypt);
|
||||
pc.decrypt("12345", timestamp, nonce, fromXML); // 这里签名错误
|
||||
} catch (RuntimeException e) {
|
||||
assertEquals(e.getMessage(), "加密消息签名校验失败");
|
||||
return;
|
||||
}
|
||||
fail("错误流程不抛出异常???");
|
||||
}
|
||||
|
||||
}
|
||||
BIN
weixin-java-mp/src/test/resources/mm.jpeg
Normal file
BIN
weixin-java-mp/src/test/resources/mm.jpeg
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 14 KiB |
BIN
weixin-java-mp/src/test/resources/mm.mp3
Normal file
BIN
weixin-java-mp/src/test/resources/mm.mp3
Normal file
Binary file not shown.
BIN
weixin-java-mp/src/test/resources/mm.mp4
Normal file
BIN
weixin-java-mp/src/test/resources/mm.mp4
Normal file
Binary file not shown.
9
weixin-java-mp/src/test/resources/test-config.sample.xml
Normal file
9
weixin-java-mp/src/test/resources/test-config.sample.xml
Normal file
@@ -0,0 +1,9 @@
|
||||
<xml>
|
||||
<appId>公众号appID</appId>
|
||||
<secret>公众号appsecret</secret>
|
||||
<token>公众号Token</token>
|
||||
<aesKey>公众号EncodingAESKey</aesKey>
|
||||
<accessToken>可以不填写</accessToken>
|
||||
<expiresIn>可以不填写</expiresIn>
|
||||
<openId>某个加你公众号的用户的openId</openId>
|
||||
</xml>
|
||||
35
weixin-java-mp/src/test/resources/testng.xml
Normal file
35
weixin-java-mp/src/test/resources/testng.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<!DOCTYPE suite SYSTEM "http://testng.org/testng-1.0.dtd" >
|
||||
|
||||
<suite name="Weixin-java-tool-suite" verbose="1">
|
||||
<test name="API_Test">
|
||||
<classes>
|
||||
<class name="me.chanjar.weixin.mp.api.WxBaseAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxCustomMessageAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMenuAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxGroupAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMassMessageAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMediaAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxUserAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxQrCodeAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxShortUrlAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMessageRouterTest" />
|
||||
</classes>
|
||||
</test>
|
||||
|
||||
<test name="Bean_Test">
|
||||
<classes>
|
||||
<class name="me.chanjar.weixin.mp.bean.WxAccessTokenTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxCustomMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxErrorTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxMenuTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutImageMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutMusicMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutNewsMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutVideoMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutVoiceMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.bean.WxXmlOutTextMessageTest" />
|
||||
<class name="me.chanjar.weixin.mp.util.crypto.WxCryptUtilTest" />
|
||||
</classes>
|
||||
</test>
|
||||
</suite>
|
||||
Reference in New Issue
Block a user