Skip to content

Commit

Permalink
🆕 #2746 【企业微信】 增加读取学生或家长所有接口支持
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 authored Jul 14, 2022
1 parent e0f3c76 commit bac1853
Show file tree
Hide file tree
Showing 8 changed files with 536 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,40 @@ public interface WxCpSchoolUserService {
*/
WxCpBatchResultList batchUpdateParent(@NonNull WxCpBatchUpdateParentRequest request) throws WxErrorException;

/**
* 读取学生或家长
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/get?access_token=ACCESS_TOKEN&userid=USERID
*
* @param userId
* @return
* @throws WxErrorException
*/
WxCpUserResult getUser(@NonNull String userId) throws WxErrorException;

/**
* 获取部门成员详情
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/list?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID&fetch_child=FETCH_CHILD
*
* @param departmentId 获取的部门id
* @param fetchChild 1/0:是否递归获取子部门下面的成员
* @return
* @throws WxErrorException
*/
WxCpUserListResult getUserList(@NonNull Integer departmentId, Integer fetchChild) throws WxErrorException;

/**
* 获取部门家长详情
* 请求方式:GET(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/list_parent?access_token=ACCESS_TOKEN&department_id=DEPARTMENT_ID
*
* @param departmentId 获取的部门id
* @return
* @throws WxErrorException
*/
WxCpListParentResult getUserListParent(@NonNull Integer departmentId) throws WxErrorException;

/**
* 更新家长
* 请求方式:POST(HTTPS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,27 @@ public WxCpBatchResultList batchUpdateParent(@NonNull WxCpBatchUpdateParentReque
return WxCpBatchResultList.fromJson(responseContent);
}

@Override
public WxCpUserResult getUser(@NonNull String userId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_USER) + userId;
String responseContent = this.cpService.get(apiUrl, null);
return WxCpUserResult.fromJson(responseContent);
}

@Override
public WxCpUserListResult getUserList(@NonNull Integer departmentId, Integer fetchChild) throws WxErrorException {
String apiUrl = String.format(this.cpService.getWxCpConfigStorage().getApiUrl(GET_USER_LIST), departmentId, fetchChild);
String responseContent = this.cpService.get(apiUrl, null);
return WxCpUserListResult.fromJson(responseContent);
}

@Override
public WxCpListParentResult getUserListParent(@NonNull Integer departmentId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(GET_USER_LIST_PARENT) + departmentId;
String responseContent = this.cpService.get(apiUrl, null);
return WxCpListParentResult.fromJson(responseContent);
}

@Override
public WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_PARENT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
* <pre>
* 使用user_ticket获取成员详情接口返回类.
* Created by BinaryWang on 2018/4/22.
* 官方文档:https://developer.work.weixin.qq.com/document/path/91122
* </pre>
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
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.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 获取部门家长详情返回结果.
*
* @author Wang_Wong
* @date 2022-07-13
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpListParentResult extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;

@SerializedName("parents")
private List<Parent> parents;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Parent implements Serializable {

@SerializedName("parent_userid")
private String parentUserId;

@SerializedName("mobile")
private String mobile;

@SerializedName("external_userid")
private String externalUserId;

@SerializedName("is_subscribe")
private Integer isSubscribe;

@SerializedName("children")
private List<Children> children;

public static Parent fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Parent.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Children implements Serializable {

@SerializedName("student_userid")
private String studentUserId;

@SerializedName("relation")
private String relation;

@SerializedName("name")
private String name;

public static Children fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Children.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

public static WxCpListParentResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpListParentResult.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
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.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;

import java.io.Serializable;
import java.util.List;

/**
* 获取部门成员详情返回结果.
*
* @author Wang_Wong
* @date 2022-07-13
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpUserListResult extends WxCpBaseResp implements Serializable {
private static final long serialVersionUID = -4960239393895754138L;

@SerializedName("students")
private List<Student> students;

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Parent implements Serializable {

@SerializedName("parent_userid")
private String parentUserId;

@SerializedName("relation")
private String relation;

@SerializedName("mobile")
private String mobile;

@SerializedName("external_userid")
private String externalUserId;

@SerializedName("is_subscribe")
private Integer isSubscribe;

public static Parent fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Parent.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Setter
@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public static class Student implements Serializable {

@SerializedName("student_userid")
private String studentUserId;

@SerializedName("name")
private String name;

@SerializedName("department")
private List<Integer> department;

@SerializedName("parents")
private List<Parent> parents;

public static Student fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, Student.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

public static WxCpUserListResult fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpUserListResult.class);
}

public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Loading

0 comments on commit bac1853

Please sign in to comment.