mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-24 21:13:59 +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>
|
||||||
|
* @param openid 微信用户的openid
|
||||||
|
* @throws WxErrorException
|
||||||
|
*/
|
||||||
|
public long groupQueryUserGroup(String openid) throws WxErrorException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <pre>
|
* <pre>
|
||||||
* 分组管理接口 - 查询所有分组
|
* 分组管理接口 - 查询所有分组
|
||||||
|
@@ -38,6 +38,7 @@ import chanjarster.weixin.util.http.MediaUploadRequestExecutor;
|
|||||||
import chanjarster.weixin.util.http.RequestExecutor;
|
import chanjarster.weixin.util.http.RequestExecutor;
|
||||||
import chanjarster.weixin.util.http.SimpleGetRequestExecutor;
|
import chanjarster.weixin.util.http.SimpleGetRequestExecutor;
|
||||||
import chanjarster.weixin.util.http.SimplePostRequestExecutor;
|
import chanjarster.weixin.util.http.SimplePostRequestExecutor;
|
||||||
|
import chanjarster.weixin.util.json.GsonHelper;
|
||||||
import chanjarster.weixin.util.json.WxGsonBuilder;
|
import chanjarster.weixin.util.json.WxGsonBuilder;
|
||||||
|
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
@@ -210,6 +211,13 @@ public class WxServiceImpl implements WxService {
|
|||||||
return WxGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxGroup>>(){}.getType());
|
return WxGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxGroup>>(){}.getType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public long groupQueryUserGroup(String openid) throws WxErrorException {
|
||||||
|
String url = "https://api.weixin.qq.com/cgi-bin/groups/getid";
|
||||||
|
String responseContent = execute(new SimplePostRequestExecutor(), url, MessageFormat.format("'{'\"openid\":\"{0}\"}", openid));
|
||||||
|
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
|
||||||
|
return GsonHelper.getAsLong(tmpJsonElement.getAsJsonObject().get("groupid"));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
* 向微信端发送请求,在这里执行的策略是当发生access_token过期时才去刷新,然后重新执行请求,而不是全局定时请求
|
||||||
* @param executor
|
* @param executor
|
||||||
|
@@ -38,5 +38,9 @@ public class WxGroup {
|
|||||||
public String toJson(String json) {
|
public String toJson(String json) {
|
||||||
return WxGsonBuilder.create().toJson(this);
|
return WxGsonBuilder.create().toJson(this);
|
||||||
}
|
}
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "WxGroup [id=" + id + ", name=" + name + ", count=" + count + "]";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -22,10 +22,10 @@ public class WxCustomMessageAPITest {
|
|||||||
protected WxServiceImpl wxService;
|
protected WxServiceImpl wxService;
|
||||||
|
|
||||||
public void testSendCustomMessage() throws WxErrorException {
|
public void testSendCustomMessage() throws WxErrorException {
|
||||||
WxXmlConfigStorage configProvider = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||||
WxCustomMessage message = new WxCustomMessage();
|
WxCustomMessage message = new WxCustomMessage();
|
||||||
message.setMsgtype(WxConsts.CUSTOM_MSG_TEXT);
|
message.setMsgtype(WxConsts.CUSTOM_MSG_TEXT);
|
||||||
message.setTouser(configProvider.getOpenId());
|
message.setTouser(configStorage.getOpenId());
|
||||||
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
|
||||||
|
|
||||||
wxService.customMessageSend(message);
|
wxService.customMessageSend(message);
|
||||||
|
@@ -6,6 +6,7 @@ import org.testng.Assert;
|
|||||||
import org.testng.annotations.Guice;
|
import org.testng.annotations.Guice;
|
||||||
import org.testng.annotations.Test;
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import chanjarster.weixin.api.ApiTestModule.WxXmlConfigStorage;
|
||||||
import chanjarster.weixin.bean.WxGroup;
|
import chanjarster.weixin.bean.WxGroup;
|
||||||
import chanjarster.weixin.exception.WxErrorException;
|
import chanjarster.weixin.exception.WxErrorException;
|
||||||
|
|
||||||
@@ -38,4 +39,10 @@ public class WxGroupAPITest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(dependsOnMethods="testGroupCreate")
|
||||||
|
public void groupQueryUserGroup() throws WxErrorException {
|
||||||
|
WxXmlConfigStorage configStorage = (WxXmlConfigStorage) wxService.wxConfigStorage;
|
||||||
|
long groupid = wxService.groupQueryUserGroup(configStorage.getOpenId());
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user