Skip to content

Commit f30ac6b

Browse files
authored
🆕 #2725【企业微信】增加家校沟通-发送「学校通知」的接口
1 parent 918daa2 commit f30ac6b

17 files changed

+1188
-4
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
/**
1111
* 微信开发所使用到的常量类.
1212
*
13-
* @author Daniel Qian & binarywang
13+
* @author Daniel Qian & binarywang & Wang_Wong
1414
*/
1515
public class WxConsts {
1616
/**
@@ -133,6 +133,54 @@ public static class KefuMsgType {
133133
public static final String MP_NEWS_ARTICLE = "mpnewsarticle";
134134
}
135135

136+
/**
137+
* 发送「学校通知」类型
138+
* https://developer.work.weixin.qq.com/document/path/92321
139+
*/
140+
public static class SchoolContactMsgType {
141+
142+
/**
143+
* 文本消息.
144+
*/
145+
public static final String TEXT = "text";
146+
147+
/**
148+
* 图片消息.
149+
*/
150+
public static final String IMAGE = "image";
151+
152+
/**
153+
* 语音消息.
154+
*/
155+
public static final String VOICE = "voice";
156+
157+
/**
158+
* 视频消息.
159+
*/
160+
public static final String VIDEO = "video";
161+
162+
/**
163+
* 文件消息
164+
*/
165+
public static final String FILE = "file";
166+
167+
/**
168+
* 图文消息
169+
*/
170+
public static final String NEWS = "news";
171+
172+
/**
173+
* 图文消息(mpnews)
174+
*/
175+
public static final String MPNEWS = "mpnews";
176+
177+
/**
178+
* 小程序消息
179+
*/
180+
public static final String MINIPROGRAM = "miniprogram";
181+
182+
}
183+
136184
/**
137185
* 企业微信模板卡片消息的卡片类型
138186
*/

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpMessageService.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,20 @@ public interface WxCpMessageService {
5050
* @throws WxErrorException the wx error exception
5151
*/
5252
WxCpLinkedCorpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessage message) throws WxErrorException;
53+
54+
/**
55+
* 发送「学校通知」
56+
* https://developer.work.weixin.qq.com/document/path/92321
57+
* <p>
58+
* 学校可以通过此接口来给家长发送不同类型的学校通知,来满足多种场景下的学校通知需求。目前支持的消息类型为文本、图片、语音、视频、文件、图文。
59+
* <p>
60+
* 请求方式:POST(HTTPS)
61+
* 请求地址: https://qyapi.weixin.qq.com/cgi-bin/externalcontact/message/send?access_token=ACCESS_TOKEN
62+
*
63+
* @param message 要发送的消息对象
64+
* @return
65+
* @throws WxErrorException
66+
*/
67+
WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException;
68+
5369
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpSchoolUserService.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,39 @@ public interface WxCpSchoolUserService {
2929
*/
3030
WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String name, @NonNull List<Integer> departments) throws WxErrorException;
3131

32+
/**
33+
* 批量创建学生
34+
* 请求方式:POST(HTTPS)
35+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_create_student?access_token=ACCESS_TOKEN
36+
*
37+
* @param request
38+
* @return
39+
* @throws WxErrorException
40+
*/
41+
WxCpBatchResultList batchCreateStudent(@NonNull WxCpBatchCreateStudentRequest request) throws WxErrorException;
42+
43+
/**
44+
* 批量删除学生
45+
* 请求方式:POST(HTTPS)
46+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_delete_student?access_token=ACCESS_TOKEN
47+
*
48+
* @param request
49+
* @return
50+
* @throws WxErrorException
51+
*/
52+
WxCpBatchResultList batchDeleteStudent(@NonNull WxCpBatchDeleteStudentRequest request) throws WxErrorException;
53+
54+
/**
55+
* 批量更新学生
56+
* 请求方式:POST(HTTPS)
57+
* 请求地址:https://qyapi.weixin.qq.com/cgi-bin/school/user/batch_update_student?access_token=ACCESS_TOKEN
58+
*
59+
* @param request
60+
* @return
61+
* @throws WxErrorException
62+
*/
63+
WxCpBatchResultList batchUpdateStudent(@NonNull WxCpBatchUpdateStudentRequest request) throws WxErrorException;
64+
3265
/**
3366
* 删除学生
3467
* 请求方式:GET(HTTPS)

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpMessageServiceImpl.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,4 +46,15 @@ public WxCpLinkedCorpMessageSendResult sendLinkedCorpMessage(WxCpLinkedCorpMessa
4646
return WxCpLinkedCorpMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
4747
.getApiUrl(Message.LINKEDCORP_MESSAGE_SEND), message.toJson()));
4848
}
49+
50+
@Override
51+
public WxCpSchoolContactMessageSendResult sendSchoolContactMessage(WxCpSchoolContactMessage message) throws WxErrorException {
52+
if (null == message.getAgentId()) {
53+
message.setAgentId(this.cpService.getWxCpConfigStorage().getAgentId());
54+
}
55+
56+
return WxCpSchoolContactMessageSendResult.fromJson(this.cpService.post(this.cpService.getWxCpConfigStorage()
57+
.getApiUrl(Message.EXTERNAL_CONTACT_MESSAGE_SEND), message.toJson()));
58+
}
59+
4960
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpSchoolUserServiceImpl.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,27 @@ public WxCpBaseResp createStudent(@NonNull String studentUserId, @NonNull String
4747
return WxCpBaseResp.fromJson(responseContent);
4848
}
4949

50+
@Override
51+
public WxCpBatchResultList batchCreateStudent(@NonNull WxCpBatchCreateStudentRequest request) throws WxErrorException {
52+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_CREATE_STUDENT);
53+
String responseContent = this.cpService.post(apiUrl, request.toJson());
54+
return WxCpBatchResultList.fromJson(responseContent);
55+
}
56+
57+
@Override
58+
public WxCpBatchResultList batchDeleteStudent(@NonNull WxCpBatchDeleteStudentRequest request) throws WxErrorException {
59+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_DELETE_STUDENT);
60+
String responseContent = this.cpService.post(apiUrl, request.toJson());
61+
return WxCpBatchResultList.fromJson(responseContent);
62+
}
63+
64+
@Override
65+
public WxCpBatchResultList batchUpdateStudent(@NonNull WxCpBatchUpdateStudentRequest request) throws WxErrorException {
66+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(BATCH_UPDATE_STUDENT);
67+
String responseContent = this.cpService.post(apiUrl, request.toJson());
68+
return WxCpBatchResultList.fromJson(responseContent);
69+
}
70+
5071
@Override
5172
public WxCpBaseResp deleteStudent(@NonNull String studentUserId) throws WxErrorException {
5273
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(DELETE_STUDENT) + studentUserId;

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/article/NewArticle.java

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,22 @@
2020
@NoArgsConstructor
2121
public class NewArticle implements Serializable {
2222
private static final long serialVersionUID = 4087852055781140659L;
23+
2324
/**
2425
* 标题,不超过128个字节,超过会自动截断
2526
*/
2627
private String title;
28+
2729
/**
2830
* 描述,不超过512个字节,超过会自动截断
2931
*/
3032
private String description;
33+
3134
/**
3235
* 点击后跳转的链接。
3336
*/
3437
private String url;
38+
3539
/**
3640
* 图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图1068*455,小图150*150。
3741
*/
@@ -42,9 +46,14 @@ public class NewArticle implements Serializable {
4246
*/
4347
private String btnText;
4448

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

48-
/**点击消息卡片后的小程序页面,仅限本小程序内的页面。appid和pagepath必须同时填写,填写后会忽略url字段**/
54+
/**
55+
* 点击消息卡片后的小程序页面,仅限本小程序内的页面。appid和pagepath必须同时填写,填写后会忽略url字段
56+
*/
4957
private String pagepath;
58+
5059
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpLinkedCorpMessage.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
/**
2323
* 互联企业消息.
24+
* https://developer.work.weixin.qq.com/document/path/90250
2425
*
2526
* @author <a href="https://github.com/binarywang">Binary Wang</a>
2627
* @date 2020-08-30

0 commit comments

Comments
 (0)