diff --git a/README.md b/README.md index bf3ec86e2d..b55ee50ef5 100644 --- a/README.md +++ b/README.md @@ -182,6 +182,7 @@ 1. [007gzs](https://github.com/007gzs) 1. [Silloy](https://github.com/silloy) 1. [mgcnrx11](https://github.com/mgcnrx11) +1. [0katekate0 (Wang_Wong)](https://github.com/0katekate0) 1. [yuanqixun](https://github.com/yuanqixun) 1. [kakotor](https://github.com/kakotor) 1. [aimilin6688 (Jonk)](https://github.com/aimilin6688) diff --git a/pom.xml b/pom.xml index 42b3f63813..3f8f739780 100644 --- a/pom.xml +++ b/pom.xml @@ -97,6 +97,11 @@ xiaohe@53jy.net https://github.com/xiaohe-53 + + Wang_Wong + wangkaikate@163.com + https://github.com/0katekate0 + diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java index 7a97914a1f..4256352282 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java @@ -3,8 +3,7 @@ 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 me.chanjar.weixin.cp.bean.school.user.*; import java.util.List; @@ -101,4 +100,62 @@ public interface WxCpSchoolUserService { */ WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErrorException; + /** + * 创建部门 + *

+ * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/create?access_token=ACCESS_TOKEN + * + * @param request 请求参数对象 + * @return + * @throws WxErrorException + */ + WxCpCreateDepartment createDepartment(@NonNull WxCpCreateDepartmentRequest request) throws WxErrorException; + + /** + * 更新部门 + *

+ * 请求方式:POST(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/update?access_token=ACCESS_TOKEN + * + * @param request + * @return + * @throws WxErrorException + */ + WxCpBaseResp updateDepartment(@NonNull WxCpUpdateDepartmentRequest request) throws WxErrorException; + + /** + * 删除部门 + * 请求方式:GET(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/delete?access_token=ACCESS_TOKEN&id=ID + * + * @param id + * @return + * @throws WxErrorException + */ + WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException; + + /** + * 获取部门列表 + * 请求方式:GET(HTTPS) + * 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/department/list?access_token=ACCESS_TOKEN&id=ID + * + * @param id + * @return + * @throws WxErrorException + */ + WxCpDepartmentList listDepartment(Integer id) throws WxErrorException; + + /** + * 修改自动升年级的配置 + * 请求方式: POST(HTTPS) + * 请求地址: https://qyapi.weixin.qq.com/cgi-bin/school/set_upgrade_info?access_token=ACCESS_TOKEN + * + * @param upgradeTime + * @param upgradeSwitch + * @return + * @throws WxErrorException + */ + WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException; + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolUserServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolUserServiceImpl.java index 404797f2ce..c8204c5f5d 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolUserServiceImpl.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolUserServiceImpl.java @@ -10,8 +10,7 @@ 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 me.chanjar.weixin.cp.bean.school.user.*; import org.apache.commons.lang3.StringUtils; import java.util.List; @@ -105,4 +104,46 @@ public WxCpBaseResp setArchSyncMode(@NonNull Integer archSyncMode) throws WxErro return WxCpBaseResp.fromJson(responseContent); } + @Override + public WxCpCreateDepartment createDepartment(@NonNull WxCpCreateDepartmentRequest request) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_CREATE); + String responseContent = this.cpService.post(apiUrl, request.toJson()); + return WxCpCreateDepartment.fromJson(responseContent); + } + + @Override + public WxCpBaseResp updateDepartment(@NonNull WxCpUpdateDepartmentRequest request) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_UPDATE); + String responseContent = this.cpService.post(apiUrl, request.toJson()); + return WxCpBaseResp.fromJson(responseContent); + } + + @Override + public WxCpBaseResp deleteDepartment(Integer id) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_DELETE) + id; + String responseContent = this.cpService.get(apiUrl, null); + return WxCpBaseResp.fromJson(responseContent); + } + + @Override + public WxCpDepartmentList listDepartment(Integer id) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DEPARTMENT_LIST) + id; + String responseContent = this.cpService.get(apiUrl, null); + return WxCpDepartmentList.fromJson(responseContent); + } + + @Override + public WxCpSetUpgradeInfo setUpgradeInfo(Long upgradeTime, Integer upgradeSwitch) throws WxErrorException { + String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(SET_UPGRADE_INFO); + JsonObject jsonObject = new JsonObject(); + if (upgradeTime != null) { + jsonObject.addProperty("upgrade_time", upgradeTime); + } + if (upgradeSwitch != null) { + jsonObject.addProperty("upgrade_switch", upgradeSwitch); + } + String responseContent = this.cpService.post(apiUrl, jsonObject.toString()); + return WxCpSetUpgradeInfo.fromJson(responseContent); + } + } diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartment.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartment.java new file mode 100644 index 0000000000..75d34b2e8c --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartment.java @@ -0,0 +1,30 @@ +package me.chanjar.weixin.cp.bean.school.user; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 创建部门返回结果. + * + * @author Wang_Wong + */ +@Data +public class WxCpCreateDepartment extends WxCpBaseResp implements Serializable { + private static final long serialVersionUID = -5028321625140879571L; + + @SerializedName("id") + private Integer id; + + public static WxCpCreateDepartment fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartment.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartmentRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartmentRequest.java new file mode 100644 index 0000000000..a851aacc94 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpCreateDepartmentRequest.java @@ -0,0 +1,80 @@ +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-22 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +public class WxCpCreateDepartmentRequest implements Serializable { + private static final long serialVersionUID = -4960239394895754138L; + + @SerializedName("parentid") + private Integer parentId; + + @SerializedName("name") + private String name; + + @SerializedName("id") + private Integer id; + + @SerializedName("type") + private Integer type; + + @SerializedName("register_year") + private Integer registerYear; + + @SerializedName("standard_grade") + private Integer standardGrade; + + @SerializedName("order") + private Integer order; + + @SerializedName("department_admins") + private List departmentAdmins; + + @Setter + @Getter + public static class DepartmentAdmin implements Serializable { + + @SerializedName("userid") + private String userId; + + @SerializedName("type") + private Integer type; + + @SerializedName("subject") + private String subject; + + public static DepartmentAdmin fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + public static WxCpCreateDepartmentRequest fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpCreateDepartmentRequest.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpDepartmentList.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpDepartmentList.java new file mode 100644 index 0000000000..5e1c031847 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpDepartmentList.java @@ -0,0 +1,102 @@ +package me.chanjar.weixin.cp.bean.school.user; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import lombok.Getter; +import lombok.Setter; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; +import java.util.List; + +/** + * 获取部门列表返回结果. + * + * @author Wang_Wong + */ +@Data +public class WxCpDepartmentList extends WxCpBaseResp implements Serializable { + private static final long serialVersionUID = -5028321625140879571L; + + @SerializedName("departments") + private List departments; + + @Setter + @Getter + public static class Department implements Serializable{ + @SerializedName("parentid") + private Integer parentId; + + @SerializedName("name") + private String name; + + @SerializedName("id") + private Integer id; + + @SerializedName("type") + private Integer type; + + @SerializedName("register_year") + private Integer registerYear; + + @SerializedName("standard_grade") + private Integer standardGrade; + + @SerializedName("order") + private Integer order; + + @SerializedName("is_graduated") + private Integer isGraduated; + + @SerializedName("open_group_chat") + private Integer openGroupChat; + + @SerializedName("group_chat_id") + private String groupChatId; + + @SerializedName("department_admins") + private List departmentAdmins; + + public static Department fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, Department.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + @Setter + @Getter + public static class DepartmentAdmin implements Serializable { + + @SerializedName("userid") + private String userId; + + @SerializedName("type") + private Integer type; + + @SerializedName("subject") + private String subject; + + public static DepartmentAdmin fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + public static WxCpDepartmentList fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpDepartmentList.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSetUpgradeInfo.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSetUpgradeInfo.java new file mode 100644 index 0000000000..7a1b3ee276 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpSetUpgradeInfo.java @@ -0,0 +1,30 @@ +package me.chanjar.weixin.cp.bean.school.user; + +import com.google.gson.annotations.SerializedName; +import lombok.Data; +import me.chanjar.weixin.cp.bean.WxCpBaseResp; +import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder; + +import java.io.Serializable; + +/** + * 修改自动升年级的配置 返回结果. + * + * @author Wang_Wong + */ +@Data +public class WxCpSetUpgradeInfo extends WxCpBaseResp implements Serializable { + private static final long serialVersionUID = -5028321625140879571L; + + @SerializedName("next_upgrade_time") + private Long nextUpgradeTime; + + public static WxCpSetUpgradeInfo fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpSetUpgradeInfo.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpUpdateDepartmentRequest.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpUpdateDepartmentRequest.java new file mode 100644 index 0000000000..e1dff520e7 --- /dev/null +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/school/user/WxCpUpdateDepartmentRequest.java @@ -0,0 +1,86 @@ +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-22 + */ +@Data +@Builder +@NoArgsConstructor +@AllArgsConstructor +@Accessors(chain = true) +public class WxCpUpdateDepartmentRequest implements Serializable { + private static final long serialVersionUID = -4960239394895754138L; + + @SerializedName("parentid") + private Integer parentId; + + @SerializedName("name") + private String name; + + @SerializedName("id") + private Integer id; + + @SerializedName("new_id") + private Integer newId; + + @SerializedName("type") + private Integer type; + + @SerializedName("register_year") + private Integer registerYear; + + @SerializedName("standard_grade") + private Integer standardGrade; + + @SerializedName("order") + private Integer order; + + @SerializedName("department_admins") + private List departmentAdmins; + + @Setter + @Getter + public static class DepartmentAdmin implements Serializable { + + @SerializedName("userid") + private String userId; + + @SerializedName("op") + private Integer op; + + @SerializedName("type") + private Integer type; + + @SerializedName("subject") + private String subject; + + public static DepartmentAdmin fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, DepartmentAdmin.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + + } + + public static WxCpUpdateDepartmentRequest fromJson(String json) { + return WxCpGsonBuilder.create().fromJson(json, WxCpUpdateDepartmentRequest.class); + } + + public String toJson() { + return WxCpGsonBuilder.create().toJson(this); + } + +} diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java index 476f827adf..8165f6a307 100644 --- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java +++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java @@ -190,6 +190,12 @@ interface School { String UPDATE_PARENT = "/cgi-bin/school/user/update_parent"; String DELETE_PARENT = "/cgi-bin/school/user/delete_parent?userid="; String SET_ARCH_SYNC_MODE = "/cgi-bin/school/set_arch_sync_mode"; + String SET_UPGRADE_INFO = "/cgi-bin/school/set_upgrade_info"; + + String DEPARTMENT_CREATE = "/cgi-bin/school/department/create"; + String DEPARTMENT_UPDATE = "/cgi-bin/school/department/update"; + String DEPARTMENT_DELETE = "/cgi-bin/school/department/delete?id="; + String DEPARTMENT_LIST = "/cgi-bin/school/department/list?id="; String GET_PAYMENT_RESULT = "/cgi-bin/school/get_payment_result"; String GET_TRADE = "/cgi-bin/school/get_trade"; diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolUserTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolUserTest.java index a201da2836..fbf2e97b40 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolUserTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/WxCpSchoolUserTest.java @@ -6,8 +6,7 @@ import me.chanjar.weixin.common.error.WxErrorException; import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl; 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 me.chanjar.weixin.cp.bean.school.user.*; import me.chanjar.weixin.cp.config.WxCpConfigStorage; import me.chanjar.weixin.cp.demo.WxCpDemoInMemoryConfigStorage; import org.testng.annotations.Test; @@ -44,6 +43,72 @@ public void test() throws WxErrorException { list.add(3); log.info("list:{}", list.toString()); + final String userId = "WangKai"; + + + /** + * 修改自动升年级的配置 + * https://developer.work.weixin.qq.com/document/path/92949 + */ + WxCpSetUpgradeInfo wxCpSetUpgradeInfo = cpService.getSchoolUserService().setUpgradeInfo(1594090969L, 2); + log.info("wxCpSetUpgradeInfo:{}", wxCpSetUpgradeInfo.toJson()); + + /** + * 获取部门列表 + * https://developer.work.weixin.qq.com/document/path/92343 + */ + String str5 = "{\"errcode\":0,\"errmsg\":\"ok\",\"departments\":[{\"name\":\"一年级\",\"parentid\":1,\"id\":2,\"type\":2,\"register_year\":2018,\"standard_grade\":1,\"order\":1,\"department_admins\":[{\"userid\":\"zhangsan\",\"type\":1},{\"userid\":\"lisi\",\"type\":2}],\"is_graduated\":0},{\"name\":\"一年级一班\",\"parentid\":1,\"id\":3,\"type\":1,\"department_admins\":[{\"userid\":\"zhangsan\",\"type\":3,\"subject\":\"语文\"},{\"userid\":\"lisi\",\"type\":4,\"subject\":\"数学\"}],\"open_group_chat\":1,\"group_chat_id\":\"group_chat_id\"}]}"; + WxCpDepartmentList wxCpDepartmentList = WxCpDepartmentList.fromJson(str5); + log.info("wxCpDepartmentList:{}", wxCpDepartmentList.toJson()); + + WxCpDepartmentList departmentList = cpService.getSchoolUserService().listDepartment(7); + log.info("departmentList:{}", departmentList.toJson()); + + /** + * 删除部门 + * https://developer.work.weixin.qq.com/document/path/92342 + */ + WxCpBaseResp deleteDepartment = cpService.getSchoolUserService().deleteDepartment(7); + log.info("deleteDepartment:{}", deleteDepartment.toJson()); + + /** + * 更新部门 + * https://developer.work.weixin.qq.com/document/path/92341 + */ + String str4 = "{\"name\":\"一年级\",\"parentid\":5,\"id\":2,\"register_year\":2018,\"standard_grade\":1,\"order\":1,\"new_id\":100,\"department_admins\":[{\"op\":0,\"userid\":\"zhangsan\",\"type\":3,\"subject\":\"语文\"},{\"op\":1,\"userid\":\"lisi\",\"type\":4,\"subject\":\"数学\"}]}"; + WxCpUpdateDepartmentRequest wxCpUpdateDepartmentRequest = WxCpUpdateDepartmentRequest.fromJson(str4); + log.info("wxCpUpdateParentRequest:{}", wxCpUpdateDepartmentRequest.toJson()); + + WxCpBaseResp updateDepartment = cpService.getSchoolUserService().updateDepartment(wxCpUpdateDepartmentRequest); + log.info("updateDepartment:{}", updateDepartment.toJson()); + + /** + * 创建部门 + * https://developer.work.weixin.qq.com/document/path/92340 + */ + String str3 = "{\"name\":\"一年级\",\"parentid\":5,\"id\":2,\"type\":1,\"register_year\":2018,\"standard_grade\":1,\"order\":1,\"department_admins\":[{\"userid\":\"zhangsan\",\"type\":4,\"subject\":\"语文\"},{\"userid\":\"lisi\",\"type\":3,\"subject\":\"数学\"}]}"; + WxCpCreateDepartmentRequest wxCpCreateDepartmentRequest = WxCpCreateDepartmentRequest.fromJson(str3); + log.info("wxCpCreateDepartmentRequest:{}", wxCpCreateDepartmentRequest.toJson()); + + WxCpCreateDepartmentRequest createDepartmentRequest = new WxCpCreateDepartmentRequest(); + createDepartmentRequest.setParentId(5); + createDepartmentRequest.setName("一年级"); + createDepartmentRequest.setId(2); + createDepartmentRequest.setType(1); + createDepartmentRequest.setRegisterYear(2018); + createDepartmentRequest.setStandardGrade(1); + createDepartmentRequest.setOrder(1); + + var departmentAdmin = new WxCpCreateDepartmentRequest.DepartmentAdmin(); + departmentAdmin.setUserId(userId); + departmentAdmin.setType(4); + departmentAdmin.setSubject("英语"); + List createDepartList = Lists.newArrayList(); + createDepartList.add(departmentAdmin); + + createDepartmentRequest.setDepartmentAdmins(createDepartList); + WxCpCreateDepartment createDepartment = cpService.getSchoolUserService().createDepartment(createDepartmentRequest); + log.info("createDepartment:{}", createDepartment.toJson()); /** * 更新家长