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());
}
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());
}
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);
}
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());
}
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;
}
Aggregations