Skip to content

Commit 8ed0e78

Browse files
committed
#246 修复企业号用户信息相关属性,对比实际接口返回内容,移除已失效属性(weixinid、tel),添加缺失的属性(telephone, english_name, hide_mobile)
1 parent 228b379 commit 8ed0e78

23 files changed

+144
-86
lines changed

weixin-java-cp/pom.xml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
<groupId>redis.clients</groupId>
3535
<artifactId>jedis</artifactId>
3636
</dependency>
37+
<dependency>
38+
<groupId>org.slf4j</groupId>
39+
<artifactId>slf4j-api</artifactId>
40+
</dependency>
3741

3842
<dependency>
3943
<groupId>org.testng</groupId>
@@ -60,6 +64,11 @@
6064
<artifactId>jetty-servlet</artifactId>
6165
<scope>test</scope>
6266
</dependency>
67+
<dependency>
68+
<groupId>ch.qos.logback</groupId>
69+
<artifactId>logback-classic</artifactId>
70+
<scope>test</scope>
71+
</dependency>
6372
</dependencies>
6473

6574
<build>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/AbstractWxCpServiceImpl.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
public abstract class AbstractWxCpServiceImpl<H, P> implements WxCpService, RequestHttp<H, P> {
3636

37-
protected final Logger log = LoggerFactory.getLogger(AbstractWxCpServiceImpl.class);
37+
protected final Logger log = LoggerFactory.getLogger(this.getClass());
3838

3939
/**
4040
* 全局的是否正在刷新access token的锁
@@ -293,8 +293,7 @@ public List<WxCpUser> userList(Integer departId, Boolean fetchChild, Integer sta
293293
String responseContent = get(url, params);
294294
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
295295
return WxCpGsonBuilder.INSTANCE.create()
296-
.fromJson(
297-
tmpJsonElement.getAsJsonObject().get("userlist"),
296+
.fromJson( tmpJsonElement.getAsJsonObject().get("userlist"),
298297
new TypeToken<List<WxCpUser>>() {
299298
}.getType()
300299
);

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java

Lines changed: 33 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,21 @@
1414
public class WxCpUser implements Serializable {
1515

1616
private static final long serialVersionUID = -5696099236344075582L;
17-
private final List<Attr> extAttrs = new ArrayList<>();
1817
private String userId;
1918
private String name;
2019
private Integer[] departIds;
2120
private String position;
2221
private String mobile;
2322
private String gender;
24-
private String tel;
2523
private String email;
26-
private String weiXinId;
2724
private String avatar;
2825
private Integer status;
2926
private Integer enable;
27+
private Integer isLeader;
28+
private final List<Attr> extAttrs = new ArrayList<>();
29+
private Integer hideMobile;
30+
private String englishName;
31+
private String telephone;
3032

3133
public static WxCpUser fromJson(String json) {
3234
return WxCpGsonBuilder.INSTANCE.create().fromJson(json, WxCpUser.class);
@@ -80,12 +82,12 @@ public void setMobile(String mobile) {
8082
this.mobile = mobile;
8183
}
8284

83-
public String getTel() {
84-
return this.tel;
85+
public String getTelephone() {
86+
return this.telephone;
8587
}
8688

87-
public void setTel(String tel) {
88-
this.tel = tel;
89+
public void setTelephone(String telephone) {
90+
this.telephone = telephone;
8991
}
9092

9193
public String getEmail() {
@@ -96,14 +98,6 @@ public void setEmail(String email) {
9698
this.email = email;
9799
}
98100

99-
public String getWeiXinId() {
100-
return this.weiXinId;
101-
}
102-
103-
public void setWeiXinId(String weiXinId) {
104-
this.weiXinId = weiXinId;
105-
}
106-
107101
public String getAvatar() {
108102
return this.avatar;
109103
}
@@ -136,6 +130,30 @@ public List<Attr> getExtAttrs() {
136130
return this.extAttrs;
137131
}
138132

133+
public Integer getIsLeader() {
134+
return isLeader;
135+
}
136+
137+
public void setIsLeader(Integer isLeader) {
138+
this.isLeader = isLeader;
139+
}
140+
141+
public Integer getHideMobile() {
142+
return hideMobile;
143+
}
144+
145+
public void setHideMobile(Integer hideMobile) {
146+
this.hideMobile = hideMobile;
147+
}
148+
149+
public String getEnglishName() {
150+
return englishName;
151+
}
152+
153+
public void setEnglishName(String englishName) {
154+
this.englishName = englishName;
155+
}
156+
139157
public String toJson() {
140158
return WxCpGsonBuilder.INSTANCE.create().toJson(this);
141159
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/util/json/WxCpUserGsonAdapter.java

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@ public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC
2424
throws JsonParseException {
2525
JsonObject o = json.getAsJsonObject();
2626
WxCpUser user = new WxCpUser();
27-
user.setUserId(GsonHelper.getString(o, "userid"));
28-
user.setName(GsonHelper.getString(o, "name"));
2927

3028
if (o.get("department") != null) {
3129
JsonArray departJsonArray = o.get("department").getAsJsonArray();
@@ -37,14 +35,19 @@ public WxCpUser deserialize(JsonElement json, Type typeOfT, JsonDeserializationC
3735
user.setDepartIds(departIds);
3836
}
3937

38+
user.setUserId(GsonHelper.getString(o, "userid"));
39+
user.setName(GsonHelper.getString(o, "name"));
4040
user.setPosition(GsonHelper.getString(o, "position"));
4141
user.setMobile(GsonHelper.getString(o, "mobile"));
4242
user.setGender(GsonHelper.getString(o, "gender"));
43-
user.setTel(GsonHelper.getString(o, "tel"));
4443
user.setEmail(GsonHelper.getString(o, "email"));
45-
user.setWeiXinId(GsonHelper.getString(o, "weixinid"));
4644
user.setAvatar(GsonHelper.getString(o, "avatar"));
4745
user.setStatus(GsonHelper.getInteger(o, "status"));
46+
user.setEnable(GsonHelper.getInteger(o, "enable"));
47+
user.setIsLeader(GsonHelper.getInteger(o, "isleader"));
48+
user.setHideMobile(GsonHelper.getInteger(o, "hide_mobile"));
49+
user.setEnglishName(GsonHelper.getString(o, "english_name"));
50+
user.setTelephone(GsonHelper.getString(o, "telephone"));
4851

4952
if (GsonHelper.isNotNull(o.get("extattr"))) {
5053
JsonArray attrJsonElements = o.get("extattr").getAsJsonObject().get("attrs").getAsJsonArray();
@@ -84,15 +87,9 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon
8487
if (user.getGender() != null) {
8588
o.addProperty("gender", user.getGender());
8689
}
87-
if (user.getTel() != null) {
88-
o.addProperty("tel", user.getTel());
89-
}
9090
if (user.getEmail() != null) {
9191
o.addProperty("email", user.getEmail());
9292
}
93-
if (user.getWeiXinId() != null) {
94-
o.addProperty("weixinid", user.getWeiXinId());
95-
}
9693
if (user.getAvatar() != null) {
9794
o.addProperty("avatar", user.getAvatar());
9895
}
@@ -102,6 +99,18 @@ public JsonElement serialize(WxCpUser user, Type typeOfSrc, JsonSerializationCon
10299
if (user.getEnable() != null) {
103100
o.addProperty("enable", user.getEnable());
104101
}
102+
if (user.getIsLeader() != null) {
103+
o.addProperty("isleader", user.getIsLeader());
104+
}
105+
if (user.getHideMobile() != null) {
106+
o.addProperty("hide_mobile", user.getHideMobile());
107+
}
108+
if (user.getEnglishName() != null) {
109+
o.addProperty("english_name", user.getEnglishName());
110+
}
111+
if (user.getTelephone() != null) {
112+
o.addProperty("telephone", user.getTelephone());
113+
}
105114
if (user.getExtAttrs().size() > 0) {
106115
JsonArray attrsJsonArray = new JsonArray();
107116
for (WxCpUser.Attr attr : user.getExtAttrs()) {

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/ApiTestModule.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import com.thoughtworks.xstream.XStream;
66
import com.thoughtworks.xstream.annotations.XStreamAlias;
77
import me.chanjar.weixin.common.util.xml.XStreamInitializer;
8-
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
8+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
99

1010
import java.io.IOException;
1111
import java.io.InputStream;

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/apache/WxCpBaseAPITest.java renamed to weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpBaseAPITest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
package me.chanjar.weixin.cp.api.impl.apache;
1+
package me.chanjar.weixin.cp.api;
22

33
import com.google.inject.Inject;
44
import me.chanjar.weixin.common.exception.WxErrorException;
5-
import me.chanjar.weixin.cp.api.ApiTestModule;
6-
import me.chanjar.weixin.cp.api.WxCpConfigStorage;
5+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
76
import org.apache.commons.lang3.StringUtils;
8-
import org.testng.*;
9-
import org.testng.annotations.*;
7+
import org.testng.Assert;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
1010

1111
/**
1212
* 基础API测试
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
package me.chanjar.weixin.cp.api.impl.apache;
1+
package me.chanjar.weixin.cp.api;
22

33
import me.chanjar.weixin.common.bean.result.WxError;
44
import me.chanjar.weixin.common.exception.WxErrorException;
55
import me.chanjar.weixin.common.util.http.RequestExecutor;
6-
import me.chanjar.weixin.cp.api.WxCpService;
7-
import org.testng.annotations.*;
6+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
7+
import org.testng.annotations.DataProvider;
8+
import org.testng.annotations.Test;
89

910
import java.util.concurrent.ExecutionException;
1011
import java.util.concurrent.ExecutorService;

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpDepartAPITest.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,23 @@
22

33
import com.google.inject.Inject;
44
import me.chanjar.weixin.common.exception.WxErrorException;
5-
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
5+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
66
import me.chanjar.weixin.cp.bean.WxCpDepart;
7-
import org.testng.*;
8-
import org.testng.annotations.*;
7+
import org.testng.Assert;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
910

1011
import java.util.List;
1112

13+
import static org.testng.Assert.assertNotNull;
14+
import static org.testng.Assert.assertTrue;
15+
1216
/**
1317
* 测试部门接口
1418
*
1519
* @author Daniel Qian
1620
*/
17-
@Test(groups = "departAPI", dependsOnGroups = "baseAPI")
21+
@Test(groups = "departAPI")
1822
@Guice(modules = ApiTestModule.class)
1923
public class WxCpDepartAPITest {
2024

@@ -23,6 +27,7 @@ public class WxCpDepartAPITest {
2327

2428
protected WxCpDepart depart;
2529

30+
@Test
2631
public void testDepartCreate() throws WxErrorException {
2732
WxCpDepart cpDepart = new WxCpDepart();
2833
cpDepart.setName("子部门" + System.currentTimeMillis());
@@ -32,16 +37,16 @@ public void testDepartCreate() throws WxErrorException {
3237
System.out.println(departId);
3338
}
3439

35-
@Test(dependsOnMethods = "testDepartCreate")
40+
@Test//(dependsOnMethods = "testDepartCreate")
3641
public void testDepartGet() throws WxErrorException {
3742
System.out.println("=================获取部门");
3843
List<WxCpDepart> departList = this.wxCpService.departGet();
39-
Assert.assertNotNull(departList);
40-
Assert.assertTrue(departList.size() > 0);
44+
assertNotNull(departList);
45+
assertTrue(departList.size() > 0);
4146
for (WxCpDepart g : departList) {
4247
this.depart = g;
4348
System.out.println(this.depart.getId() + ":" + this.depart.getName());
44-
Assert.assertNotNull(g.getName());
49+
assertNotNull(g.getName());
4550
}
4651
}
4752

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpMediaAPITest.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,11 @@
44
import me.chanjar.weixin.common.api.WxConsts;
55
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
66
import me.chanjar.weixin.common.exception.WxErrorException;
7-
import me.chanjar.weixin.cp.api.impl.apache.WxCpServiceImpl;
8-
import org.testng.*;
9-
import org.testng.annotations.*;
7+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
8+
import org.testng.Assert;
9+
import org.testng.annotations.DataProvider;
10+
import org.testng.annotations.Guice;
11+
import org.testng.annotations.Test;
1012

1113
import java.io.IOException;
1214
import java.io.InputStream;
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
package me.chanjar.weixin.cp.api.impl.apache;
1+
package me.chanjar.weixin.cp.api;
22

33
import com.google.inject.Inject;
44
import me.chanjar.weixin.common.api.WxConsts;
55
import me.chanjar.weixin.common.exception.WxErrorException;
6-
import me.chanjar.weixin.cp.api.ApiTestModule;
6+
import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
77
import me.chanjar.weixin.cp.bean.WxCpMessage;
8-
import org.testng.annotations.*;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
910

1011
/***
1112
* 测试发送消息

0 commit comments

Comments
 (0)