mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-24 13:03:46 +08:00
issue #1 添加分组管理接口-移动用户分组
This commit is contained in:
@@ -189,6 +189,16 @@ public interface WxService {
|
|||||||
*/
|
*/
|
||||||
public WxGroup groupCreate(String name) throws WxErrorException;
|
public WxGroup groupCreate(String name) throws WxErrorException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 分组管理接口 - 查询所有分组
|
||||||
|
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||||
|
* </pre>
|
||||||
|
* @return
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
public List<WxGroup> groupGet() throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 分组管理接口 - 查询用户所在分组
|
* 分组管理接口 - 查询用户所在分组
|
||||||
@@ -213,14 +223,17 @@ public interface WxService {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 分组管理接口 - 查询所有分组
|
* 分组管理接口 - 移动用户分组
|
||||||
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
|
||||||
|
*
|
||||||
|
* 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
|
||||||
* </pre>
|
* </pre>
|
||||||
* @return
|
* @param openid 用户openid
|
||||||
|
* @param to_groupid 移动到的分组id
|
||||||
* @throws WxErrorException
|
* @throws WxErrorException
|
||||||
*/
|
*/
|
||||||
public List<WxGroup> groupGet() throws WxErrorException;
|
public void groupMoveUser(String openid, long to_groupid) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 注入 {@link WxConfigStorage} 的实现
|
* 注入 {@link WxConfigStorage} 的实现
|
||||||
* @param wxConfigProvider
|
* @param wxConfigProvider
|
||||||
|
@@ -226,6 +226,11 @@ public class WxServiceImpl implements WxService {
|
|||||||
execute(new SimplePostRequestExecutor(), url, group.toJson());
|
execute(new SimplePostRequestExecutor(), url, group.toJson());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void groupMoveUser(String openid, long to_groupid) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/cgi-bin/groups/members/update";
|
||||||
|
execute(new SimplePostRequestExecutor(), url, MessageFormat.format("'{'\"openid\":\"{0}\", \"to_groupid\":{1,number,#}}", openid, to_groupid));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
||||||
* @param executor
|
* @param executor
|
||||||
|
@@ -9,7 +9,7 @@ import chanjarster.weixin.util.json.WxGsonBuilder;
|
|||||||
*/
|
*/
|
||||||
public class WxGroup {
|
public class WxGroup {
|
||||||
|
|
||||||
private long id;
|
private long id = -1;
|
||||||
private String name;
|
private String name;
|
||||||
private long count;
|
private long count;
|
||||||
public long getId() {
|
public long getId() {
|
||||||
|
@@ -24,6 +24,8 @@ public class WxGroupAPITest {
|
|||||||
@Inject
|
@Inject
|
||||||
protected WxServiceImpl wxService;
|
protected WxServiceImpl wxService;
|
||||||
|
|
||||||
|
protected WxGroup group;
|
||||||
|
|
||||||
public void testGroupCreate() throws WxErrorException {
|
public void testGroupCreate() throws WxErrorException {
|
||||||
WxGroup res = wxService.groupCreate("测试分组1");
|
WxGroup res = wxService.groupCreate("测试分组1");
|
||||||
Assert.assertEquals(res.getName(), "测试分组1");
|
Assert.assertEquals(res.getName(), "测试分组1");
|
||||||
@@ -35,7 +37,7 @@ public class WxGroupAPITest {
|
|||||||
Assert.assertNotNull(groupList);
|
Assert.assertNotNull(groupList);
|
||||||
Assert.assertTrue(groupList.size() > 0);
|
Assert.assertTrue(groupList.size() > 0);
|
||||||
for (WxGroup g : groupList) {
|
for (WxGroup g : groupList) {
|
||||||
System.out.println(g.toString());
|
group = g;
|
||||||
Assert.assertNotNull(g.getName());
|
Assert.assertNotNull(g.getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -44,12 +46,18 @@ public class WxGroupAPITest {
|
|||||||
public void testGroupQueryUserGroup() throws WxErrorException {
|
public void testGroupQueryUserGroup() throws WxErrorException {
|
||||||
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||||
long groupid = wxService.groupQueryUserGroup(configStorage.getOpenId());
|
long groupid = wxService.groupQueryUserGroup(configStorage.getOpenId());
|
||||||
|
Assert.assertTrue(groupid != -1l);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
|
||||||
public void getGroupUpdate() throws WxErrorException {
|
public void getGroupUpdate() throws WxErrorException {
|
||||||
WxGroup group = new WxGroup();
|
group.setName("分组改名");
|
||||||
group.setId(3);
|
|
||||||
group.setName("未命名分组");
|
|
||||||
wxService.groupUpdate(group);
|
wxService.groupUpdate(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
|
||||||
|
public void getGroupMoveUser() throws WxErrorException {
|
||||||
|
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||||
|
wxService.groupMoveUser(configStorage.getOpenId(), group.getId());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user