Search in sources :

Example 1 with WxCpUser

use of me.chanjar.weixin.cp.bean.WxCpUser in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method tagGetUsers.

@Override
public List<WxCpUser> tagGetUsers(String tagId) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/get?tagid=" + tagId;
    String responseContent = get(url, null);
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return WxCpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("userlist"), new TypeToken<List<WxCpUser>>() {
    }.getType());
}
Also used : WxCpUser(me.chanjar.weixin.cp.bean.WxCpUser) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader)

Example 2 with WxCpUser

use of me.chanjar.weixin.cp.bean.WxCpUser in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method userList.

@Override
public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/user/list?department_id=" + departId;
    String params = "";
    if (fetchChild != null) {
        params += "&fetch_child=" + (fetchChild ? "1" : "0");
    }
    if (status != null) {
        params += "&status=" + status;
    } else {
        params += "&status=0";
    }
    String responseContent = get(url, params);
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return WxCpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("userlist"), new TypeToken<List<WxCpUser>>() {
    }.getType());
}
Also used : WxCpUser(me.chanjar.weixin.cp.bean.WxCpUser) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader)

Example 3 with WxCpUser

use of me.chanjar.weixin.cp.bean.WxCpUser in project weixin-java-tools by chanjarster.

the class WxCpUserAPITest method testUserUpdate.

@Test(dependsOnMethods = "testUserCreate")
public void testUserUpdate() throws WxErrorException {
    WxCpUser user = new WxCpUser();
    user.setUserId("some.woman");
    user.setName("Some Woman");
    user.addExtAttr("爱好", "table2");
    wxCpService.userUpdate(user);
}
Also used : WxCpUser(me.chanjar.weixin.cp.bean.WxCpUser) Test(org.testng.annotations.Test)

Example 4 with WxCpUser

use of me.chanjar.weixin.cp.bean.WxCpUser in project weixin-java-tools by chanjarster.

the class WxCpServiceImpl method departGetUsers.

@Override
public List<WxCpUser> departGetUsers(Integer departId, Boolean fetchChild, Integer status) throws WxErrorException {
    String url = "https://qyapi.weixin.qq.com/cgi-bin/user/simplelist?department_id=" + departId;
    String params = "";
    if (fetchChild != null) {
        params += "&fetch_child=" + (fetchChild ? "1" : "0");
    }
    if (status != null) {
        params += "&status=" + status;
    } else {
        params += "&status=0";
    }
    String responseContent = get(url, params);
    JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
    return WxCpGsonBuilder.INSTANCE.create().fromJson(tmpJsonElement.getAsJsonObject().get("userlist"), new TypeToken<List<WxCpUser>>() {
    }.getType());
}
Also used : WxCpUser(me.chanjar.weixin.cp.bean.WxCpUser) JsonElement(com.google.gson.JsonElement) TypeToken(com.google.gson.reflect.TypeToken) StringReader(java.io.StringReader) JsonReader(com.google.gson.stream.JsonReader)

Example 5 with WxCpUser

use of me.chanjar.weixin.cp.bean.WxCpUser in project weixin-java-tools by chanjarster.

the class WxCpUserGsonAdapter method deserialize.

public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
    JsonObject o = json.getAsJsonObject();
    WxCpUser user = new WxCpUser();
    user.setUserId(GsonHelper.getString(o, "userid"));
    user.setName(GsonHelper.getString(o, "name"));
    if (o.get("department") != null) {
        JsonArray departJsonArray = o.get("department").getAsJsonArray();
        Integer[] departIds = new Integer[departJsonArray.size()];
        int i = 0;
        for (JsonElement jsonElement : departJsonArray) {
            departIds[i++] = jsonElement.getAsInt();
        }
        user.setDepartIds(departIds);
    }
    user.setPosition(GsonHelper.getString(o, "position"));
    user.setMobile(GsonHelper.getString(o, "mobile"));
    user.setGender(GsonHelper.getString(o, "gender"));
    user.setTel(GsonHelper.getString(o, "tel"));
    user.setEmail(GsonHelper.getString(o, "email"));
    user.setWeiXinId(GsonHelper.getString(o, "weixinid"));
    user.setAvatar(GsonHelper.getString(o, "avatar"));
    user.setStatus(GsonHelper.getInteger(o, "status"));
    if (GsonHelper.isNotNull(o.get("extattr"))) {
        JsonArray attrJsonElements = o.get("extattr").getAsJsonObject().get("attrs").getAsJsonArray();
        for (JsonElement attrJsonElement : attrJsonElements) {
            WxCpUser.Attr attr = new WxCpUser.Attr(GsonHelper.getString(attrJsonElement.getAsJsonObject(), "name"), GsonHelper.getString(attrJsonElement.getAsJsonObject(), "value"));
            user.getExtAttrs().add(attr);
        }
    }
    return user;
}
Also used : WxCpUser(me.chanjar.weixin.cp.bean.WxCpUser)

Aggregations

WxCpUser (me.chanjar.weixin.cp.bean.WxCpUser)7 JsonElement (com.google.gson.JsonElement)3 TypeToken (com.google.gson.reflect.TypeToken)3 JsonReader (com.google.gson.stream.JsonReader)3 StringReader (java.io.StringReader)3 Test (org.testng.annotations.Test)2