mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
优化重构企业号相关代码,修复了升级企业微信后出现的菜单问题和用户管理的问题
This commit is contained in:
@@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.util.json;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.bean.result.WxError;
|
||||
import me.chanjar.weixin.common.util.json.WxErrorAdapter;
|
||||
import me.chanjar.weixin.cp.bean.WxCpDepart;
|
||||
@@ -19,6 +20,7 @@ public class WxCpGsonBuilder {
|
||||
INSTANCE.registerTypeAdapter(WxCpDepart.class, new WxCpDepartGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxCpUser.class, new WxCpUserGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxError.class, new WxErrorAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxMenu.class, new WxCpMenuGsonAdapter());
|
||||
INSTANCE.registerTypeAdapter(WxCpTag.class, new WxCpTagGsonAdapter());
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
package me.chanjar.weixin.cp.util.json;
|
||||
|
||||
import com.google.gson.JsonDeserializationContext;
|
||||
import com.google.gson.JsonElement;
|
||||
import com.google.gson.JsonParseException;
|
||||
import me.chanjar.weixin.common.bean.menu.WxMenu;
|
||||
import me.chanjar.weixin.common.util.json.WxMenuGsonAdapter;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 企业号菜单json转换适配器
|
||||
* Created by Binary Wang on 2017-6-25.
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
* </pre>
|
||||
*/
|
||||
public class WxCpMenuGsonAdapter extends WxMenuGsonAdapter {
|
||||
|
||||
@Override
|
||||
public WxMenu deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
return this.buildMenuFromJson(json.getAsJsonObject().get("button").getAsJsonArray());
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
user.setName(GsonHelper.getString(o, "name"));
|
||||
user.setPosition(GsonHelper.getString(o, "position"));
|
||||
user.setMobile(GsonHelper.getString(o, "mobile"));
|
||||
user.setGender(GsonHelper.getString(o, "gender"));
|
||||
user.setGender(WxCpUser.Gender.fromCode(GsonHelper.getString(o, "gender")));
|
||||
user.setEmail(GsonHelper.getString(o, "email"));
|
||||
user.setAvatar(GsonHelper.getString(o, "avatar"));
|
||||
user.setStatus(GsonHelper.getInteger(o, "status"));
|
||||
@@ -85,7 +85,7 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
o.addProperty("mobile", user.getMobile());
|
||||
}
|
||||
if (user.getGender() != null) {
|
||||
o.addProperty("gender", user.getGender());
|
||||
o.addProperty("gender", user.getGender().getCode());
|
||||
}
|
||||
if (user.getEmail() != null) {
|
||||
o.addProperty("email", user.getEmail());
|
||||
|
||||
Reference in New Issue
Block a user