-
-
Notifications
You must be signed in to change notification settings - Fork 8.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ed1a5f
commit 867f8e4
Showing
8 changed files
with
493 additions
and
0 deletions.
There are no files selected for viewing
104 changes: 104 additions & 0 deletions
104
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
package me.chanjar.weixin.cp.api; | ||
|
||
import lombok.NonNull; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.cp.bean.WxCpBaseResp; | ||
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest; | ||
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* 企业微信家校沟通相关接口. | ||
* https://developer.work.weixin.qq.com/document/path/91638 | ||
* | ||
* @author <a href="https://github.com/0katekate0">Wang_Wong</a> | ||
* @date: 2022/6/18 9:10 | ||
*/ | ||
public interface WxCpSchoolUserService { | ||
|
||
/** | ||
* 创建学生 | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/create_student?access_token=ACCESS_TOKEN | ||
* | ||
* @param studentUserId | ||
* @param name | ||
* @param departments | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException; | ||
|
||
/** | ||
* 删除学生 | ||
* 请求方式:GET(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/delete_student?access_token=ACCESS_TOKEN&userid=USERID | ||
* | ||
* @param studentUserId | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp deleteStudent(@NonNull String studentUserId) throws WxErrorException; | ||
|
||
/** | ||
* 更新学生 | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/update_student?access_token=ACCESS_TOKEN | ||
* | ||
* @param studentUserId | ||
* @param newStudentUserId | ||
* @param name | ||
* @param departments | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp updateStudent(@NonNull String studentUserId, String newStudentUserId, String name, List<Integer> departments) throws WxErrorException; | ||
|
||
/** | ||
* 创建家长 | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/create_parent?access_token=ACCESS_TOKEN | ||
* | ||
* @param request | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp createParent(@NonNull WxCpCreateParentRequest request) throws WxErrorException; | ||
|
||
/** | ||
* 更新家长 | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/update_parent?access_token=ACCESS_TOKEN | ||
* | ||
* @param request | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException; | ||
|
||
/** | ||
* 删除家长 | ||
* 请求方式:GET(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/delete_parent?access_token=ACCESS_TOKEN&userid=USERID | ||
* | ||
* @param userId | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp deleteParent(@NonNull String userId) throws WxErrorException; | ||
|
||
/** | ||
* 设置家校通讯录自动同步模式 | ||
* 企业和第三方可通过此接口修改家校通讯录与班级标签之间的自动同步模式,注意,一旦设置禁止自动同步,将无法再次开启。 | ||
* <p> | ||
* 请求方式:POST(HTTPS) | ||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/set_arch_sync_mode?access_token=ACCESS_TOKEN | ||
* | ||
* @param archSyncMode 家校通讯录同步模式:1-禁止将标签同步至家校通讯录,2-禁止将家校通讯录同步至标签,3-禁止家校通讯录和标签相互同步 | ||
* @return | ||
* @throws WxErrorException | ||
*/ | ||
WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolUserServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package me.chanjar.weixin.cp.api.impl; | ||
|
||
import com.google.gson.JsonArray; | ||
import com.google.gson.JsonObject; | ||
import com.google.gson.JsonPrimitive; | ||
import lombok.NonNull; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import me.chanjar.weixin.common.error.WxErrorException; | ||
import me.chanjar.weixin.cp.api.WxCpSchoolUserService; | ||
import me.chanjar.weixin.cp.api.WxCpService; | ||
import me.chanjar.weixin.cp.bean.WxCpBaseResp; | ||
import me.chanjar.weixin.cp.bean.school.user.WxCpCreateParentRequest; | ||
import me.chanjar.weixin.cp.bean.school.user.WxCpUpdateParentRequest; | ||
import org.apache.commons.lang3.StringUtils; | ||
|
||
import java.util.List; | ||
|
||
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.School.*; | ||
|
||
/** | ||
* 企业微信家校沟通相关接口. | ||
* https://developer.work.weixin.qq.com/document/path/91638 | ||
* | ||
* @author <a href="https://github.com/0katekate0">Wang_Wong</a> | ||
* @date: 2022/6/18 9:10 | ||
*/ | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class WxCpSchoolUserServiceImpl implements WxCpSchoolUserService { | ||
|
||
private final WxCpService cpService; | ||
|
||
@Override | ||
public WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(CREATE_STUDENT); | ||
JsonObject jsonObject = new JsonObject(); | ||
jsonObject.addProperty("student_userid", studentUserId); | ||
jsonObject.addProperty("name", name); | ||
JsonArray jsonArray = new JsonArray(); | ||
for (Integer depart : departments) { | ||
jsonArray.add(new JsonPrimitive(depart)); | ||
} | ||
jsonObject.add("department", jsonArray); | ||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxCpBaseResp deleteStudent(@NonNull String studentUserId) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DELETE_STUDENT) + studentUserId; | ||
String responseContent = this.cpService.get(apiUrl, null); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxCpBaseResp updateStudent(@NonNull String studentUserId, String newStudentUserId, String name, List<Integer> departments) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_STUDENT); | ||
JsonObject jsonObject = new JsonObject(); | ||
jsonObject.addProperty("student_userid", studentUserId); | ||
if (StringUtils.isNotEmpty(newStudentUserId)) { | ||
jsonObject.addProperty("new_student_userid", newStudentUserId); | ||
} | ||
if (StringUtils.isNotEmpty(name)) { | ||
jsonObject.addProperty("name", name); | ||
} | ||
if (departments != null && departments.size() > 0) { | ||
JsonArray jsonArray = new JsonArray(); | ||
for (Integer depart : departments) { | ||
jsonArray.add(new JsonPrimitive(depart)); | ||
} | ||
jsonObject.add("department", jsonArray); | ||
} | ||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxCpBaseResp createParent(@NonNull WxCpCreateParentRequest request) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(CREATE_PARENT); | ||
String responseContent = this.cpService.post(apiUrl, request.toJson()); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_PARENT); | ||
String responseContent = this.cpService.post(apiUrl, request.toJson()); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxCpBaseResp deleteParent(@NonNull String userId) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DELETE_PARENT) + userId; | ||
String responseContent = this.cpService.get(apiUrl, null); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
@Override | ||
public WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException { | ||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_ARCH_SYNC_MODE); | ||
JsonObject jsonObject = new JsonObject(); | ||
jsonObject.addProperty("arch_sync_mode", archSyncMode); | ||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); | ||
return WxCpBaseResp.fromJson(responseContent); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateParentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.chanjar.weixin.cp.bean.school.user; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* 创建家长请求. | ||
* | ||
* @author Wang_Wong | ||
* @date 2022-06-20 | ||
*/ | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Accessors(chain = true) | ||
public class WxCpCreateParentRequest implements Serializable { | ||
private static final long serialVersionUID = -4960239393895754138L; | ||
|
||
@SerializedName("parent_userid") | ||
private String parentUserId; | ||
|
||
@SerializedName("mobile") | ||
private String mobile; | ||
|
||
@SerializedName("to_invite") | ||
private Boolean toInvite; | ||
|
||
@SerializedName("children") | ||
private List<Children> children; | ||
|
||
@Setter | ||
@Getter | ||
public static class Children implements Serializable { | ||
|
||
@SerializedName("student_userid") | ||
private String studentUserId; | ||
|
||
@SerializedName("relation") | ||
private String relation; | ||
|
||
public static Children fromJson(String json) { | ||
return WxCpGsonBuilder.create().fromJson(json, Children.class); | ||
} | ||
|
||
public String toJson() { | ||
return WxCpGsonBuilder.create().toJson(this); | ||
} | ||
|
||
} | ||
|
||
public static WxCpCreateParentRequest fromJson(String json) { | ||
return WxCpGsonBuilder.create().fromJson(json, WxCpCreateParentRequest.class); | ||
} | ||
|
||
public String toJson() { | ||
return WxCpGsonBuilder.create().toJson(this); | ||
} | ||
|
||
} |
65 changes: 65 additions & 0 deletions
65
...-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpUpdateParentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package me.chanjar.weixin.cp.bean.school.user; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import lombok.*; | ||
import lombok.experimental.Accessors; | ||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; | ||
|
||
import java.io.Serializable; | ||
import java.util.List; | ||
|
||
/** | ||
* 更新家长请求. | ||
* | ||
* @author Wang_Wong | ||
* @date 2022-06-20 | ||
*/ | ||
@Data | ||
@Builder | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Accessors(chain = true) | ||
public class WxCpUpdateParentRequest implements Serializable { | ||
private static final long serialVersionUID = -4960239393895754138L; | ||
|
||
@SerializedName("parent_userid") | ||
private String parentUserId; | ||
|
||
@SerializedName("mobile") | ||
private String mobile; | ||
|
||
@SerializedName("new_parent_userid") | ||
private String newParentUserId; | ||
|
||
@SerializedName("children") | ||
private List<Children> children; | ||
|
||
@Setter | ||
@Getter | ||
public static class Children implements Serializable { | ||
|
||
@SerializedName("student_userid") | ||
private String studentUserId; | ||
|
||
@SerializedName("relation") | ||
private String relation; | ||
|
||
public static Children fromJson(String json) { | ||
return WxCpGsonBuilder.create().fromJson(json, Children.class); | ||
} | ||
|
||
public String toJson() { | ||
return WxCpGsonBuilder.create().toJson(this); | ||
} | ||
|
||
} | ||
|
||
public static WxCpUpdateParentRequest fromJson(String json) { | ||
return WxCpGsonBuilder.create().fromJson(json, WxCpUpdateParentRequest.class); | ||
} | ||
|
||
public String toJson() { | ||
return WxCpGsonBuilder.create().toJson(this); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.