diff --git a/src/main/java/chanjarster/weixin/api/WxService.java b/src/main/java/chanjarster/weixin/api/WxService.java index 4f6e30b15..c2f1ee38d 100644 --- a/src/main/java/chanjarster/weixin/api/WxService.java +++ b/src/main/java/chanjarster/weixin/api/WxService.java @@ -189,6 +189,16 @@ public interface WxService { */ public WxGroup groupCreate(String name) throws WxErrorException; + /** + *
+ * 分组管理接口 - 查询所有分组 + * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 + *+ * @return + * @throws WxErrorException + */ + public List
* 分组管理接口 - 查询用户所在分组
@@ -213,14 +223,17 @@ public interface WxService {
/**
*
- * 分组管理接口 - 查询所有分组
+ * 分组管理接口 - 移动用户分组
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
+ *
+ * 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
*
- * @return
+ * @param openid 用户openid
+ * @param to_groupid 移动到的分组id
* @throws WxErrorException
*/
- public List groupGet() throws WxErrorException;
-
+ public void groupMoveUser(String openid, long to_groupid) throws WxErrorException;
+
/**
* 注入 {@link WxConfigStorage} 的实现
* @param wxConfigProvider
diff --git a/src/main/java/chanjarster/weixin/api/WxServiceImpl.java b/src/main/java/chanjarster/weixin/api/WxServiceImpl.java
index ee8440038..f414e0c44 100644
--- a/src/main/java/chanjarster/weixin/api/WxServiceImpl.java
+++ b/src/main/java/chanjarster/weixin/api/WxServiceImpl.java
@@ -226,6 +226,11 @@ public class WxServiceImpl implements WxService {
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过期时才去刷新,然后重新执行请求,而不是全局定时请求
* @param executor
diff --git a/src/main/java/chanjarster/weixin/bean/WxGroup.java b/src/main/java/chanjarster/weixin/bean/WxGroup.java
index cc72c56bc..5ff232156 100644
--- a/src/main/java/chanjarster/weixin/bean/WxGroup.java
+++ b/src/main/java/chanjarster/weixin/bean/WxGroup.java
@@ -9,7 +9,7 @@ import chanjarster.weixin.util.json.WxGsonBuilder;
*/
public class WxGroup {
- private long id;
+ private long id = -1;
private String name;
private long count;
public long getId() {
diff --git a/src/test/java/chanjarster/weixin/api/WxGroupAPITest.java b/src/test/java/chanjarster/weixin/api/WxGroupAPITest.java
index 9542759cb..d592c5e0c 100644
--- a/src/test/java/chanjarster/weixin/api/WxGroupAPITest.java
+++ b/src/test/java/chanjarster/weixin/api/WxGroupAPITest.java
@@ -24,6 +24,8 @@ 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");
@@ -35,7 +37,7 @@ public class WxGroupAPITest {
Assert.assertNotNull(groupList);
Assert.assertTrue(groupList.size() > 0);
for (WxGroup g : groupList) {
- System.out.println(g.toString());
+ group = g;
Assert.assertNotNull(g.getName());
}
}
@@ -44,12 +46,18 @@ public class WxGroupAPITest {
public void testGroupQueryUserGroup() throws WxErrorException {
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
long groupid = wxService.groupQueryUserGroup(configStorage.getOpenId());
+ Assert.assertTrue(groupid != -1l);
}
+ @Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
public void getGroupUpdate() throws WxErrorException {
- WxGroup group = new WxGroup();
- group.setId(3);
- group.setName("未命名分组");
+ group.setName("分组改名");
wxService.groupUpdate(group);
}
+
+ @Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
+ public void getGroupMoveUser() throws WxErrorException {
+ WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
+ wxService.groupMoveUser(configStorage.getOpenId(), group.getId());
+ }
}