Skip to content

Commit c4a8796

Browse files
committed
🐛 #1969 【企业微信】修复第三方应用获取登录用户信息接口方法里的错误代码
1 parent 596aafc commit c4a8796

File tree

4 files changed

+113
-80
lines changed

4 files changed

+113
-80
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import lombok.Setter;
66
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
77

8+
import java.io.Serializable;
9+
810
/**
911
* @author yqx
1012
* @date 2020/3/16
1113
*/
1214
@Getter
1315
@Setter
14-
public class WxCpBaseResp {
16+
public class WxCpBaseResp implements Serializable {
17+
private static final long serialVersionUID = -4301684507150486556L;
18+
1519
@SerializedName("errcode")
1620
protected Long errcode;
1721

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

+26-12
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,23 @@
22

33
import com.google.gson.annotations.SerializedName;
44
import lombok.Data;
5+
import lombok.EqualsAndHashCode;
56
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
67

8+
import java.io.Serializable;
79
import java.util.List;
810

911
/**
10-
* @description: 登录信息
11-
* @author: Jamie.shi
12-
* @create: 2020-08-03 17:18
12+
* 登录信息
13+
*
14+
* @author Jamie.shi
15+
* @date 2020-08-03 17:18
1316
**/
1417
@Data
18+
@EqualsAndHashCode(callSuper = true)
1519
public class WxTpLoginInfo extends WxCpBaseResp {
20+
private static final long serialVersionUID = -6994487991072386856L;
21+
1622
@SerializedName("usertype")
1723
private Integer userType;
1824
@SerializedName("user_info")
@@ -23,8 +29,14 @@ public class WxTpLoginInfo extends WxCpBaseResp {
2329
private AuthInfo authInfo;
2430
private List<Agent> agent;
2531

32+
public static WxTpLoginInfo fromJson(String json) {
33+
return WxCpGsonBuilder.create().fromJson(json, WxTpLoginInfo.class);
34+
}
35+
2636
@Data
27-
public static class UserInfo {
37+
public static class UserInfo implements Serializable {
38+
private static final long serialVersionUID = -4558358748587735192L;
39+
2840
@SerializedName("userid")
2941
private String userId;
3042
@SerializedName("open_userid")
@@ -34,32 +46,34 @@ public static class UserInfo {
3446
}
3547

3648
@Data
37-
public static class CorpInfoBean {
49+
public static class CorpInfoBean implements Serializable {
50+
private static final long serialVersionUID = -3160146744148144984L;
51+
3852
@SerializedName("corpid")
3953
private String corpId;
4054
}
4155

4256
@Data
43-
public static class AuthInfo {
57+
public static class AuthInfo implements Serializable {
58+
private static final long serialVersionUID = -8697184659526210472L;
59+
4460
private List<Department> department;
4561

4662
@Data
47-
public static class Department {
63+
public static class Department implements Serializable {
64+
private static final long serialVersionUID = -4389328276936557541L;
4865

4966
private int id;
5067
private boolean writable;
5168
}
5269
}
5370

5471
@Data
55-
public static class Agent {
72+
public static class Agent implements Serializable {
73+
private static final long serialVersionUID = 1461544500964159037L;
5674
@SerializedName("agentid")
5775
private int agentId;
5876
@SerializedName("auth_type")
5977
private int authType;
6078
}
61-
62-
public static WxTpLoginInfo fromJson(String json) {
63-
return WxCpGsonBuilder.create().fromJson(json, WxTpLoginInfo.class);
64-
}
6579
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java

+81-66
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public interface WxCpTpService {
3434
*
3535
* @return the suite access token
3636
* @throws WxErrorException the wx error exception
37-
* @see #getSuiteAccessToken(boolean) #getSuiteAccessToken(boolean)
37+
* @see #getSuiteAccessToken(boolean) #getSuiteAccessToken(boolean)#getSuiteAccessToken(boolean)
3838
*/
3939
String getSuiteAccessToken() throws WxErrorException;
4040

@@ -58,10 +58,23 @@ public interface WxCpTpService {
5858
*
5959
* @return the suite ticket
6060
* @throws WxErrorException the wx error exception
61-
* @see #getSuiteTicket(boolean) #getSuiteTicket(boolean)
61+
* @see #getSuiteTicket(boolean) #getSuiteTicket(boolean)#getSuiteTicket(boolean)
6262
*/
6363
String getSuiteTicket() throws WxErrorException;
6464

65+
/**
66+
* <pre>
67+
* 保存企业微信定时推送的suite_ticket,(每10分钟)
68+
* 详情请见:https://work.weixin.qq.com/api/doc#90001/90143/90628
69+
*
70+
* 注意:微信不是固定10分钟推送suite_ticket的, 且suite_ticket的有效期为30分钟
71+
* https://work.weixin.qq.com/api/doc/10975#%E8%8E%B7%E5%8F%96%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E5%87%AD%E8%AF%81
72+
* </pre>
73+
*
74+
* @param suiteTicket the suite ticket
75+
*/
76+
void setSuiteTicket(String suiteTicket);
77+
6578
/**
6679
* <pre>
6780
* 获得suite_ticket
@@ -73,8 +86,8 @@ public interface WxCpTpService {
7386
* @param forceRefresh 强制刷新
7487
* @return the suite ticket
7588
* @throws WxErrorException the wx error exception
76-
* @Deprecated 由于无法主动刷新,所以这个接口实际已经没有意义,需要在接收企业微信的主动推送后,保存这个ticket
77-
* @see #setSuiteTicket(String)
89+
* @deprecated 由于无法主动刷新 ,所以这个接口实际已经没有意义,需要在接收企业微信的主动推送后,保存这个ticket
90+
* @see #setSuiteTicket(String) #setSuiteTicket(String)
7891
*/
7992
@Deprecated
8093
String getSuiteTicket(boolean forceRefresh) throws WxErrorException;
@@ -88,21 +101,8 @@ public interface WxCpTpService {
88101
* https://work.weixin.qq.com/api/doc/10975#%E8%8E%B7%E5%8F%96%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E5%87%AD%E8%AF%81
89102
* </pre>
90103
*
91-
* @param suiteTicket
92-
*/
93-
void setSuiteTicket(String suiteTicket);
94-
95-
/**
96-
* <pre>
97-
* 保存企业微信定时推送的suite_ticket,(每10分钟)
98-
* 详情请见:https://work.weixin.qq.com/api/doc#90001/90143/90628
99-
*
100-
* 注意:微信不是固定10分钟推送suite_ticket的, 且suite_ticket的有效期为30分钟
101-
* https://work.weixin.qq.com/api/doc/10975#%E8%8E%B7%E5%8F%96%E7%AC%AC%E4%B8%89%E6%96%B9%E5%BA%94%E7%94%A8%E5%87%AD%E8%AF%81
102-
* </pre>
103-
*
104-
* @param suiteTicket
105-
* @param expiresInSeconds
104+
* @param suiteTicket the suite ticket
105+
* @param expiresInSeconds the expires in seconds
106106
*/
107107
void setSuiteTicket(String suiteTicket, int expiresInSeconds);
108108

@@ -111,6 +111,7 @@ public interface WxCpTpService {
111111
*
112112
* @param authCorpId 授权企业的cropId
113113
* @return jsapi ticket
114+
* @throws WxErrorException the wx error exception
114115
*/
115116
String getSuiteJsApiTicket(String authCorpId) throws WxErrorException;
116117

@@ -172,14 +173,12 @@ public interface WxCpTpService {
172173
/**
173174
* <pre>
174175
* 获取预授权链接,测试环境下使用
175-
* @Link https://work.weixin.qq.com/api/doc/90001/90143/90602
176-
* </pre>
177-
*
178176
* @param redirectUri 授权完成后的回调网址
179-
* @param state a-zA-Z0-9的参数值(不超过128个字节),用于第三方自行校验session,防止跨域攻击
180-
* @param authType 授权类型:0 正式授权, 1 测试授权。
177+
* @param state a-zA-Z0-9的参数值(不超过128个字节),用于第三方自行校验session,防止跨域攻击
178+
* @param authType 授权类型:0 正式授权, 1 测试授权。
181179
* @return pre auth url
182180
* @throws WxErrorException the wx error exception
181+
* @Link https ://work.weixin.qq.com/api/doc/90001/90143/90602 </pre>
183182
*/
184183
String getPreAuthUrl(String redirectUri, String state, int authType) throws WxErrorException;
185184

@@ -198,6 +197,7 @@ public interface WxCpTpService {
198197
*
199198
* @param authCorpId 授权企业的cropId
200199
* @return jsapi ticket
200+
* @throws WxErrorException the wx error exception
201201
*/
202202
String getAuthCorpJsApiTicket(String authCorpId) throws WxErrorException;
203203

@@ -267,7 +267,7 @@ public interface WxCpTpService {
267267
* 获取WxMpConfigStorage 对象.
268268
*
269269
* @return WxMpConfigStorage wx cp tp config storage
270-
* @deprecated storage应该在service内部使用,提供这个接口,容易破坏这个封装
270+
* @deprecated storage应该在service内部使用 ,提供这个接口,容易破坏这个封装
271271
*/
272272
@Deprecated
273273
WxCpTpConfigStorage getWxCpTpConfigStorage();
@@ -298,8 +298,9 @@ public interface WxCpTpService {
298298
* 获取访问用户身份
299299
* </pre>
300300
*
301-
* @param code
302-
* @return
301+
* @param code the code
302+
* @return user info 3 rd
303+
* @throws WxErrorException the wx error exception
303304
*/
304305
WxCpTpUserInfo getUserInfo3rd(String code) throws WxErrorException;
305306

@@ -308,94 +309,108 @@ public interface WxCpTpService {
308309
* 获取访问用户敏感信息
309310
* </pre>
310311
*
311-
* @param userTicket
312-
* @return
312+
* @param userTicket the user ticket
313+
* @return user detail 3 rd
314+
* @throws WxErrorException the wx error exception
313315
*/
314316
WxCpTpUserDetail getUserDetail3rd(String userTicket) throws WxErrorException;
315317

316318
/**
317-
* 企业用户登录信息
318-
* @param authCode
319-
* @return
320-
* @throws WxErrorException
319+
* 获取登录用户信息
320+
*
321+
* 文档地址:https://work.weixin.qq.com/api/doc/90001/90143/91125
322+
* @param authCode the auth code
323+
* @return login info
324+
* @throws WxErrorException the wx error exception
321325
*/
322326
WxTpLoginInfo getLoginInfo(String authCode) throws WxErrorException;
323327

324328
/**
325329
* 获取服务商providerToken
326-
* @return
327-
* @throws WxErrorException
330+
*
331+
* @return the wx cp provider token
332+
* @throws WxErrorException the wx error exception
328333
*/
329334
String getWxCpProviderToken() throws WxErrorException;
330335

331336
/**
332337
* get contact service
333-
* @return WxCpTpContactService
338+
*
339+
* @return WxCpTpContactService wx cp tp contact service
334340
*/
335341
WxCpTpContactService getWxCpTpContactService();
336342

337-
/**
338-
* get department service
339-
* @return WxCpTpDepartmentService
340-
*/
341-
WxCpTpDepartmentService getWxCpTpDepartmentService();
342-
343-
/**
344-
* get media service
345-
* @return WxCpTpMediaService
346-
*/
347-
WxCpTpMediaService getWxCpTpMediaService();
348-
349-
/**
350-
* get oa service
351-
* @return WxCpTpOAService
352-
*/
353-
WxCpTpOAService getWxCpTpOAService();
354-
355-
/**
356-
* get user service
357-
* @return WxCpTpUserService
358-
*/
359-
WxCpTpUserService getWxCpTpUserService();
360-
361343
/**
362344
* set contact service
345+
*
363346
* @param wxCpTpContactService the contact service
364347
*/
365348
void setWxCpTpContactService(WxCpTpContactService wxCpTpContactService);
366349

350+
/**
351+
* get department service
352+
*
353+
* @return WxCpTpDepartmentService wx cp tp department service
354+
*/
355+
WxCpTpDepartmentService getWxCpTpDepartmentService();
356+
367357
/**
368358
* set department service
359+
*
369360
* @param wxCpTpDepartmentService the department service
370361
*/
371362
void setWxCpTpDepartmentService(WxCpTpDepartmentService wxCpTpDepartmentService);
372363

364+
/**
365+
* get media service
366+
*
367+
* @return WxCpTpMediaService wx cp tp media service
368+
*/
369+
WxCpTpMediaService getWxCpTpMediaService();
370+
373371
/**
374372
* set media service
373+
*
375374
* @param wxCpTpMediaService the media service
376375
*/
377376
void setWxCpTpMediaService(WxCpTpMediaService wxCpTpMediaService);
378377

378+
/**
379+
* get oa service
380+
*
381+
* @return WxCpTpOAService wx cp tp oa service
382+
*/
383+
WxCpTpOAService getWxCpTpOAService();
384+
379385
/**
380386
* set oa service
387+
*
381388
* @param wxCpTpOAService the oa service
382389
*/
383390
void setWxCpTpOAService(WxCpTpOAService wxCpTpOAService);
384391

392+
/**
393+
* get user service
394+
*
395+
* @return WxCpTpUserService wx cp tp user service
396+
*/
397+
WxCpTpUserService getWxCpTpUserService();
398+
385399
/**
386400
* set user service
401+
*
387402
* @param wxCpTpUserService the set user service
388403
*/
389404
void setWxCpTpUserService(WxCpTpUserService wxCpTpUserService);
390405

391406
/**
392407
* 获取应用的管理员列表
393-
* @param authCorpId
394-
* @param agentId
395-
* @return
408+
*
409+
* @param authCorpId the auth corp id
410+
* @param agentId the agent id
411+
* @return admin list
412+
* @throws WxErrorException the wx error exception
396413
*/
397-
WxCpTpAdmin getAdminList(String authCorpId,Integer agentId) throws WxErrorException;
398-
399-
414+
WxCpTpAdmin getAdminList(String authCorpId, Integer agentId) throws WxErrorException;
400415

401416
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -401,7 +401,7 @@ public WxCpTpUserDetail getUserDetail3rd(String userTicket) throws WxErrorExcept
401401
public WxTpLoginInfo getLoginInfo(String authCode) throws WxErrorException {
402402
JsonObject jsonObject = new JsonObject();
403403
jsonObject.addProperty("auth_code", authCode);
404-
jsonObject.addProperty("access_token", configStorage.getAccessToken(authCode));
404+
jsonObject.addProperty("access_token", configStorage.getProviderToken());
405405
String responseText = post(configStorage.getApiUrl(GET_LOGIN_INFO), jsonObject.toString());
406406
return WxTpLoginInfo.fromJson(responseText);
407407
}

0 commit comments

Comments
 (0)