Skip to content

Commit bac1853

Browse files
authored
🆕 #2746 【企业微信】 增加读取学生或家长所有接口支持
1 parent e0f3c76 commit bac1853

File tree

8 files changed

+536
-0
lines changed

8 files changed

+536
-0
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,40 @@ public interface WxCpSchoolUserService {
158158
*/
159159
WxCpBatchResultList batchUpdateParent(@NonNull WxCpBatchUpdateParentRequest request) throws WxErrorException;
160160

161+
/**
162+
* 读取学生或家长
163+
* 请求方式:GET(HTTPS)
164+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/get?access_token=ACCESS_TOKEN&userid=USERID
165+
*
166+
* @param userId
167+
* @return
168+
* @throws WxErrorException
169+
*/
170+
WxCpUserResult getUser(@NonNull String userId) throws WxErrorException;
171+
172+
/**
173+
* 获取部门成员详情
174+
* 请求方式:GET(HTTPS)
175+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD
176+
*
177+
* @param departmentId 获取的部门id
178+
* @param fetchChild 1/0:是否递归获取子部门下面的成员
179+
* @return
180+
* @throws WxErrorException
181+
*/
182+
WxCpUserListResult getUserList(@NonNull Integer departmentId, Integer fetchChild) throws WxErrorException;
183+
184+
/**
185+
* 获取部门家长详情
186+
* 请求方式:GET(HTTPS)
187+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/list_parent?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID
188+
*
189+
* @param departmentId 获取的部门id
190+
* @return
191+
* @throws WxErrorException
192+
*/
193+
WxCpListParentResult getUserListParent(@NonNull Integer departmentId) throws WxErrorException;
194+
161195
/**
162196
* 更新家长
163197
* 请求方式:POST(HTTPS)

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,27 @@ public WxCpBatchResultList batchUpdateParent(@NonNull WxCpBatchUpdateParentReque
142142
return WxCpBatchResultList.fromJson(responseContent);
143143
}
144144

145+
@Override
146+
public WxCpUserResult getUser(@NonNull String userId) throws WxErrorException {
147+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_USER) + userId;
148+
String responseContent = this.cpService.get(apiUrl, null);
149+
return WxCpUserResult.fromJson(responseContent);
150+
}
151+
152+
@Override
153+
public WxCpUserListResult getUserList(@NonNull Integer departmentId, Integer fetchChild) throws WxErrorException {
154+
String apiUrl = String.format(this.cpService.getWxCpConfigStorage().getApiUrl(GET_USER_LIST), departmentId, fetchChild);
155+
String responseContent = this.cpService.get(apiUrl, null);
156+
return WxCpUserListResult.fromJson(responseContent);
157+
}
158+
159+
@Override
160+
public WxCpListParentResult getUserListParent(@NonNull Integer departmentId) throws WxErrorException {
161+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_USER_LIST_PARENT) + departmentId;
162+
String responseContent = this.cpService.get(apiUrl, null);
163+
return WxCpListParentResult.fromJson(responseContent);
164+
}
165+
145166
@Override
146167
public WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException {
147168
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_PARENT);

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
* <pre>
1010
* 使用user_ticket获取成员详情接口返回类.
1111
* Created by BinaryWang on 2018/4/22.
12+
* 官方文档:https://developer.work.weixin.qq.com/document/path/91122
1213
* </pre>
1314
*
1415
* @author <a href="https://github.com/binarywang">Binary Wang</a>
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
import lombok.experimental.Accessors;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* 获取部门家长详情返回结果.
14+
*
15+
* @author Wang_Wong
16+
* @date 2022-07-13
17+
*/
18+
@Data
19+
@Builder
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
@Accessors(chain = true)
23+
public class WxCpListParentResult extends WxCpBaseResp implements Serializable {
24+
private static final long serialVersionUID = -4960239393895754138L;
25+
26+
@SerializedName("parents")
27+
private List<Parent> parents;
28+
29+
@Setter
30+
@Getter
31+
@Builder
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public static class Parent implements Serializable {
35+
36+
@SerializedName("parent_userid")
37+
private String parentUserId;
38+
39+
@SerializedName("mobile")
40+
private String mobile;
41+
42+
@SerializedName("external_userid")
43+
private String externalUserId;
44+
45+
@SerializedName("is_subscribe")
46+
private Integer isSubscribe;
47+
48+
@SerializedName("children")
49+
private List<Children> children;
50+
51+
public static Parent fromJson(String json) {
52+
return WxCpGsonBuilder.create().fromJson(json, Parent.class);
53+
}
54+
55+
public String toJson() {
56+
return WxCpGsonBuilder.create().toJson(this);
57+
}
58+
59+
}
60+
61+
@Setter
62+
@Getter
63+
@Builder
64+
@NoArgsConstructor
65+
@AllArgsConstructor
66+
public static class Children implements Serializable {
67+
68+
@SerializedName("student_userid")
69+
private String studentUserId;
70+
71+
@SerializedName("relation")
72+
private String relation;
73+
74+
@SerializedName("name")
75+
private String name;
76+
77+
public static Children fromJson(String json) {
78+
return WxCpGsonBuilder.create().fromJson(json, Children.class);
79+
}
80+
81+
public String toJson() {
82+
return WxCpGsonBuilder.create().toJson(this);
83+
}
84+
85+
}
86+
87+
public static WxCpListParentResult fromJson(String json) {
88+
return WxCpGsonBuilder.create().fromJson(json, WxCpListParentResult.class);
89+
}
90+
91+
public String toJson() {
92+
return WxCpGsonBuilder.create().toJson(this);
93+
}
94+
95+
}
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package me.chanjar.weixin.cp.bean.school.user;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
import lombok.experimental.Accessors;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* 获取部门成员详情返回结果.
14+
*
15+
* @author Wang_Wong
16+
* @date 2022-07-13
17+
*/
18+
@Data
19+
@Builder
20+
@NoArgsConstructor
21+
@AllArgsConstructor
22+
@Accessors(chain = true)
23+
public class WxCpUserListResult extends WxCpBaseResp implements Serializable {
24+
private static final long serialVersionUID = -4960239393895754138L;
25+
26+
@SerializedName("students")
27+
private List<Student> students;
28+
29+
@Setter
30+
@Getter
31+
@Builder
32+
@NoArgsConstructor
33+
@AllArgsConstructor
34+
public static class Parent implements Serializable {
35+
36+
@SerializedName("parent_userid")
37+
private String parentUserId;
38+
39+
@SerializedName("relation")
40+
private String relation;
41+
42+
@SerializedName("mobile")
43+
private String mobile;
44+
45+
@SerializedName("external_userid")
46+
private String externalUserId;
47+
48+
@SerializedName("is_subscribe")
49+
private Integer isSubscribe;
50+
51+
public static Parent fromJson(String json) {
52+
return WxCpGsonBuilder.create().fromJson(json, Parent.class);
53+
}
54+
55+
public String toJson() {
56+
return WxCpGsonBuilder.create().toJson(this);
57+
}
58+
59+
}
60+
61+
@Setter
62+
@Getter
63+
@Builder
64+
@NoArgsConstructor
65+
@AllArgsConstructor
66+
public static class Student implements Serializable {
67+
68+
@SerializedName("student_userid")
69+
private String studentUserId;
70+
71+
@SerializedName("name")
72+
private String name;
73+
74+
@SerializedName("department")
75+
private List<Integer> department;
76+
77+
@SerializedName("parents")
78+
private List<Parent> parents;
79+
80+
public static Student fromJson(String json) {
81+
return WxCpGsonBuilder.create().fromJson(json, Student.class);
82+
}
83+
84+
public String toJson() {
85+
return WxCpGsonBuilder.create().toJson(this);
86+
}
87+
88+
}
89+
90+
public static WxCpUserListResult fromJson(String json) {
91+
return WxCpGsonBuilder.create().fromJson(json, WxCpUserListResult.class);
92+
}
93+
94+
public String toJson() {
95+
return WxCpGsonBuilder.create().toJson(this);
96+
}
97+
98+
}

0 commit comments

Comments
 (0)