mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-12 11:30:03 +08:00
重构代码,将用户管理、分组管理以及二维码相关的接口分别移到单独类中管理
This commit is contained in:
@@ -63,7 +63,7 @@ public class WxMpMassMessageAPITest {
|
||||
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
|
||||
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());
|
||||
massMessage.setGroupId(wxService.getGroupService().groupGet().get(0).getId());
|
||||
|
||||
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
@@ -75,7 +75,7 @@ public class WxMpMassMessageAPITest {
|
||||
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
|
||||
massMessage.setMsgtype(massMsgType);
|
||||
massMessage.setMediaId(mediaId);
|
||||
massMessage.setGroupId(wxService.groupGet().get(0).getId());
|
||||
massMessage.setGroupId(wxService.getGroupService().groupGet().get(0).getId());
|
||||
|
||||
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
|
||||
Assert.assertNotNull(massResult);
|
||||
|
||||
@@ -1,37 +1,19 @@
|
||||
package me.chanjar.weixin.mp.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.common.session.WxSession;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassGroupMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassNews;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
|
||||
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.DataProvider;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "miscAPI", dependsOnGroups = { "baseAPI"})
|
||||
@Test(groups = "miscAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpMiscAPITest {
|
||||
|
||||
@@ -46,24 +28,4 @@ public class WxMpMiscAPITest {
|
||||
Assert.assertNotEquals(ipArray.length, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserSummary() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserSummary> summaries = wxService.getUserSummary(beginDate, endDate);
|
||||
System.out.println(summaries);
|
||||
Assert.assertNotNull(summaries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserCumulate() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserCumulate> cumulates = wxService.getUserCumulate(beginDate, endDate);
|
||||
System.out.println(cumulates);
|
||||
Assert.assertNotNull(cumulates);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
* @author chanjarster
|
||||
*
|
||||
*/
|
||||
@Test(groups = "userAPI", dependsOnGroups = { "baseAPI", "groupAPI" })
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpUserAPITest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testUserUpdateRemark() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
wxService.userUpdateRemark(configProvider.getOpenId(), "测试备注名");
|
||||
}
|
||||
|
||||
public void testUserInfo() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
WxMpUser user = wxService.userInfo(configProvider.getOpenId(), null);
|
||||
Assert.assertNotNull(user);
|
||||
}
|
||||
|
||||
public void testUserList() throws WxErrorException {
|
||||
WxMpUserList wxMpUserList = wxService.userList(null);
|
||||
Assert.assertNotNull(wxMpUserList);
|
||||
Assert.assertFalse(wxMpUserList.getCount() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getTotal() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getOpenIds().size() == -1);
|
||||
}
|
||||
|
||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
long groupid = wxService.userGetGroup(configStorage.getOpenId());
|
||||
Assert.assertTrue(groupid != -1l);
|
||||
}
|
||||
|
||||
public void getGroupMoveUser() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.wxMpConfigStorage;
|
||||
wxService.userUpdateGroup(configStorage.getOpenId(), wxService.groupGet().get(3).getId());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.WxMpGroup;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
@@ -14,9 +16,9 @@ import java.util.List;
|
||||
*
|
||||
* @author chanjarster
|
||||
*/
|
||||
@Test(groups = "groupAPI", dependsOnGroups = "baseAPI")
|
||||
@Test(groups = "groupAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpGroupAPITest {
|
||||
public class WxMpGroupServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
@@ -24,13 +26,13 @@ public class WxMpGroupAPITest {
|
||||
protected WxMpGroup group;
|
||||
|
||||
public void testGroupCreate() throws WxErrorException {
|
||||
WxMpGroup res = wxService.groupCreate("测试分组1");
|
||||
WxMpGroup res = this.wxService.getGroupService().groupCreate("测试分组1");
|
||||
Assert.assertEquals(res.getName(), "测试分组1");
|
||||
}
|
||||
|
||||
@Test(dependsOnMethods="testGroupCreate")
|
||||
public void testGroupGet() throws WxErrorException {
|
||||
List<WxMpGroup> groupList = wxService.groupGet();
|
||||
List<WxMpGroup> groupList = this.wxService.getGroupService().groupGet();
|
||||
Assert.assertNotNull(groupList);
|
||||
Assert.assertTrue(groupList.size() > 0);
|
||||
for (WxMpGroup g : groupList) {
|
||||
@@ -42,7 +44,7 @@ public class WxMpGroupAPITest {
|
||||
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
|
||||
public void getGroupUpdate() throws WxErrorException {
|
||||
group.setName("分组改名");
|
||||
wxService.groupUpdate(group);
|
||||
this.wxService.getGroupService().groupUpdate(group);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package me.chanjar.weixin.mp.api;
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
@@ -16,35 +18,39 @@ import java.io.File;
|
||||
*/
|
||||
@Test(groups = "qrCodeAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpQrCodeAPITest {
|
||||
public class WxMpQrCodeServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testQrCodeCreateTmpTicket() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateTmpTicket(1, null);
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() != -1);
|
||||
System.out.println(ticket);
|
||||
}
|
||||
|
||||
public void testQrCodeCreateLastTicket() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() == -1);
|
||||
System.out.println(ticket);
|
||||
}
|
||||
|
||||
public void testQrCodePicture() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
File file = this.wxService.qrCodePicture(ticket);
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
|
||||
File file = this.wxService.getQrcodeService().qrCodePicture(ticket);
|
||||
Assert.assertNotNull(file);
|
||||
System.out.println(file.getAbsolutePath());
|
||||
}
|
||||
|
||||
public void testQrCodePictureUrl() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
String url = this.wxService.qrCodePictureUrl(ticket.getTicket());
|
||||
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
|
||||
String url = this.wxService.getQrcodeService().qrCodePictureUrl(ticket.getTicket());
|
||||
Assert.assertNotNull(url);
|
||||
System.out.println(url);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,85 @@
|
||||
package me.chanjar.weixin.mp.api.impl;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
import me.chanjar.weixin.common.exception.WxErrorException;
|
||||
import me.chanjar.weixin.mp.api.ApiTestModule;
|
||||
import me.chanjar.weixin.mp.api.WxMpServiceImpl;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUser;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserCumulate;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserList;
|
||||
import me.chanjar.weixin.mp.bean.result.WxMpUserSummary;
|
||||
import org.testng.Assert;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 测试用户相关的接口
|
||||
*
|
||||
* @author chanjarster
|
||||
* @author Binary Wang
|
||||
*/
|
||||
@Test(groups = "userAPI")
|
||||
@Guice(modules = ApiTestModule.class)
|
||||
public class WxMpUserServiceImplTest {
|
||||
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testUserUpdateRemark() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
this.wxService.getUserService().userUpdateRemark(configProvider.getOpenId(), "测试备注名");
|
||||
}
|
||||
|
||||
public void testUserInfo() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
WxMpUser user = this.wxService.getUserService().userInfo(configProvider.getOpenId(), null);
|
||||
Assert.assertNotNull(user);
|
||||
System.out.println(user);
|
||||
}
|
||||
|
||||
public void testUserList() throws WxErrorException {
|
||||
WxMpUserList wxMpUserList = this.wxService.getUserService().userList(null);
|
||||
Assert.assertNotNull(wxMpUserList);
|
||||
Assert.assertFalse(wxMpUserList.getCount() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getTotal() == -1);
|
||||
Assert.assertFalse(wxMpUserList.getOpenIds().size() == -1);
|
||||
System.out.println(wxMpUserList);
|
||||
}
|
||||
|
||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenId());
|
||||
Assert.assertTrue(groupid != -1l);
|
||||
}
|
||||
|
||||
public void testGroupMoveUser() throws WxErrorException {
|
||||
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
|
||||
this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenId(), this.wxService.getGroupService().groupGet().get(3).getId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserSummary() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserSummary> summaries = this.wxService.getUserService().dataCubeUserSummary(beginDate, endDate);
|
||||
Assert.assertNotNull(summaries);
|
||||
System.out.println(summaries);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetUserCumulate() throws WxErrorException, ParseException {
|
||||
SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
|
||||
Date beginDate = simpleDateFormat.parse("2015-01-01");
|
||||
Date endDate = simpleDateFormat.parse("2015-01-02");
|
||||
List<WxMpUserCumulate> cumulates = this.wxService.getUserService().dataCubeUserCumulate(beginDate, endDate);
|
||||
Assert.assertNotNull(cumulates);
|
||||
System.out.println(cumulates);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,10 +7,10 @@
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpBaseAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpCustomMessageAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpMenuAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpGroupAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpGroupServiceImplTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpMassMessageAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpUserAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpQrCodeAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpUserServiceImplTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.impl.WxMpQrCodeServiceImplTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpShortUrlAPITest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpMessageRouterTest" />
|
||||
<class name="me.chanjar.weixin.mp.api.WxMpJsAPITest" />
|
||||
|
||||
Reference in New Issue
Block a user