Search in sources :

Example 1 with WxMpGroup

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());
}
Also used : WxMpGroup(me.chanjar.weixin.mp.bean.WxMpGroup) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader) SimpleGetRequestExecutor(me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)

Example 2 with WxMpGroup

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;
}
Also used : WxMpGroup(me.chanjar.weixin.mp.bean.WxMpGroup)

Example 3 with WxMpGroup

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());
    }
}
Also used : WxMpGroup(me.chanjar.weixin.mp.bean.WxMpGroup) Test(org.testng.annotations.Test)

Example 4 with WxMpGroup

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");
}
Also used : WxMpGroup(me.chanjar.weixin.mp.bean.WxMpGroup)

Aggregations

WxMpGroup (me.chanjar.weixin.mp.bean.WxMpGroup)4 JsonElement (com.google.gson.JsonElement)1 TypeToken (com.google.gson.reflect.TypeToken)1 JsonReader (com.google.gson.stream.JsonReader)1 StringReader (java.io.StringReader)1 SimpleGetRequestExecutor (me.chanjar.weixin.common.util.http.SimpleGetRequestExecutor)1 Test (org.testng.annotations.Test)1