issue #1 添加分组管理接口-查询分组

This commit is contained in:
Daniel Qian
2014-08-25 17:57:06 +08:00
parent f57a0e4c87
commit fb7e739fef
4 changed files with 48 additions and 2 deletions

View File

@@ -3,9 +3,11 @@ package chanjarster.weixin.api;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringReader;
import java.security.MessageDigest;
import java.text.MessageFormat;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
@@ -36,6 +38,12 @@ import chanjarster.weixin.util.http.MediaUploadRequestExecutor;
import chanjarster.weixin.util.http.RequestExecutor;
import chanjarster.weixin.util.http.SimpleGetRequestExecutor;
import chanjarster.weixin.util.http.SimplePostRequestExecutor;
import chanjarster.weixin.util.json.WxGsonBuilder;
import com.google.gson.JsonElement;
import com.google.gson.internal.Streams;
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
public class WxServiceImpl implements WxService {
@@ -190,6 +198,17 @@ public class WxServiceImpl implements WxService {
String responseContent = execute(new SimplePostRequestExecutor(), url, MessageFormat.format("'{'\"group\":'{'\"name\":\"{0}\"}}", name));
return WxGroup.fromJson(responseContent);
}
public List<WxGroup> groupGet() throws WxErrorException {
String url = "https://api.weixin.qq.com/cgi-bin/groups/get";
String responseContent = execute(new SimpleGetRequestExecutor(), url, null);
/*
* 操蛋的微信API创建时返回的是 { group : { id : ..., name : ...} }
* 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
*/
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return WxGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxGroup>>(){}.getType());
}
/**
* 向微信端发送请求在这里执行的策略是当发生access_token过期时才去刷新然后重新执行请求而不是全局定时请求