mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
#783 企业微信模块增加群聊相关接口
* 实现消息推送的服务,添加发送应用消息的方法 * 添加创建群聊会话方法,去除不需要的类 * 完成群聊会话的修改和获取 * 重构群聊服务,提出到单独的服务类里面 * 完成群聊的测试
This commit is contained in:
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* KINGSTAR MEDIA SOLUTIONS Co.,LTD. Copyright c 2005-2013. All rights reserved.
|
||||
*
|
||||
* This source code is the property of KINGSTAR MEDIA SOLUTIONS LTD. It is intended
|
||||
* only for the use of KINGSTAR MEDIA application development. Reengineering, reproduction
|
||||
* arose from modification of the original source, or other redistribution of this source
|
||||
* is not permitted without written permission of the KINGSTAR MEDIA SOLUTIONS LTD.
|
||||
*/
|
||||
package me.chanjar.weixin.cp.util.json;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonDeserializer;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParseException;
|
||||
import com.google.gson.JsonSerializationContext;
|
||||
import com.google.gson.JsonSerializer;
|
||||
|
||||
import me.chanjar.weixin.common.util.json.GsonHelper;
|
||||
import me.chanjar.weixin.cp.bean.WxCpChat;
|
||||
|
||||
/**
|
||||
* 群聊适配器
|
||||
*
|
||||
* @author gaigeshen
|
||||
*/
|
||||
public class WxCpChatGsonAdapter implements JsonSerializer<WxCpChat>, JsonDeserializer<WxCpChat> {
|
||||
|
||||
@Override
|
||||
public JsonElement serialize(WxCpChat chat, Type typeOfSrc, JsonSerializationContext context) {
|
||||
JsonObject json = new JsonObject();
|
||||
if (chat.getId() != null) {
|
||||
json.addProperty("chatid", chat.getId());
|
||||
}
|
||||
if (chat.getName() != null) {
|
||||
json.addProperty("name", chat.getName());
|
||||
}
|
||||
if (chat.getOwner() != null) {
|
||||
json.addProperty("owner", chat.getOwner());
|
||||
}
|
||||
if (chat.getUsers() != null) {
|
||||
JsonArray users = new JsonArray();
|
||||
for (String user : chat.getUsers()) {
|
||||
users.add(user);
|
||||
}
|
||||
json.add("userlist", users);
|
||||
}
|
||||
return json;
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpChat deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject chatJson = json.getAsJsonObject();
|
||||
|
||||
WxCpChat chat = new WxCpChat();
|
||||
chat.setId(GsonHelper.getAsString(chatJson.get("chatid")));
|
||||
chat.setName(GsonHelper.getAsString(chatJson.get("name")));
|
||||
chat.setOwner(GsonHelper.getAsString(chatJson.get("owner")));
|
||||
|
||||
JsonArray usersJson = chatJson.getAsJsonArray("userlist");
|
||||
if (usersJson != null) {
|
||||
List<String> users = new ArrayList<>(usersJson.size());
|
||||
chat.setUsers(users);
|
||||
for (JsonElement userJson : usersJson) {
|
||||
users.add(userJson.getAsString());
|
||||
}
|
||||
}
|
||||
|
||||
return chat;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.error.WxError;
|
||||
import me.chanjar.weixin.common.util.json.WxErrorAdapter;
|
||||
import me.chanjar.weixin.cp.bean.WxCpChat;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
@@ -20,6 +21,7 @@ public class WxCpGsonBuilder {
|
||||
static {
|
||||
INSTANCE.disableHtmlEscaping();
|
||||
INSTANCE.registerTypeAdapter(WxCpMessage.class, new WxCpMessageGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxCpChat.class, new WxCpChatGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxCpDepart.class, new WxCpDepartGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxCpUser.class, new WxCpUserGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter());
|
||||
|
||||
Reference in New Issue
Block a user