Skip to content

Commit

Permalink
🆕 #2725【企业微信】增加家校沟通-发送「学校通知」的接口
Browse files Browse the repository at this point in the history
  • Loading branch information
0katekate0 committed Jul 6, 2022
1 parent 918daa2 commit f30ac6b
Show file tree
Hide file tree
Showing 17 changed files with 1,188 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* 微信开发所使用到的常量类.
*
* @author Daniel Qian & binarywang
* @author Daniel Qian & binarywang & Wang_Wong
*/
public class WxConsts {
/**
Expand Down Expand Up @@ -133,6 +133,54 @@ public static class KefuMsgType {
public static final String MP_NEWS_ARTICLE = "mpnewsarticle";
}

/**
* 发送「学校通知」类型
* https://developer.work.weixin.qq.com/document/path/92321
*/
public static class SchoolContactMsgType {

/**
* 文本消息.
*/
public static final String TEXT = "text";

/**
* 图片消息.
*/
public static final String IMAGE = "image";

/**
* 语音消息.
*/
public static final String VOICE = "voice";

/**
* 视频消息.
*/
public static final String VIDEO = "video";

/**
* 文件消息
*/
public static final String FILE = "file";

/**
* 图文消息
*/
public static final String NEWS = "news";

/**
* 图文消息(mpnews)
*/
public static final String MPNEWS = "mpnews";

/**
* 小程序消息
*/
public static final String MINIPROGRAM = "miniprogram";

}

/**
* 企业微信模板卡片消息的卡片类型
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,20 @@ public interface WxCpMessageService {
* @throws WxErrorException the wx error exception
*/
WxCpLinkedCorpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException;

/**
* 发送「学校通知」
* https://developer.work.weixin.qq.com/document/path/92321
* <p>
* 学校可以通过此接口来给家长发送不同类型的学校通知,来满足多种场景下的学校通知需求。目前支持的消息类型为文本、图片、语音、视频、文件、图文。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/externalcontact/message/send?access_token=ACCESS_TOKEN
*
* @param message 要发送的消息对象
* @return
* @throws WxErrorException
*/
WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException;

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,39 @@ public interface WxCpSchoolUserService {
*/
WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException;

/**
* 批量创建学生
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_create_student?access_token=ACCESS_TOKEN
*
* @param request
* @return
* @throws WxErrorException
*/
WxCpBatchResultList batchCreateStudent(@NonNull WxCpBatchCreateStudentRequest request) throws WxErrorException;

/**
* 批量删除学生
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_delete_student?access_token=ACCESS_TOKEN
*
* @param request
* @return
* @throws WxErrorException
*/
WxCpBatchResultList batchDeleteStudent(@NonNull WxCpBatchDeleteStudentRequest request) throws WxErrorException;

/**
* 批量更新学生
* 请求方式:POST(HTTPS)
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_update_student?access_token=ACCESS_TOKEN
*
* @param request
* @return
* @throws WxErrorException
*/
WxCpBatchResultList batchUpdateStudent(@NonNull WxCpBatchUpdateStudentRequest request) throws WxErrorException;

/**
* 删除学生
* 请求方式:GET(HTTPS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,15 @@ public WxCpLinkedCorpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessa
return WxCpLinkedCorpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
.getApiUrl(Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
}

@Override
public WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException {
if (null == message.getAgentId()) {
message.setAgentId(this.cpService.getWxCpConfigStorage().getAgentId());
}

return WxCpSchoolContactMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
.getApiUrl(Message.EXTERNAL_CONTACT_MESSAGE_SEND), message.toJson()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,27 @@ public WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String
return WxCpBaseResp.fromJson(responseContent);
}

@Override
public WxCpBatchResultList batchCreateStudent(@NonNull WxCpBatchCreateStudentRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_CREATE_STUDENT);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBatchResultList.fromJson(responseContent);
}

@Override
public WxCpBatchResultList batchDeleteStudent(@NonNull WxCpBatchDeleteStudentRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_DELETE_STUDENT);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBatchResultList.fromJson(responseContent);
}

@Override
public WxCpBatchResultList batchUpdateStudent(@NonNull WxCpBatchUpdateStudentRequest request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_UPDATE_STUDENT);
String responseContent = this.cpService.post(apiUrl, request.toJson());
return WxCpBatchResultList.fromJson(responseContent);
}

@Override
public WxCpBaseResp deleteStudent(@NonNull String studentUserId) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DELETE_STUDENT) + studentUserId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,22 @@
@NoArgsConstructor
public class NewArticle implements Serializable {
private static final long serialVersionUID = 4087852055781140659L;

/**
* 标题,不超过128个字节,超过会自动截断
*/
private String title;

/**
* 描述,不超过512个字节,超过会自动截断
*/
private String description;

/**
* 点击后跳转的链接。
*/
private String url;

/**
* 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图1068*455,小图150*150。
*/
Expand All @@ -42,9 +46,14 @@ public class NewArticle implements Serializable {
*/
private String btnText;

/**小程序appid,必须是与当前应用关联的小程序,appid和pagepath必须同时填写,填写后会忽略url字段**/
/**
* 小程序appid,必须是与当前应用关联的小程序,appid和pagepath必须同时填写,填写后会忽略url字段
*/
private String appid;

/**点击消息卡片后的小程序页面,仅限本小程序内的页面。appid和pagepath必须同时填写,填写后会忽略url字段**/
/**
* 点击消息卡片后的小程序页面,仅限本小程序内的页面。appid和pagepath必须同时填写,填写后会忽略url字段
*/
private String pagepath;

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

/**
* 互联企业消息.
* https://developer.work.weixin.qq.com/document/path/90250
*
* @author <a href="https://github.com/binarywang">Binary Wang</a>
* @date 2020-08-30
Expand Down
Loading

0 comments on commit f30ac6b

Please sign in to comment.