| @@ -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 { | |||
| /** | |||
| * <pre> | |||
| * 分组管理接口 - 创建分组 | |||
| * 最多支持创建500个分组 | |||
| * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
| * </pre> | |||
| * | |||
| * @param name 分组名字(30个字符以内) | |||
| */ | |||
| WxMpGroup groupCreate(String name) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 分组管理接口 - 查询所有分组 | |||
| * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
| * </pre> | |||
| */ | |||
| List<WxMpGroup> groupGet() throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 分组管理接口 - 查询用户所在分组 | |||
| * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
| * </pre> | |||
| * | |||
| * @param openid 微信用户的openid | |||
| */ | |||
| long userGetGroup(String openid) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 分组管理接口 - 修改分组名 | |||
| * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
| * | |||
| * 如果id为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 | |||
| * </pre> | |||
| * | |||
| * @param group 要更新的group,group的id,name必须设置 | |||
| */ | |||
| void groupUpdate(WxMpGroup group) throws WxErrorException; | |||
| /** | |||
| * <pre> | |||
| * 分组管理接口 - 移动用户分组 | |||
| * 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=分组管理接口 | |||
| * | |||
| * 如果to_groupid为0(未分组),1(黑名单),2(星标组),或者不存在的id,微信会返回系统繁忙的错误 | |||
| * </pre> | |||
| * | |||
| * @param openid 用户openid | |||
| * @param to_groupid 移动到的分组id | |||
| */ | |||
| void userUpdateGroup(String openid, long to_groupid) throws WxErrorException; | |||
| } | |||
| @@ -322,14 +322,6 @@ public interface WxMpService { | |||
| */ | |||
| WxMpUserService getUserService(); | |||
| /** | |||
| * 返回用户分组相关接口方法的实现类对象,以方便调用个其各种接口 | |||
| * | |||
| * @return WxMpGroupService | |||
| */ | |||
| WxMpGroupService getGroupService(); | |||
| /** | |||
| * 返回用户标签相关接口方法的实现类对象,以方便调用个其各种接口 | |||
| * | |||
| @@ -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<WxMpGroup> 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<List<WxMpGroup>>() { | |||
| }.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()); | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -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<WxMpGroup> 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()); | |||
| } | |||
| } | |||
| @@ -5,9 +5,6 @@ | |||
| <classes> | |||
| <class name="me.chanjar.weixin.mp.api.WxMpBusyRetryTest" /> | |||
| <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.impl.WxMpGroupServiceImplTest" /> | |||
| <class name="me.chanjar.weixin.mp.api.WxMpMassMessageAPITest" /> | |||
| <class name="me.chanjar.weixin.mp.api.impl.WxMpUserServiceImplTest" /> | |||
| <class name="me.chanjar.weixin.mp.api.impl.WxMpQrCodeServiceImplTest" /> | |||