mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-22 03:27:39 +08:00
🐛 #1738 修复企业微信创建用户接口自定义字段缺失的问题
This commit is contained in:
@@ -86,6 +86,9 @@ public class WxCpUser implements Serializable {
|
||||
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Attr {
|
||||
/**
|
||||
* 属性类型: 0-文本 1-网页
|
||||
|
@@ -276,11 +276,11 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
o.addProperty("main_department", user.getMainDepartment());
|
||||
}
|
||||
|
||||
if (user.getExtAttrs().size() > 0) {
|
||||
if (!user.getExtAttrs().isEmpty()) {
|
||||
JsonArray attrsJsonArray = new JsonArray();
|
||||
for (WxCpUser.Attr attr : user.getExtAttrs()) {
|
||||
JsonObject attrJson = new JsonObject();
|
||||
|
||||
JsonObject attrJson = GsonHelper.buildJsonObject("type", attr.getType(),
|
||||
"name", attr.getName());
|
||||
attrsJsonArray.add(attrJson);
|
||||
|
||||
if (attr.getType() == null) {
|
||||
@@ -290,19 +290,12 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
}
|
||||
|
||||
switch (attr.getType()) {
|
||||
case 0: {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("value", attr.getTextValue());
|
||||
attrJson.add("text", text);
|
||||
case 0:
|
||||
attrJson.add("text", GsonHelper.buildJsonObject("value", attr.getTextValue()));
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
JsonObject web = new JsonObject();
|
||||
web.addProperty("url", attr.getWebUrl());
|
||||
web.addProperty("title", attr.getWebTitle());
|
||||
attrJson.add("web", web);
|
||||
case 1:
|
||||
attrJson.add("web", GsonHelper.buildJsonObject("url", attr.getWebUrl(), "title", attr.getWebTitle()));
|
||||
break;
|
||||
}
|
||||
default: //ignored
|
||||
}
|
||||
}
|
||||
@@ -322,12 +315,11 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
attrsJson.addProperty(EXTERNAL_CORP_NAME, user.getExternalCorpName());
|
||||
}
|
||||
|
||||
if (user.getExternalAttrs().size() > 0) {
|
||||
if (!user.getExternalAttrs().isEmpty()) {
|
||||
JsonArray attrsJsonArray = new JsonArray();
|
||||
for (WxCpUser.ExternalAttribute attr : user.getExternalAttrs()) {
|
||||
JsonObject attrJson = new JsonObject();
|
||||
attrJson.addProperty("type", attr.getType());
|
||||
attrJson.addProperty("name", attr.getName());
|
||||
JsonObject attrJson = GsonHelper.buildJsonObject("type", attr.getType(),
|
||||
"name", attr.getName());
|
||||
|
||||
attrsJsonArray.add(attrJson);
|
||||
|
||||
@@ -336,27 +328,16 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
}
|
||||
|
||||
switch (attr.getType()) {
|
||||
case 0: {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("value", attr.getValue());
|
||||
attrJson.add("text", text);
|
||||
case 0:
|
||||
attrJson.add("text", GsonHelper.buildJsonObject("value", attr.getValue()));
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
JsonObject web = new JsonObject();
|
||||
web.addProperty("url", attr.getUrl());
|
||||
web.addProperty("title", attr.getTitle());
|
||||
attrJson.add("web", web);
|
||||
case 1:
|
||||
attrJson.add("web", GsonHelper.buildJsonObject("url", attr.getUrl(), "title", attr.getTitle()));
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
JsonObject miniprogram = new JsonObject();
|
||||
miniprogram.addProperty("appid", attr.getAppid());
|
||||
miniprogram.addProperty("pagepath", attr.getPagePath());
|
||||
miniprogram.addProperty("title", attr.getTitle());
|
||||
attrJson.add("miniprogram", miniprogram);
|
||||
case 2:
|
||||
attrJson.add("miniprogram", GsonHelper.buildJsonObject("appid", attr.getAppid(),
|
||||
"pagepath", attr.getPagePath(), "title", attr.getTitle()));
|
||||
break;
|
||||
}
|
||||
default://忽略
|
||||
}
|
||||
}
|
||||
|
@@ -91,7 +91,7 @@ public class WxCpUserGsonAdapterTest {
|
||||
assertThat(user).isNotNull();
|
||||
|
||||
assertThat(user.getOrders()).isNotEmpty();
|
||||
assertThat(user.getOrders().length).isEqualTo(2);
|
||||
assertThat(user.getOrders()).hasSize(2);
|
||||
assertThat(user.getOrders()[0]).isEqualTo(1);
|
||||
assertThat(user.getOrders()[1]).isEqualTo(2);
|
||||
|
||||
@@ -140,6 +140,12 @@ public class WxCpUserGsonAdapterTest {
|
||||
public void testSerialize() {
|
||||
WxCpUser user = new WxCpUser();
|
||||
user.setOrders(new Integer[]{1, 2});
|
||||
user.addExtAttr(WxCpUser.Attr.builder()
|
||||
.type(0)
|
||||
.name("文本名称")
|
||||
.textValue("文本")
|
||||
.build());
|
||||
|
||||
user.addExternalAttr(WxCpUser.ExternalAttribute.builder()
|
||||
.type(0)
|
||||
.name("文本名称")
|
||||
@@ -159,7 +165,9 @@ public class WxCpUserGsonAdapterTest {
|
||||
.title("my miniprogram")
|
||||
.build());
|
||||
|
||||
assertThat(user.toJson()).isEqualTo("{\"order\":[1,2],\"external_profile\":{\"external_attr\":" +
|
||||
assertThat(user.toJson()).isEqualTo("{\"order\":[1,2]," +
|
||||
"\"extattr\":{\"attrs\":[{\"type\":0,\"name\":\"文本名称\",\"text\":{\"value\":\"文本\"}}]}," +
|
||||
"\"external_profile\":{\"external_attr\":" +
|
||||
"[{\"type\":0,\"name\":\"文本名称\",\"text\":{\"value\":\"文本\"}}," +
|
||||
"{\"type\":1,\"name\":\"网页名称\",\"web\":{\"url\":\"http://www.test.com\",\"title\":\"标题\"}}," +
|
||||
"{\"type\":2,\"name\":\"测试app\"," +
|
||||
|
Reference in New Issue
Block a user