From 94064752abfed263f2d329dc01a245a3cc30162a Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Thu, 13 Feb 2020 17:51:59 +0800 Subject: [PATCH] =?UTF-8?q?:new:=20#1397=20=E4=BC=81=E4=B8=9A=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E9=80=9A=E8=AE=AF=E5=BD=95=E6=88=90=E5=91=98=E7=B1=BB?= =?UTF-8?q?WxCpUser=E5=A2=9E=E5=8A=A0alias=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/me/chanjar/weixin/cp/bean/WxCpUser.java | 13 +++++++++---- .../weixin/cp/util/json/WxCpUserGsonAdapter.java | 4 ++++ .../cp/util/json/WxCpUserGsonAdapterTest.java | 2 ++ 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java index a47d2a2a0f..90354154a6 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java @@ -1,15 +1,15 @@ package me.chanjar.weixin.cp.bean; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.List; - import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Data; import lombok.NoArgsConstructor; import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + /** * 微信用户信息. * @@ -28,6 +28,7 @@ public class WxCpUser implements Serializable { private String email; private String avatar; private String thumbAvatar; + /** * 地址。长度最大128个字符 */ @@ -35,6 +36,10 @@ public class WxCpUser implements Serializable { private String avatarMediaId; private Integer status; private Integer enable; + /** + * 别名;第三方仅通讯录应用可获取 + */ + private String alias; private Integer isLeader; /** * is_leader_in_dept. diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java index 8dfeb1d752..5128405a47 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java @@ -71,6 +71,7 @@ public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC user.setAvatarMediaId(GsonHelper.getString(o, "avatar_mediaid")); user.setStatus(GsonHelper.getInteger(o, "status")); user.setEnable(GsonHelper.getInteger(o, "enable")); + user.setAlias(GsonHelper.getString(o, "alias")); user.setIsLeader(GsonHelper.getInteger(o, "isleader")); user.setIsLeaderInDept(GsonHelper.getIntArray(o, "is_leader_in_dept")); user.setHideMobile(GsonHelper.getInteger(o, "hide_mobile")); @@ -203,6 +204,9 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon if (user.getEnable() != null) { o.addProperty("enable", user.getEnable()); } + if (user.getAlias() != null) { + o.addProperty("alias", user.getAlias()); + } if (user.getIsLeader() != null) { o.addProperty("isleader", user.getIsLeader()); } diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java index d17700220d..abfb8a4617 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapterTest.java @@ -83,6 +83,7 @@ public void testDeserialize() { assertThat(user.getOrders()[1]).isEqualTo(2); assertThat(user.getAddress()).isEqualTo("广州市海珠区新港中路"); + assertThat(user.getAlias()).isEqualTo("jackzhang"); assertThat(user.getExternalAttrs()).isNotEmpty(); final WxCpUser.ExternalAttribute externalAttr1 = user.getExternalAttrs().get(0); @@ -102,6 +103,7 @@ public void testDeserialize() { assertThat(externalAttr3.getAppid()).isEqualTo("wx8bd80126147df384"); assertThat(externalAttr3.getPagePath()).isEqualTo("/index"); assertThat(externalAttr3.getTitle()).isEqualTo("my miniprogram"); + } @Test