#705 企业微信用户相关接口增加成员对外信息external_profile
This commit is contained in:
@@ -5,7 +5,9 @@ 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;
|
||||
|
||||
/**
|
||||
@@ -34,6 +36,14 @@ public class WxCpUser implements Serializable {
|
||||
private String telephone;
|
||||
private String qrCode;
|
||||
private Boolean toInvite;
|
||||
/**
|
||||
* 成员对外信息.
|
||||
*/
|
||||
private List<ExternalAttr> externalAttrs = new ArrayList<>();
|
||||
|
||||
public void addExternalAttr(ExternalAttr externalAttr) {
|
||||
this.externalAttrs.add(externalAttr);
|
||||
}
|
||||
|
||||
public void addExtAttr(String name, String value) {
|
||||
this.extAttrs.add(new Attr(name, value));
|
||||
@@ -54,4 +64,40 @@ public class WxCpUser implements Serializable {
|
||||
private String value;
|
||||
}
|
||||
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class ExternalAttr {
|
||||
/**
|
||||
* 属性类型: 0-本文 1-网页 2-小程序.
|
||||
*/
|
||||
private int type;
|
||||
/**
|
||||
* 属性名称: 需要先确保在管理端有创建改属性,否则会忽略.
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 文本属性内容,长度限制12个UTF8字符.
|
||||
*/
|
||||
private String value;
|
||||
/**
|
||||
* 网页的url,必须包含http或者https头.
|
||||
*/
|
||||
private String url;
|
||||
/**
|
||||
* 小程序的展示标题,长度限制12个UTF8字符.
|
||||
* 或者 网页的展示标题,长度限制12个UTF8字符
|
||||
*/
|
||||
private String title;
|
||||
/**
|
||||
* 小程序appid,必须是有在本企业安装授权的小程序,否则会被忽略.
|
||||
*/
|
||||
private String appid;
|
||||
/**
|
||||
* 小程序的页面路径.
|
||||
*/
|
||||
private String pagePath;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -10,6 +10,9 @@ import me.chanjar.weixin.cp.bean.WxCpMessage;
|
||||
import me.chanjar.weixin.cp.bean.WxCpTag;
|
||||
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
|
||||
/**
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxCpGsonBuilder {
|
||||
|
||||
public static final GsonBuilder INSTANCE = new GsonBuilder();
|
||||
|
||||
@@ -27,10 +27,11 @@ import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||
* @author Daniel Qian
|
||||
*/
|
||||
public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSerializer<WxCpUser> {
|
||||
private static final String EXTERNAL_PROFILE = "external_profile";
|
||||
private static final String EXTERNAL_ATTR = "external_attr";
|
||||
|
||||
@Override
|
||||
public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context)
|
||||
throws JsonParseException {
|
||||
public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException {
|
||||
JsonObject o = json.getAsJsonObject();
|
||||
WxCpUser user = new WxCpUser();
|
||||
|
||||
@@ -71,6 +72,53 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
user.getExtAttrs().add(attr);
|
||||
}
|
||||
}
|
||||
|
||||
if (GsonHelper.isNotNull(o.get(EXTERNAL_PROFILE))) {
|
||||
JsonArray attrJsonElements = o.get(EXTERNAL_PROFILE).getAsJsonObject().get(EXTERNAL_ATTR).getAsJsonArray();
|
||||
for (JsonElement element : attrJsonElements) {
|
||||
final Integer type = GsonHelper.getInteger(element.getAsJsonObject(), "type");
|
||||
final String name = GsonHelper.getString(element.getAsJsonObject(), "name");
|
||||
|
||||
switch (type) {
|
||||
case 0: {
|
||||
user.getExternalAttrs()
|
||||
.add(WxCpUser.ExternalAttr.builder()
|
||||
.type(type)
|
||||
.name(name)
|
||||
.value(GsonHelper.getString(element.getAsJsonObject().get("text").getAsJsonObject(), "value"))
|
||||
.build()
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
final JsonObject web = element.getAsJsonObject().get("web").getAsJsonObject();
|
||||
user.getExternalAttrs()
|
||||
.add(WxCpUser.ExternalAttr.builder()
|
||||
.type(type)
|
||||
.name(name)
|
||||
.url(GsonHelper.getString(web, "url"))
|
||||
.title(GsonHelper.getString(web, "title"))
|
||||
.build()
|
||||
);
|
||||
break;
|
||||
}
|
||||
case 2: {
|
||||
final JsonObject miniprogram = element.getAsJsonObject().get("miniprogram").getAsJsonObject();
|
||||
user.getExternalAttrs()
|
||||
.add(WxCpUser.ExternalAttr.builder()
|
||||
.type(type)
|
||||
.name(name)
|
||||
.appid(GsonHelper.getString(miniprogram, "appid"))
|
||||
.pagePath(GsonHelper.getString(miniprogram, "pagepath"))
|
||||
.title(GsonHelper.getString(miniprogram, "title"))
|
||||
.build()
|
||||
);
|
||||
break;
|
||||
}
|
||||
default://ignored
|
||||
}
|
||||
}
|
||||
}
|
||||
return user;
|
||||
}
|
||||
|
||||
@@ -145,6 +193,45 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
||||
attrsJson.add("attrs", attrsJsonArray);
|
||||
o.add("extattr", attrsJson);
|
||||
}
|
||||
|
||||
if (user.getExternalAttrs().size() > 0) {
|
||||
JsonArray attrsJsonArray = new JsonArray();
|
||||
for (WxCpUser.ExternalAttr attr : user.getExternalAttrs()) {
|
||||
JsonObject attrJson = new JsonObject();
|
||||
attrJson.addProperty("type",attr.getType());
|
||||
attrJson.addProperty("name", attr.getName());
|
||||
switch (attr.getType()) {
|
||||
case 0: {
|
||||
JsonObject text = new JsonObject();
|
||||
text.addProperty("value", attr.getValue());
|
||||
attrJson.add("text", text);
|
||||
break;
|
||||
}
|
||||
case 1: {
|
||||
JsonObject web = new JsonObject();
|
||||
web.addProperty("url", attr.getUrl());
|
||||
web.addProperty("title", attr.getTitle());
|
||||
attrJson.add("web", web);
|
||||
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);
|
||||
break;
|
||||
}
|
||||
default://忽略
|
||||
}
|
||||
attrsJsonArray.add(attrJson);
|
||||
}
|
||||
|
||||
JsonObject attrsJson = new JsonObject();
|
||||
attrsJson.add(EXTERNAL_ATTR, attrsJsonArray);
|
||||
o.add(EXTERNAL_PROFILE, attrsJson);
|
||||
}
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user