🆕 #2742【企业微信】 家校沟通-增加批量更新家长接口支持
This commit is contained in:
@@ -9,6 +9,8 @@ import me.chanjar.weixin.cp.bean.WxCpUserDetail;
|
||||
* OAuth2相关管理接口.
|
||||
* Created by BinaryWang on 2017/6/24.
|
||||
* </pre>
|
||||
* <p>
|
||||
* 文档1:https://developer.work.weixin.qq.com/document/path/91856
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@@ -84,6 +86,19 @@ public interface WxCpOAuth2Service {
|
||||
*/
|
||||
WxCpOauth2UserInfo getUserInfo(Integer agentId, String code) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取家校访问用户身份
|
||||
* 该接口用于根据code获取家长或者学生信息
|
||||
* <p>
|
||||
* 请求方式:GET(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpOauth2UserInfo getSchoolUserInfo(String code) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* <pre>
|
||||
* 使用user_ticket获取成员详情.
|
||||
|
||||
@@ -3,6 +3,7 @@ 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.WxCpOauth2UserInfo;
|
||||
import me.chanjar.weixin.cp.bean.school.user.*;
|
||||
|
||||
import java.util.List;
|
||||
@@ -16,6 +17,32 @@ import java.util.List;
|
||||
*/
|
||||
public interface WxCpSchoolUserService {
|
||||
|
||||
/**
|
||||
* 获取访问用户身份
|
||||
* 该接口用于根据code获取成员信息
|
||||
* <p>
|
||||
* 请求方式:GET(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpOauth2UserInfo getUserInfo(@NonNull String code) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 获取家校访问用户身份
|
||||
* 该接口用于根据code获取家长或者学生信息
|
||||
* <p>
|
||||
* 请求方式:GET(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
|
||||
*
|
||||
* @param code
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpOauth2UserInfo getSchoolUserInfo(@NonNull String code) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 创建学生
|
||||
* 请求方式:POST(HTTPS)
|
||||
@@ -98,6 +125,39 @@ public interface WxCpSchoolUserService {
|
||||
*/
|
||||
WxCpBaseResp createParent(@NonNull WxCpCreateParentRequest request) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 批量创建家长
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_create_parent?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpBatchResultList batchCreateParent(@NonNull WxCpBatchCreateParentRequest request) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 批量删除家长
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_delete_parent?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param userIdList
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpBatchResultList batchDeleteParent(@NonNull String... userIdList) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 批量更新家长
|
||||
* 请求方式:POST(HTTPS)
|
||||
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_update_parent?access_token=ACCESS_TOKEN
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
* @throws WxErrorException
|
||||
*/
|
||||
WxCpBatchResultList batchUpdateParent(@NonNull WxCpBatchUpdateParentRequest request) throws WxErrorException;
|
||||
|
||||
/**
|
||||
* 更新家长
|
||||
* 请求方式:POST(HTTPS)
|
||||
|
||||
@@ -77,6 +77,20 @@ public class WxCpOAuth2ServiceImpl implements WxCpOAuth2Service {
|
||||
.userTicket(GsonHelper.getString(jo, "user_ticket"))
|
||||
.expiresIn(GsonHelper.getString(jo, "expires_in"))
|
||||
.externalUserId(GsonHelper.getString(jo, "external_userid"))
|
||||
.parentUserId(GsonHelper.getString(jo, "parent_userid"))
|
||||
.studentUserId(GsonHelper.getString(jo, "student_userid"))
|
||||
.build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpOauth2UserInfo getSchoolUserInfo(String code) throws WxErrorException {
|
||||
String responseText = this.mainService.get(String.format(this.mainService.getWxCpConfigStorage().getApiUrl(GET_SCHOOL_USER_INFO), code), null);
|
||||
JsonObject jo = GsonParser.parse(responseText);
|
||||
|
||||
return WxCpOauth2UserInfo.builder()
|
||||
.deviceId(GsonHelper.getString(jo, "DeviceId"))
|
||||
.parentUserId(GsonHelper.getString(jo, "parent_userid"))
|
||||
.studentUserId(GsonHelper.getString(jo, "student_userid"))
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ import me.chanjar.weixin.common.util.json.GsonParser;
|
||||
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.WxCpOauth2UserInfo;
|
||||
import me.chanjar.weixin.cp.bean.school.user.*;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
@@ -32,6 +33,16 @@ public class WxCpSchoolUserServiceImpl implements WxCpSchoolUserService {
|
||||
|
||||
private final WxCpService cpService;
|
||||
|
||||
@Override
|
||||
public WxCpOauth2UserInfo getUserInfo(@NonNull String code) throws WxErrorException {
|
||||
return cpService.getOauth2Service().getUserInfo(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpOauth2UserInfo getSchoolUserInfo(@NonNull String code) throws WxErrorException {
|
||||
return cpService.getOauth2Service().getSchoolUserInfo(code);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(CREATE_STUDENT);
|
||||
@@ -104,6 +115,33 @@ public class WxCpSchoolUserServiceImpl implements WxCpSchoolUserService {
|
||||
return WxCpBaseResp.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpBatchResultList batchCreateParent(@NonNull WxCpBatchCreateParentRequest request) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_CREATE_PARENT);
|
||||
String responseContent = this.cpService.post(apiUrl, request.toJson());
|
||||
return WxCpBatchResultList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpBatchResultList batchDeleteParent(@NonNull String... userIdList) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_DELETE_PARENT);
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
JsonArray jsonArray = new JsonArray();
|
||||
for (String userId : userIdList) {
|
||||
jsonArray.add(new JsonPrimitive(userId));
|
||||
}
|
||||
jsonObject.add("useridlist", jsonArray);
|
||||
String responseContent = this.cpService.post(apiUrl, jsonObject.toString());
|
||||
return WxCpBatchResultList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpBatchResultList batchUpdateParent(@NonNull WxCpBatchUpdateParentRequest request) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_UPDATE_PARENT);
|
||||
String responseContent = this.cpService.post(apiUrl, request.toJson());
|
||||
return WxCpBatchResultList.fromJson(responseContent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public WxCpBaseResp updateParent(@NonNull WxCpUpdateParentRequest request) throws WxErrorException {
|
||||
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(UPDATE_PARENT);
|
||||
|
||||
@@ -14,6 +14,8 @@ import java.io.Serializable;
|
||||
* Created by BinaryWang on 2019/5/26.
|
||||
* </pre>
|
||||
*
|
||||
* 文档1:https://developer.work.weixin.qq.com/document/path/91707
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
@@ -30,4 +32,7 @@ public class WxCpOauth2UserInfo implements Serializable {
|
||||
private String userTicket;
|
||||
private String expiresIn;
|
||||
private String externalUserId;
|
||||
private String parentUserId;
|
||||
private String studentUserId;
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,88 @@
|
||||
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-07-11
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class WxCpBatchCreateParentRequest 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("to_invite")
|
||||
private Boolean toInvite;
|
||||
|
||||
@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;
|
||||
|
||||
public static Children fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, Children.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WxCpBatchCreateParentRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpBatchCreateParentRequest.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,88 @@
|
||||
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-07-11
|
||||
*/
|
||||
@Data
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Accessors(chain = true)
|
||||
public class WxCpBatchUpdateParentRequest 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("new_parent_userid")
|
||||
private String newParentUserId;
|
||||
|
||||
@SerializedName("mobile")
|
||||
private String mobile;
|
||||
|
||||
@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;
|
||||
|
||||
public static Children fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, Children.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static WxCpBatchUpdateParentRequest fromJson(String json) {
|
||||
return WxCpGsonBuilder.create().fromJson(json, WxCpBatchUpdateParentRequest.class);
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -36,6 +36,9 @@ public class WxCpCreateParentRequest implements Serializable {
|
||||
|
||||
@Setter
|
||||
@Getter
|
||||
@Builder
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
public static class Children implements Serializable {
|
||||
|
||||
@SerializedName("student_userid")
|
||||
|
||||
@@ -67,6 +67,7 @@ public interface WxCpApiPathConsts {
|
||||
|
||||
interface OAuth2 {
|
||||
String GET_USER_INFO = "/cgi-bin/user/getuserinfo?code=%s&agentid=%d";
|
||||
String GET_SCHOOL_USER_INFO = "/cgi-bin/school/getuserinfo?code=%s";
|
||||
String GET_USER_DETAIL = "/cgi-bin/user/getuserdetail";
|
||||
String URL_OAUTH2_AUTHORIZE = "https://open.weixin.qq.com/connect/oauth2/authorize";
|
||||
}
|
||||
@@ -195,6 +196,9 @@ public interface WxCpApiPathConsts {
|
||||
String BATCH_CREATE_STUDENT = "/cgi-bin/school/user/batch_create_student";
|
||||
String BATCH_DELETE_STUDENT = "/cgi-bin/school/user/batch_delete_student";
|
||||
String BATCH_UPDATE_STUDENT = "/cgi-bin/school/user/batch_update_student";
|
||||
String BATCH_CREATE_PARENT = "/cgi-bin/school/user/batch_create_parent";
|
||||
String BATCH_DELETE_PARENT = "/cgi-bin/school/user/batch_delete_parent";
|
||||
String BATCH_UPDATE_PARENT = "/cgi-bin/school/user/batch_update_parent";
|
||||
|
||||
String CREATE_STUDENT = "/cgi-bin/school/user/create_student";
|
||||
String DELETE_STUDENT = "/cgi-bin/school/user/delete_student?userid=";
|
||||
|
||||
Reference in New Issue
Block a user