use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method tagCreate.
@Override
public String tagCreate(String tagName) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/create";
JsonObject o = new JsonObject();
o.addProperty("tagname", tagName);
String responseContent = post(url, o.toString());
JsonElement tmpJsonElement = Streams.parse(new JsonReader(new StringReader(responseContent)));
return tmpJsonElement.getAsJsonObject().get("tagid").getAsString();
}
use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method userDelete.
@Override
public void userDelete(String[] userids) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/user/batchdelete";
JsonObject jsonObject = new JsonObject();
JsonArray jsonArray = new JsonArray();
for (int i = 0; i < userids.length; i++) {
jsonArray.add(new JsonPrimitive(userids[i]));
}
jsonObject.add("useridlist", jsonArray);
post(url, jsonObject.toString());
}
use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method tagAddUsers.
@Override
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
if (userIds != null) {
JsonArray jsonArray = new JsonArray();
for (String userId : userIds) {
jsonArray.add(new JsonPrimitive(userId));
}
jsonObject.add("userlist", jsonArray);
}
if (partyIds != null) {
JsonArray jsonArray = new JsonArray();
for (String userId : partyIds) {
jsonArray.add(new JsonPrimitive(userId));
}
jsonObject.add("partylist", jsonArray);
}
post(url, jsonObject.toString());
}
use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxCpServiceImpl method replaceParty.
@Override
public String replaceParty(String mediaId) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/batch/replaceparty";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("media_id", mediaId);
return post(url, jsonObject.toString());
}
use of com.google.gson.JsonObject in project weixin-java-tools by chanjarster.
the class WxMenuGsonAdapter method deserialize.
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
/*
* 操蛋的微信
* 创建菜单时是 { button : ... }
* 查询菜单时是 { menu : { button : ... } }
*/
WxMenu menu = new WxMenu();
JsonObject menuJson = json.getAsJsonObject().get("menu").getAsJsonObject();
JsonArray buttonsJson = menuJson.get("button").getAsJsonArray();
for (int i = 0; i < buttonsJson.size(); i++) {
JsonObject buttonJson = buttonsJson.get(i).getAsJsonObject();
WxMenu.WxMenuButton button = convertFromJson(buttonJson);
menu.getButtons().add(button);
if (buttonJson.get("sub_button") == null || buttonJson.get("sub_button").isJsonNull()) {
continue;
}
JsonArray sub_buttonsJson = buttonJson.get("sub_button").getAsJsonArray();
for (int j = 0; j < sub_buttonsJson.size(); j++) {
JsonObject sub_buttonJson = sub_buttonsJson.get(j).getAsJsonObject();
button.getSubButtons().add(convertFromJson(sub_buttonJson));
}
}
return menu;
}
Aggregations