From 1352385328f133796d1a56d163c51ef493ab1009 Mon Sep 17 00:00:00 2001 From: BinaryWang Date: Wed, 28 Sep 2016 18:47:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=A7=BB=E9=99=A4Group=E7=9B=B8=E5=85=B3?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin/mp/api/WxMpGroupService.java | 71 ---------------- .../me/chanjar/weixin/mp/api/WxMpService.java | 8 -- .../mp/api/impl/WxMpGroupServiceImpl.java | 84 ------------------- .../weixin/mp/api/impl/WxMpServiceImpl.java | 70 ++++------------ .../mp/api/impl/WxMpGroupServiceImplTest.java | 62 -------------- weixin-java-mp/src/test/resources/testng.xml | 3 - 6 files changed, 16 insertions(+), 282 deletions(-) delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGroupService.java delete mode 100644 weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java delete mode 100644 weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGroupService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGroupService.java deleted file mode 100644 index 22255d36..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGroupService.java +++ /dev/null @@ -1,71 +0,0 @@ -package me.chanjar.weixin.mp.api; - -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.mp.bean.WxMpGroup; - -import java.util.List; - -/** - * 用户分组相关操作接口 - * @author Binary Wang - * 分组接口属于老接口,不知道啥时候被替换成用户标签接口 - * - */ -@Deprecated -public interface WxMpGroupService { - - - /** - *
-   * 分组管理接口 - 创建分组
-   * 最多支持创建500个分组
-   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   * 
- * - * @param name 分组名字(30个字符以内) - */ - WxMpGroup groupCreate(String name) throws WxErrorException; - - /** - *
-   * 分组管理接口 - 查询所有分组
-   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   * 
- */ - List groupGet() throws WxErrorException; - - /** - *
-   * 分组管理接口 - 查询用户所在分组
-   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   * 
- * - * @param openid 微信用户的openid - */ - long userGetGroup(String openid) throws WxErrorException; - - /** - *
-   * 分组管理接口 - 修改分组名
-   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   *
-   * 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
-   * 
- * - * @param group 要更新的group,group的id,name必须设置 - */ - void groupUpdate(WxMpGroup group) throws WxErrorException; - - /** - *
-   * 分组管理接口 - 移动用户分组
-   * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口
-   *
-   * 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误
-   * 
- * - * @param openid 用户openid - * @param to_groupid 移动到的分组id - */ - void userUpdateGroup(String openid, long to_groupid) throws WxErrorException; -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java index 3b7f2125..5eca1192 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java @@ -322,14 +322,6 @@ public interface WxMpService { */ WxMpUserService getUserService(); - /** - * 返回用户分组相关接口方法的实现类对象,以方便调用个其各种接口 - * - * @return WxMpGroupService - */ - - WxMpGroupService getGroupService(); - /** * 返回用户标签相关接口方法的实现类对象,以方便调用个其各种接口 * diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java deleted file mode 100644 index bfceff61..00000000 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImpl.java +++ /dev/null @@ -1,84 +0,0 @@ -package me.chanjar.weixin.mp.api.impl; - -import com.google.gson.JsonElement; -import com.google.gson.JsonObject; -import com.google.gson.JsonParser; -import com.google.gson.reflect.TypeToken; -import me.chanjar.weixin.common.exception.WxErrorException; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; -import me.chanjar.weixin.common.util.json.GsonHelper; -import me.chanjar.weixin.mp.api.WxMpGroupService; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.bean.WxMpGroup; -import me.chanjar.weixin.mp.util.json.WxMpGsonBuilder; - -import java.util.List; - -/** - * Created by Binary Wang on 2016/7/21. - */ -@Deprecated -public class WxMpGroupServiceImpl implements WxMpGroupService { - private static final String API_URL_PREFIX = "https://api.weixin.qq.com/cgi-bin/groups"; - private WxMpService wxMpService; - - public WxMpGroupServiceImpl(WxMpService wxMpService) { - this.wxMpService = wxMpService; - } - - @Override - public WxMpGroup groupCreate(String name) throws WxErrorException { - String url = API_URL_PREFIX + "/create"; - JsonObject json = new JsonObject(); - JsonObject groupJson = new JsonObject(); - json.add("group", groupJson); - groupJson.addProperty("name", name); - - String responseContent = this.wxMpService.execute( - new SimplePostRequestExecutor(), - url, - json.toString()); - return WxMpGroup.fromJson(responseContent); - } - - @Override - public List groupGet() throws WxErrorException { - String url = API_URL_PREFIX + "/get"; - String responseContent = this.wxMpService.execute(new SimpleGetRequestExecutor(), url, null); - /* - * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} } - * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] } - */ - JsonElement tmpJsonElement = new JsonParser().parse(responseContent); - return WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), - new TypeToken>() { - }.getType()); - } - - @Override - public long userGetGroup(String openid) throws WxErrorException { - String url = API_URL_PREFIX + "/getid"; - JsonObject o = new JsonObject(); - o.addProperty("openid", openid); - String responseContent = this.wxMpService.execute(new SimplePostRequestExecutor(), url, o.toString()); - JsonElement tmpJsonElement = new JsonParser().parse(responseContent); - return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid")); - } - - @Override - public void groupUpdate(WxMpGroup group) throws WxErrorException { - String url = API_URL_PREFIX + "/update"; - this.wxMpService.execute(new SimplePostRequestExecutor(), url, group.toJson()); - } - - @Override - public void userUpdateGroup(String openid, long to_groupid) throws WxErrorException { - String url = API_URL_PREFIX + "/members/update"; - JsonObject json = new JsonObject(); - json.addProperty("openid", openid); - json.addProperty("to_groupid", to_groupid); - this.wxMpService.execute(new SimplePostRequestExecutor(), url, json.toString()); - } - -} diff --git a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java index ba3fcdfc..ef1f8e87 100644 --- a/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java +++ b/weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpServiceImpl.java @@ -1,23 +1,9 @@ package me.chanjar.weixin.mp.api.impl; -import java.io.IOException; - -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.ssl.DefaultHostnameVerifier; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.impl.client.BasicResponseHandler; -import org.apache.http.impl.client.CloseableHttpClient; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.gson.JsonArray; import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; - import me.chanjar.weixin.common.bean.WxAccessToken; import me.chanjar.weixin.common.bean.WxJsapiSignature; import me.chanjar.weixin.common.bean.result.WxError; @@ -26,39 +12,22 @@ import me.chanjar.weixin.common.session.StandardSessionManager; import me.chanjar.weixin.common.session.WxSessionManager; import me.chanjar.weixin.common.util.RandomUtils; import me.chanjar.weixin.common.util.crypto.SHA1; -import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder; -import me.chanjar.weixin.common.util.http.DefaultApacheHttpClientBuilder; -import me.chanjar.weixin.common.util.http.RequestExecutor; -import me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor; -import me.chanjar.weixin.common.util.http.SimplePostRequestExecutor; -import me.chanjar.weixin.common.util.http.URIUtil; -import me.chanjar.weixin.mp.api.WxMpCardService; -import me.chanjar.weixin.mp.api.WxMpConfigStorage; -import me.chanjar.weixin.mp.api.WxMpDataCubeService; -import me.chanjar.weixin.mp.api.WxMpGroupService; -import me.chanjar.weixin.mp.api.WxMpKefuService; -import me.chanjar.weixin.mp.api.WxMpMaterialService; -import me.chanjar.weixin.mp.api.WxMpMenuService; -import me.chanjar.weixin.mp.api.WxMpPayService; -import me.chanjar.weixin.mp.api.WxMpQrcodeService; -import me.chanjar.weixin.mp.api.WxMpService; -import me.chanjar.weixin.mp.api.WxMpStoreService; -import me.chanjar.weixin.mp.api.WxMpUserBlacklistService; -import me.chanjar.weixin.mp.api.WxMpUserService; -import me.chanjar.weixin.mp.api.WxMpUserTagService; -import me.chanjar.weixin.mp.bean.WxMpIndustry; -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.WxMpMassPreviewMessage; -import me.chanjar.weixin.mp.bean.WxMpMassVideo; -import me.chanjar.weixin.mp.bean.WxMpSemanticQuery; -import me.chanjar.weixin.mp.bean.WxMpTemplateMessage; -import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult; -import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult; -import me.chanjar.weixin.mp.bean.result.WxMpOAuth2AccessToken; -import me.chanjar.weixin.mp.bean.result.WxMpSemanticQueryResult; -import me.chanjar.weixin.mp.bean.result.WxMpUser; +import me.chanjar.weixin.common.util.http.*; +import me.chanjar.weixin.mp.api.*; +import me.chanjar.weixin.mp.bean.*; +import me.chanjar.weixin.mp.bean.result.*; +import org.apache.http.HttpHost; +import org.apache.http.client.config.RequestConfig; +import org.apache.http.client.methods.CloseableHttpResponse; +import org.apache.http.client.methods.HttpGet; +import org.apache.http.conn.ssl.DefaultHostnameVerifier; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.impl.client.BasicResponseHandler; +import org.apache.http.impl.client.CloseableHttpClient; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; public class WxMpServiceImpl implements WxMpService { @@ -86,8 +55,6 @@ public class WxMpServiceImpl implements WxMpService { private WxMpUserService userService = new WxMpUserServiceImpl(this); - private WxMpGroupService groupService = new WxMpGroupServiceImpl(this); - private WxMpUserTagService tagService = new WxMpUserTagServiceImpl(this); private WxMpQrcodeService qrCodeService = new WxMpQrcodeServiceImpl(this); @@ -559,11 +526,6 @@ public class WxMpServiceImpl implements WxMpService { return this.userService; } - @Override - public WxMpGroupService getGroupService() { - return this.groupService; - } - @Override public WxMpUserTagService getUserTagService() { return this.tagService; diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java deleted file mode 100644 index 2216e553..00000000 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGroupServiceImplTest.java +++ /dev/null @@ -1,62 +0,0 @@ -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.WxXmlMpInMemoryConfigStorage; -import me.chanjar.weixin.mp.bean.WxMpGroup; -import org.testng.Assert; -import org.testng.annotations.Guice; -import org.testng.annotations.Test; - -import java.util.List; - -/** - * 测试分组接口 - * - * @author chanjarster - */ -@Deprecated -@Test(groups = "groupAPI") -@Guice(modules = ApiTestModule.class) -public class WxMpGroupServiceImplTest { - - @Inject - protected WxMpServiceImpl wxService; - - protected WxMpGroup group; - - public void testGroupCreate() throws WxErrorException { - WxMpGroup res = this.wxService.getGroupService().groupCreate("测试分组1"); - Assert.assertEquals(res.getName(), "测试分组1"); - } - - @Test(dependsOnMethods="testGroupCreate") - public void testGroupGet() throws WxErrorException { - List groupList = this.wxService.getGroupService().groupGet(); - Assert.assertNotNull(groupList); - Assert.assertTrue(groupList.size() > 0); - for (WxMpGroup g : groupList) { - this.group = g; - Assert.assertNotNull(g.getName()); - } - } - - @Test(dependsOnMethods={"testGroupGet", "testGroupCreate"}) - public void getGroupUpdate() throws WxErrorException { - this.group.setName("分组改名"); - this.wxService.getGroupService().groupUpdate(this.group); - } - - public void testGroupQueryUserGroup() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - long groupid = this.wxService.getGroupService().userGetGroup(configStorage.getOpenid()); - Assert.assertTrue(groupid != -1l); - } - - public void testGroupMoveUser() throws WxErrorException { - WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage(); - this.wxService.getGroupService().userUpdateGroup(configStorage.getOpenid(), this.wxService.getGroupService().groupGet().get(3).getId()); - } - -} diff --git a/weixin-java-mp/src/test/resources/testng.xml b/weixin-java-mp/src/test/resources/testng.xml index d821e398..6d5310ce 100644 --- a/weixin-java-mp/src/test/resources/testng.xml +++ b/weixin-java-mp/src/test/resources/testng.xml @@ -5,9 +5,6 @@ - - -