Skip to content

Commit 867f8e4

Browse files
authored
🆕 #2707【企业微信】家校沟通-增加学生与家长部分接口
1 parent 2ed1a5f commit 867f8e4

File tree

8 files changed

+493
-0
lines changed

8 files changed

+493
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.NonNull;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest;
7+
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest;
8+
9+
import java.util.List;
10+
11+
/**
12+
* 企业微信家校沟通相关接口.
13+
* https://developer.work.weixin.qq.com/document/path/91638
14+
*
15+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
16+
* @date: 2022/6/18 9:10
17+
*/
18+
public interface WxCpSchoolUserService {
19+
20+
/**
21+
* 创建学生
22+
* 请求方式:POST(HTTPS)
23+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/create_student?access_token=ACCESS_TOKEN
24+
*
25+
* @param studentUserId
26+
* @param name
27+
* @param departments
28+
* @return
29+
* @throws WxErrorException
30+
*/
31+
WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException;
32+
33+
/**
34+
* 删除学生
35+
* 请求方式:GET(HTTPS)
36+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/delete_student?access_token=ACCESS_TOKEN&userid=USERID
37+
*
38+
* @param studentUserId
39+
* @return
40+
* @throws WxErrorException
41+
*/
42+
WxCpBaseResp deleteStudent(@NonNull String studentUserId) throws WxErrorException;
43+
44+
/**
45+
* 更新学生
46+
* 请求方式:POST(HTTPS)
47+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/update_student?access_token=ACCESS_TOKEN
48+
*
49+
* @param studentUserId
50+
* @param newStudentUserId
51+
* @param name
52+
* @param departments
53+
* @return
54+
* @throws WxErrorException
55+
*/
56+
WxCpBaseResp updateStudent(@NonNull String studentUserId, String newStudentUserId, String name, List<Integer> departments) throws WxErrorException;
57+
58+
/**
59+
* 创建家长
60+
* 请求方式:POST(HTTPS)
61+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/create_parent?access_token=ACCESS_TOKEN
62+
*
63+
* @param request
64+
* @return
65+
* @throws WxErrorException
66+
*/
67+
WxCpBaseResp createParent(@NonNull WxCpCreateParentRequest request) throws WxErrorException;
68+
69+
/**
70+
* 更新家长
71+
* 请求方式:POST(HTTPS)
72+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/update_parent?access_token=ACCESS_TOKEN
73+
*
74+
* @param request
75+
* @return
76+
* @throws WxErrorException
77+
*/
78+
WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException;
79+
80+
/**
81+
* 删除家长
82+
* 请求方式:GET(HTTPS)
83+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/delete_parent?access_token=ACCESS_TOKEN&userid=USERID
84+
*
85+
* @param userId
86+
* @return
87+
* @throws WxErrorException
88+
*/
89+
WxCpBaseResp deleteParent(@NonNull String userId) throws WxErrorException;
90+
91+
/**
92+
* 设置家校通讯录自动同步模式
93+
* 企业和第三方可通过此接口修改家校通讯录与班级标签之间的自动同步模式,注意,一旦设置禁止自动同步,将无法再次开启。
94+
* <p>
95+
* 请求方式:POST(HTTPS)
96+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/set_arch_sync_mode?access_token=ACCESS_TOKEN
97+
*
98+
* @param archSyncMode 家校通讯录同步模式:1-禁止将标签同步至家校通讯录,2-禁止将家校通讯录同步至标签,3-禁止家校通讯录和标签相互同步
99+
* @return
100+
* @throws WxErrorException
101+
*/
102+
WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException;
103+
104+
}

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

+7
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,13 @@ public interface WxCpService extends WxService {
407407
*/
408408
WxCpSchoolService getSchoolService();
409409

410+
/**
411+
* 获取家校沟通相关接口的服务类对象
412+
*
413+
* @return
414+
*/
415+
WxCpSchoolUserService getSchoolUserService();
416+
410417
/**
411418
* 获取家校应用健康上报的服务类对象
412419
*

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

+6
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public abstract class BaseWxCpServiceImpl<H, P> implements WxCpService, RequestH
5050
private WxCpAgentService agentService = new WxCpAgentServiceImpl(this);
5151
private WxCpOaService oaService = new WxCpOaServiceImpl(this);
5252
private WxCpSchoolService schoolService = new WxCpSchoolServiceImpl(this);
53+
private WxCpSchoolUserService schoolUserService = new WxCpSchoolUserServiceImpl(this);
5354
private WxCpSchoolHealthService schoolHealthService = new WxCpSchoolHealthServiceImpl(this);
5455
private WxCpLivingService livingService = new WxCpLivingServiceImpl(this);
5556
private WxCpOaAgentService oaAgentService = new WxCpOaAgentServiceImpl(this);
@@ -500,6 +501,11 @@ public WxCpSchoolService getSchoolService() {
500501
return schoolService;
501502
}
502503

504+
@Override
505+
public WxCpSchoolUserService getSchoolUserService() {
506+
return schoolUserService;
507+
}
508+
503509
@Override
504510
public WxCpSchoolHealthService getSchoolHealthService() {
505511
return schoolHealthService;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import com.google.gson.JsonArray;
4+
import com.google.gson.JsonObject;
5+
import com.google.gson.JsonPrimitive;
6+
import lombok.NonNull;
7+
import lombok.RequiredArgsConstructor;
8+
import lombok.extern.slf4j.Slf4j;
9+
import me.chanjar.weixin.common.error.WxErrorException;
10+
import me.chanjar.weixin.cp.api.WxCpSchoolUserService;
11+
import me.chanjar.weixin.cp.api.WxCpService;
12+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
13+
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest;
14+
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest;
15+
import org.apache.commons.lang3.StringUtils;
16+
17+
import java.util.List;
18+
19+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.School.*;
20+
21+
/**
22+
* 企业微信家校沟通相关接口.
23+
* https://developer.work.weixin.qq.com/document/path/91638
24+
*
25+
* @author <a href="https://github.com/0katekate0">Wang_Wong</a>
26+
* @date: 2022/6/18 9:10
27+
*/
28+
@Slf4j
29+
@RequiredArgsConstructor
30+
public class WxCpSchoolUserServiceImpl implements WxCpSchoolUserService {
31+
32+
private final WxCpService cpService;
33+
34+
@Override
35+
public WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException {
36+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(CREATE_STUDENT);
37+
JsonObject jsonObject = new JsonObject();
38+
jsonObject.addProperty("student_userid", studentUserId);
39+
jsonObject.addProperty("name", name);
40+
JsonArray jsonArray = new JsonArray();
41+
for (Integer depart : departments) {
42+
jsonArray.add(new JsonPrimitive(depart));
43+
}
44+
jsonObject.add("department", jsonArray);
45+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
46+
return WxCpBaseResp.fromJson(responseContent);
47+
}
48+
49+
@Override
50+
public WxCpBaseResp deleteStudent(@NonNull String studentUserId) throws WxErrorException {
51+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DELETE_STUDENT) + studentUserId;
52+
String responseContent = this.cpService.get(apiUrl, null);
53+
return WxCpBaseResp.fromJson(responseContent);
54+
}
55+
56+
@Override
57+
public WxCpBaseResp updateStudent(@NonNull String studentUserId, String newStudentUserId, String name, List<Integer> departments) throws WxErrorException {
58+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_STUDENT);
59+
JsonObject jsonObject = new JsonObject();
60+
jsonObject.addProperty("student_userid", studentUserId);
61+
if (StringUtils.isNotEmpty(newStudentUserId)) {
62+
jsonObject.addProperty("new_student_userid", newStudentUserId);
63+
}
64+
if (StringUtils.isNotEmpty(name)) {
65+
jsonObject.addProperty("name", name);
66+
}
67+
if (departments != null && departments.size() > 0) {
68+
JsonArray jsonArray = new JsonArray();
69+
for (Integer depart : departments) {
70+
jsonArray.add(new JsonPrimitive(depart));
71+
}
72+
jsonObject.add("department", jsonArray);
73+
}
74+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
75+
return WxCpBaseResp.fromJson(responseContent);
76+
}
77+
78+
@Override
79+
public WxCpBaseResp createParent(@NonNull WxCpCreateParentRequest request) throws WxErrorException {
80+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(CREATE_PARENT);
81+
String responseContent = this.cpService.post(apiUrl, request.toJson());
82+
return WxCpBaseResp.fromJson(responseContent);
83+
}
84+
85+
@Override
86+
public WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException {
87+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_PARENT);
88+
String responseContent = this.cpService.post(apiUrl, request.toJson());
89+
return WxCpBaseResp.fromJson(responseContent);
90+
}
91+
92+
@Override
93+
public WxCpBaseResp deleteParent(@NonNull String userId) throws WxErrorException {
94+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DELETE_PARENT) + userId;
95+
String responseContent = this.cpService.get(apiUrl, null);
96+
return WxCpBaseResp.fromJson(responseContent);
97+
}
98+
99+
@Override
100+
public WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException {
101+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_ARCH_SYNC_MODE);
102+
JsonObject jsonObject = new JsonObject();
103+
jsonObject.addProperty("arch_sync_mode", archSyncMode);
104+
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
105+
return WxCpBaseResp.fromJson(responseContent);
106+
}
107+
108+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 创建家长请求.
13+
*
14+
* @author Wang_Wong
15+
* @date 2022-06-20
16+
*/
17+
@Data
18+
@Builder
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
@Accessors(chain = true)
22+
public class WxCpCreateParentRequest implements Serializable {
23+
private static final long serialVersionUID = -4960239393895754138L;
24+
25+
@SerializedName("parent_userid")
26+
private String parentUserId;
27+
28+
@SerializedName("mobile")
29+
private String mobile;
30+
31+
@SerializedName("to_invite")
32+
private Boolean toInvite;
33+
34+
@SerializedName("children")
35+
private List<Children> children;
36+
37+
@Setter
38+
@Getter
39+
public static class Children implements Serializable {
40+
41+
@SerializedName("student_userid")
42+
private String studentUserId;
43+
44+
@SerializedName("relation")
45+
private String relation;
46+
47+
public static Children fromJson(String json) {
48+
return WxCpGsonBuilder.create().fromJson(json, Children.class);
49+
}
50+
51+
public String toJson() {
52+
return WxCpGsonBuilder.create().toJson(this);
53+
}
54+
55+
}
56+
57+
public static WxCpCreateParentRequest fromJson(String json) {
58+
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateParentRequest.class);
59+
}
60+
61+
public String toJson() {
62+
return WxCpGsonBuilder.create().toJson(this);
63+
}
64+
65+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 更新家长请求.
13+
*
14+
* @author Wang_Wong
15+
* @date 2022-06-20
16+
*/
17+
@Data
18+
@Builder
19+
@NoArgsConstructor
20+
@AllArgsConstructor
21+
@Accessors(chain = true)
22+
public class WxCpUpdateParentRequest implements Serializable {
23+
private static final long serialVersionUID = -4960239393895754138L;
24+
25+
@SerializedName("parent_userid")
26+
private String parentUserId;
27+
28+
@SerializedName("mobile")
29+
private String mobile;
30+
31+
@SerializedName("new_parent_userid")
32+
private String newParentUserId;
33+
34+
@SerializedName("children")
35+
private List<Children> children;
36+
37+
@Setter
38+
@Getter
39+
public static class Children implements Serializable {
40+
41+
@SerializedName("student_userid")
42+
private String studentUserId;
43+
44+
@SerializedName("relation")
45+
private String relation;
46+
47+
public static Children fromJson(String json) {
48+
return WxCpGsonBuilder.create().fromJson(json, Children.class);
49+
}
50+
51+
public String toJson() {
52+
return WxCpGsonBuilder.create().toJson(this);
53+
}
54+
55+
}
56+
57+
public static WxCpUpdateParentRequest fromJson(String json) {
58+
return WxCpGsonBuilder.create().fromJson(json, WxCpUpdateParentRequest.class);
59+
}
60+
61+
public String toJson() {
62+
return WxCpGsonBuilder.create().toJson(this);
63+
}
64+
65+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+8
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,14 @@ interface School {
183183
String GET_STUDENT_CUSTOMIZE_HEALTH_INFO = "/cgi-bin/school/user/get_student_customize_health_info";
184184
String GET_HEALTH_QRCODE = "/cgi-bin/school/user/get_health_qrcode";
185185

186+
String CREATE_STUDENT = "/cgi-bin/school/user/create_student";
187+
String DELETE_STUDENT = "/cgi-bin/school/user/delete_student?userid=";
188+
String UPDATE_STUDENT = "/cgi-bin/school/user/update_student";
189+
String CREATE_PARENT = "/cgi-bin/school/user/create_parent";
190+
String UPDATE_PARENT = "/cgi-bin/school/user/update_parent";
191+
String DELETE_PARENT = "/cgi-bin/school/user/delete_parent?userid=";
192+
String SET_ARCH_SYNC_MODE = "/cgi-bin/school/set_arch_sync_mode";
193+
186194
String GET_PAYMENT_RESULT = "/cgi-bin/school/get_payment_result";
187195
String GET_TRADE = "/cgi-bin/school/get_trade";
188196

0 commit comments

Comments
 (0)