use of me.chanjar.weixin.mp.bean.WxMpGroup in project weixin-java-tools by chanjarster.
the class WxMpServiceImpl method groupGet.
public List<WxMpGroup> 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 WxMpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("groups"), new TypeToken<List<WxMpGroup>>() {
}.getType());
}
use of me.chanjar.weixin.mp.bean.WxMpGroup in project weixin-java-tools by chanjarster.
the class WxMpGroupGsonAdapter method deserialize.
public WxMpGroup deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
WxMpGroup group = new WxMpGroup();
JsonObject groupJson = json.getAsJsonObject();
if (json.getAsJsonObject().get("group") != null) {
groupJson = json.getAsJsonObject().get("group").getAsJsonObject();
}
if (groupJson.get("name") != null && !groupJson.get("name").isJsonNull()) {
group.setName(GsonHelper.getAsString(groupJson.get("name")));
}
if (groupJson.get("id") != null && !groupJson.get("id").isJsonNull()) {
group.setId(GsonHelper.getAsPrimitiveLong(groupJson.get("id")));
}
if (groupJson.get("count") != null && !groupJson.get("count").isJsonNull()) {
group.setCount(GsonHelper.getAsPrimitiveLong(groupJson.get("count")));
}
return group;
}
use of me.chanjar.weixin.mp.bean.WxMpGroup in project weixin-java-tools by chanjarster.
the class WxMpGroupAPITest method testGroupGet.
@Test(dependsOnMethods = "testGroupCreate")
public void testGroupGet() throws WxErrorException {
List<WxMpGroup> groupList = wxService.groupGet();
Assert.assertNotNull(groupList);
Assert.assertTrue(groupList.size() > 0);
for (WxMpGroup g : groupList) {
group = g;
Assert.assertNotNull(g.getName());
}
}
use of me.chanjar.weixin.mp.bean.WxMpGroup in project weixin-java-tools by chanjarster.
the class WxMpGroupAPITest method testGroupCreate.
public void testGroupCreate() throws WxErrorException {
WxMpGroup res = wxService.groupCreate("测试分组1");
Assert.assertEquals(res.getName(), "测试分组1");
}
Aggregations