mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-06-28 13:16:19 +08:00
🎨 #1624 企业微信模块更新用户信息相关接口类以适应企业微信私有化版本
This commit is contained in:
parent
320f3676a8
commit
c2034cb655
@ -26,6 +26,7 @@ public class WxCpUser implements Serializable {
|
|||||||
private Long[] departIds;
|
private Long[] departIds;
|
||||||
private Integer[] orders;
|
private Integer[] orders;
|
||||||
private String position;
|
private String position;
|
||||||
|
private String[] positions;
|
||||||
private String mobile;
|
private String mobile;
|
||||||
private Gender gender;
|
private Gender gender;
|
||||||
private String email;
|
private String email;
|
||||||
|
@ -54,6 +54,16 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
user.setOrders(orders);
|
user.setOrders(orders);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (o.get("positions") != null) {
|
||||||
|
JsonArray positionJsonArray = o.get("positions").getAsJsonArray();
|
||||||
|
String[] positions = new String[positionJsonArray.size()];
|
||||||
|
int i = 0;
|
||||||
|
for (JsonElement jsonElement : positionJsonArray) {
|
||||||
|
positions[i++] = jsonElement.getAsString();
|
||||||
|
}
|
||||||
|
user.setPositions(positions);
|
||||||
|
}
|
||||||
|
|
||||||
user.setUserId(GsonHelper.getString(o, "userid"));
|
user.setUserId(GsonHelper.getString(o, "userid"));
|
||||||
user.setName(GsonHelper.getString(o, "name"));
|
user.setName(GsonHelper.getString(o, "name"));
|
||||||
user.setPosition(GsonHelper.getString(o, "position"));
|
user.setPosition(GsonHelper.getString(o, "position"));
|
||||||
@ -198,6 +208,15 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
if (user.getPosition() != null) {
|
if (user.getPosition() != null) {
|
||||||
o.addProperty("position", user.getPosition());
|
o.addProperty("position", user.getPosition());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (user.getPositions() != null) {
|
||||||
|
JsonArray jsonArray = new JsonArray();
|
||||||
|
for (String position : user.getPositions()) {
|
||||||
|
jsonArray.add(new JsonPrimitive(position));
|
||||||
|
}
|
||||||
|
o.add("positions", jsonArray);
|
||||||
|
}
|
||||||
|
|
||||||
if (user.getMobile() != null) {
|
if (user.getMobile() != null) {
|
||||||
o.addProperty("mobile", user.getMobile());
|
o.addProperty("mobile", user.getMobile());
|
||||||
}
|
}
|
||||||
@ -265,6 +284,8 @@ public class WxCpUserGsonAdapter implements JsonDeserializer<WxCpUser>, JsonSeri
|
|||||||
attrsJsonArray.add(attrJson);
|
attrsJsonArray.add(attrJson);
|
||||||
|
|
||||||
if (attr.getType() == null) {
|
if (attr.getType() == null) {
|
||||||
|
attrJson.addProperty("name", attr.getName());
|
||||||
|
attrJson.addProperty("value", attr.getTextValue());
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -0,0 +1,89 @@
|
|||||||
|
package me.chanjar.weixin.cp.util.json;
|
||||||
|
|
||||||
|
import me.chanjar.weixin.cp.bean.WxCpUser;
|
||||||
|
import org.testng.annotations.Test;
|
||||||
|
|
||||||
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <pre>
|
||||||
|
* 企业微信(私有化版本getUser兼容测试)
|
||||||
|
* </pre>
|
||||||
|
*
|
||||||
|
* @author 庄壮壮
|
||||||
|
* @since 2020-06-16 09:36
|
||||||
|
*/
|
||||||
|
public class WxCpUserGsonAdapterForPrivatizedVersionTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testDeserialize() {
|
||||||
|
final String userJson = "{\n" +
|
||||||
|
" \"errcode\": 0,\n" +
|
||||||
|
" \"errmsg\": \"ok\",\n" +
|
||||||
|
" \"userid\": \"zhangsan\",\n" +
|
||||||
|
" \"name\": \"李四\",\n" +
|
||||||
|
" \"department\": [1, 2],\n" +
|
||||||
|
" \"order\": [2, 10],\n" +
|
||||||
|
" \"position\": \"后台工程师1\",\n" +
|
||||||
|
" \"positions\": [\"后台工程师1\",\"后台工程师2\"],\n" +
|
||||||
|
" \"mobile\": \"15913215421\",\n" +
|
||||||
|
" \"hide_mobile\": 0,\n" +
|
||||||
|
" \"gender\": \"1\",\n" +
|
||||||
|
" \"email\": \"zhangsan@gzdev.com\",\n" +
|
||||||
|
" \"is_leader_in_dept\": [1, 0],\n" +
|
||||||
|
" \"avatar\": \"http://wx.qlogo.cn/mmopen/ajNVdqHZLLA3WJ6DSZUfiakYe37PKnQhBIeOQBO4czqrnZDS79FH5Wm5m4X69TBicnHFlhiafvDwklOpZeXYQQ2icg/0\",\n" +
|
||||||
|
" \"telephone\": \"020-123456\",\n" +
|
||||||
|
" \"english_name\": \"jackzhang\",\n" +
|
||||||
|
" \"extattr\": {\"attrs\":[{\"name\":\"爱好\",\"value\":\"旅游\"},{\"name\":\"卡号\",\"value\":\"1234567234\"}]},\n" +
|
||||||
|
" \"status\": 1,\n" +
|
||||||
|
" \"enable\": 0,\n" +
|
||||||
|
" \"qr_code\": \"https://wwlocal.qq.com/wework_admin/userQRCode?vcode=vc2140a8b3c6207c74&lvc=vcf6f1acfdc4b45088\"\n" +
|
||||||
|
"}";
|
||||||
|
|
||||||
|
final WxCpUser user = WxCpUser.fromJson(userJson);
|
||||||
|
assertThat(user).isNotNull();
|
||||||
|
|
||||||
|
// test order
|
||||||
|
assertThat(user.getOrders()).isNotEmpty();
|
||||||
|
assertThat(user.getOrders().length).isEqualTo(2);
|
||||||
|
assertThat(user.getOrders()[0]).isEqualTo(2);
|
||||||
|
assertThat(user.getOrders()[1]).isEqualTo(10);
|
||||||
|
|
||||||
|
// test english name
|
||||||
|
assertThat(user.getEnglishName()).isEqualTo("jackzhang");
|
||||||
|
|
||||||
|
// test extattrs
|
||||||
|
assertThat(user.getExtAttrs()).isNotEmpty();
|
||||||
|
final WxCpUser.Attr extraAttr1 = user.getExtAttrs().get(0);
|
||||||
|
assertThat(extraAttr1.getName()).isEqualTo("爱好");
|
||||||
|
assertThat(extraAttr1.getTextValue()).isEqualTo("旅游");
|
||||||
|
final WxCpUser.Attr extraAttr2 = user.getExtAttrs().get(1);
|
||||||
|
assertThat(extraAttr2.getName()).isEqualTo("卡号");
|
||||||
|
assertThat(extraAttr2.getTextValue()).isEqualTo("1234567234");
|
||||||
|
|
||||||
|
// test position
|
||||||
|
assertThat(user.getPosition()).isEqualTo("后台工程师1");
|
||||||
|
// test positions
|
||||||
|
assertThat(user.getPositions()).isNotEmpty();
|
||||||
|
assertThat(user.getPositions().length).isEqualTo(2);
|
||||||
|
assertThat(user.getPositions()[0]).isEqualTo("后台工程师1");
|
||||||
|
assertThat(user.getPositions()[1]).isEqualTo("后台工程师2");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSerialize() {
|
||||||
|
WxCpUser user = new WxCpUser();
|
||||||
|
user.setOrders(new Integer[]{1, 2});
|
||||||
|
user.setPositions(new String[]{"后台工程师1", "后台工程师2"});
|
||||||
|
user.setEnglishName("jackson");
|
||||||
|
WxCpUser.Attr attr1 = new WxCpUser.Attr();
|
||||||
|
attr1.setName("爱好").setTextValue("旅游");
|
||||||
|
WxCpUser.Attr attr2 = new WxCpUser.Attr();
|
||||||
|
attr2.setName("卡号").setTextValue("1234567234");
|
||||||
|
|
||||||
|
user.addExtAttr(attr1);
|
||||||
|
user.addExtAttr(attr2);
|
||||||
|
|
||||||
|
assertThat(user.toJson()).isEqualTo("{\"order\":[1,2],\"positions\":[\"后台工程师1\",\"后台工程师2\"],\"english_name\":\"jackson\",\"extattr\":{\"attrs\":[{\"name\":\"爱好\",\"value\":\"旅游\"},{\"name\":\"卡号\",\"value\":\"1234567234\"}]},\"external_profile\":{}}");
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user