Skip to content

Commit dea0f85

Browse files
wslongchenaieyes
authored andcommitted
🆕 binarywang#2365 【企业微信】新增获取企业群发记录及结果的接口
1 parent 7f5bcc5 commit dea0f85

File tree

7 files changed

+306
-4
lines changed

7 files changed

+306
-4
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/http/apache/ApacheHttpDnsClientBuilder.java

+4
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,12 @@
2020
import org.apache.http.impl.client.HttpClientBuilder;
2121
import org.apache.http.impl.client.HttpClients;
2222
import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
23+
import org.apache.http.protocol.HttpContext;
2324
import org.slf4j.Logger;
2425
import org.slf4j.LoggerFactory;
2526

2627
import javax.annotation.concurrent.NotThreadSafe;
28+
import java.io.IOException;
2729
import java.util.concurrent.TimeUnit;
2830
import java.util.concurrent.atomic.AtomicBoolean;
2931

@@ -52,10 +54,12 @@ public class ApacheHttpDnsClientBuilder implements ApacheHttpClientBuilder {
5254
private SSLConnectionSocketFactory sslConnectionSocketFactory = SSLConnectionSocketFactory.getSocketFactory();
5355
private PlainConnectionSocketFactory plainConnectionSocketFactory = PlainConnectionSocketFactory.getSocketFactory();
5456
private String httpProxyHost;
57+
5558
private int httpProxyPort;
5659
private String httpProxyUsername;
5760
private String httpProxyPassword;
5861

62+
5963
/**
6064
* 闲置连接监控线程.
6165
*/

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

+49-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferCustomerResp;
2121
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferResultResp;
2222
import me.chanjar.weixin.cp.bean.external.WxCpWelcomeMsg;
23-
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
24-
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
23+
import me.chanjar.weixin.cp.bean.external.contact.*;
24+
import me.chanjar.weixin.cp.bean.oa.WxCpApprovalInfoQueryFilter;
2525
import org.jetbrains.annotations.NotNull;
2626

2727
import java.util.Date;
@@ -587,4 +587,51 @@ WxCpExternalContactBatchInfo getContactDetailBatch(String[] userIdList, String c
587587
WxCpBaseResp markTag(String userid, String externalUserid, String[] addTag, String[] removeTag) throws WxErrorException;
588588

589589

590+
/**
591+
* <pre>
592+
* 企业和第三方应用可通过此接口获取企业与成员的群发记录。
593+
* https://work.weixin.qq.com/api/doc/90000/90135/93338
594+
* </pre>
595+
*
596+
* @param chatType 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
597+
* @param startTime 群发任务记录开始时间
598+
* @param endTime 群发任务记录结束时间
599+
* @param creator 群发任务创建人企业账号id
600+
* @param filterType 创建人类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
601+
* @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
602+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
603+
* @return wx cp base resp
604+
* @throws WxErrorException the wx error exception
605+
*/
606+
WxCpGroupMsgListResult getGroupMsgListV2(String chatType, @NonNull Date startTime, @NonNull Date endTime, String creator, Integer filterType, Integer limit, String cursor) throws WxErrorException;
607+
608+
/**
609+
* <pre>
610+
* 企业和第三方应用可通过此接口获取企业与成员的群发记录。
611+
* https://work.weixin.qq.com/api/doc/90000/90135/93338#获取企业群发成员执行结果
612+
* </pre>
613+
*
614+
* @param msgid 群发消息的id,通过获取群发记录列表接口返回
615+
* @param userid 发送成员userid,通过获取群发成员发送任务列表接口返回
616+
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
617+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
618+
* @return wx cp base resp
619+
* @throws WxErrorException the wx error exception
620+
*/
621+
WxCpGroupMsgSendResult getGroupMsgSendResult(String msgid, String userid, Integer limit, String cursor) throws WxErrorException;
622+
623+
/**
624+
* <pre>
625+
* 获取群发成员发送任务列表。
626+
* https://work.weixin.qq.com/api/doc/90000/90135/93338#获取群发成员发送任务列表
627+
* </pre>
628+
*
629+
* @param msgid 群发消息的id,通过获取群发记录列表接口返回
630+
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
631+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
632+
* @return wx cp base resp
633+
* @throws WxErrorException the wx error exception
634+
*/
635+
WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, String cursor) throws WxErrorException;
636+
590637
}

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

+83-2
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,7 @@
3131
import me.chanjar.weixin.cp.bean.external.WxCpUserTransferResultResp;
3232
import me.chanjar.weixin.cp.bean.external.WxCpUserWithExternalPermission;
3333
import me.chanjar.weixin.cp.bean.external.WxCpWelcomeMsg;
34-
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
35-
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
34+
import me.chanjar.weixin.cp.bean.external.contact.*;
3635
import org.apache.commons.lang3.ArrayUtils;
3736
import org.apache.commons.lang3.StringUtils;
3837
import org.jetbrains.annotations.NotNull;
@@ -449,4 +448,86 @@ public WxCpBaseResp markTag(String userid, String externalUserid, String[] addTa
449448
final String result = this.mainService.post(url, json.toString());
450449
return WxCpBaseResp.fromJson(result);
451450
}
451+
452+
/**
453+
* <pre>
454+
* 企业和第三方应用可通过此接口获取企业与成员的群发记录。
455+
* https://work.weixin.qq.com/api/doc/90000/90135/93338
456+
* </pre>
457+
*
458+
* @param chatType 群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群
459+
* @param startTime 群发任务记录开始时间
460+
* @param endTime 群发任务记录结束时间
461+
* @param creator 群发任务创建人企业账号id
462+
* @param filterType 创建人类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型
463+
* @param limit 返回的最大记录数,整型,最大值100,默认值50,超过最大值时取默认值
464+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
465+
* @return wx cp base resp
466+
* @throws WxErrorException the wx error exception
467+
*/
468+
@Override
469+
public WxCpGroupMsgListResult getGroupMsgListV2(String chatType, @NonNull Date startTime, @NonNull Date endTime, String creator, Integer filterType, Integer limit, String cursor) throws WxErrorException {
470+
JsonObject json = new JsonObject();
471+
json.addProperty("chat_type", chatType);
472+
json.addProperty("start_time", startTime.getTime() / 1000);
473+
json.addProperty("end_time", endTime.getTime() / 1000);
474+
json.addProperty("creator", creator);
475+
json.addProperty("filter_type", filterType);
476+
json.addProperty("limit", limit);
477+
json.addProperty("cursor", cursor);
478+
479+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT);
480+
final String result = this.mainService.post(url, json.toString());
481+
return WxCpGroupMsgListResult.fromJson(result);
482+
}
483+
484+
/**
485+
* <pre>
486+
* 企业和第三方应用可通过此接口获取企业与成员的群发记录。
487+
* https://work.weixin.qq.com/api/doc/90000/90135/93338#获取企业群发成员执行结果
488+
* </pre>
489+
*
490+
* @param msgid 群发消息的id,通过获取群发记录列表接口返回
491+
* @param userid 发送成员userid,通过获取群发成员发送任务列表接口返回
492+
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
493+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
494+
* @return wx cp base resp
495+
* @throws WxErrorException the wx error exception
496+
*/
497+
@Override
498+
public WxCpGroupMsgSendResult getGroupMsgSendResult(String msgid, String userid, Integer limit, String cursor) throws WxErrorException {
499+
JsonObject json = new JsonObject();
500+
json.addProperty("msgid", msgid);
501+
json.addProperty("userid", userid);
502+
json.addProperty("limit", limit);
503+
json.addProperty("cursor", cursor);
504+
505+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT);
506+
final String result = this.mainService.post(url, json.toString());
507+
return WxCpGroupMsgSendResult.fromJson(result);
508+
}
509+
510+
/**
511+
* <pre>
512+
* 获取群发成员发送任务列表。
513+
* https://work.weixin.qq.com/api/doc/90000/90135/93338#获取群发成员发送任务列表
514+
* </pre>
515+
*
516+
* @param msgid 群发消息的id,通过获取群发记录列表接口返回
517+
* @param limit 返回的最大记录数,整型,最大值1000,默认值500,超过最大值时取默认值
518+
* @param cursor 用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填
519+
* @return wx cp base resp
520+
* @throws WxErrorException the wx error exception
521+
*/
522+
@Override
523+
public WxCpGroupMsgTaskResult getGroupMsgTask(String msgid, Integer limit, String cursor) throws WxErrorException {
524+
JsonObject json = new JsonObject();
525+
json.addProperty("msgid", msgid);
526+
json.addProperty("limit", limit);
527+
json.addProperty("cursor", cursor);
528+
529+
final String url = this.mainService.getWxCpConfigStorage().getApiUrl(GET_GROUP_MSG_SEND_RESULT);
530+
final String result = this.mainService.post(url, json.toString());
531+
return WxCpGroupMsgTaskResult.fromJson(result);
532+
}
452533
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package me.chanjar.weixin.cp.bean.external.contact;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
8+
import me.chanjar.weixin.cp.bean.external.msg.Text;
9+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
10+
11+
import java.io.Serializable;
12+
import java.util.List;
13+
14+
/**
15+
* <pre>
16+
* 获取企业群发成员执行结果
17+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/93338
18+
* </pre>
19+
*
20+
* @author <a href="https://github.com/wslongchen">Mr.Pan</a>
21+
*/
22+
@Getter
23+
@Setter
24+
public class WxCpGroupMsgListResult extends WxCpBaseResp implements Serializable {
25+
26+
private static final long serialVersionUID = 3464981991558716620L;
27+
28+
@SerializedName("group_msg_list")
29+
private List<ExternalContactGroupMsgInfo> groupMsgList;
30+
31+
@SerializedName("next_cursor")
32+
private String nextCursor;
33+
34+
@Getter
35+
@Setter
36+
public static class ExternalContactGroupMsgInfo implements Serializable {
37+
38+
private static final long serialVersionUID = 3108435608725559381L;
39+
@SerializedName("msgid")
40+
private String msgId;
41+
42+
private String creator;
43+
44+
private Text text;
45+
46+
private List<Attachment> attachments;
47+
48+
@SerializedName("create_type")
49+
private Integer createType;
50+
51+
@SerializedName("create_time")
52+
private Long createTime;
53+
54+
}
55+
56+
public static WxCpGroupMsgListResult fromJson(String json) {
57+
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupMsgListResult.class);
58+
}
59+
60+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package me.chanjar.weixin.cp.bean.external.contact;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* <pre>
14+
* 获取企业群发成员执行结果
15+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/93338
16+
* </pre>
17+
*
18+
* @author <a href="https://github.com/wslongchen">Mr.Pan</a>
19+
*/
20+
@Getter
21+
@Setter
22+
public class WxCpGroupMsgSendResult extends WxCpBaseResp implements Serializable {
23+
private static final long serialVersionUID = -5166048319463473186L;
24+
25+
@SerializedName("send_list")
26+
private List<ExternalContactGroupMsgSendInfo> sendList;
27+
28+
@SerializedName("next_cursor")
29+
private String nextCursor;
30+
31+
@Getter
32+
@Setter
33+
public static class ExternalContactGroupMsgSendInfo implements Serializable {
34+
private static final long serialVersionUID = 1500416806087532531L;
35+
36+
@SerializedName("external_userid")
37+
private String externalUserId;
38+
39+
@SerializedName("chat_id")
40+
private String chatId;
41+
42+
@SerializedName("userid")
43+
private String userId;
44+
45+
private Integer status;
46+
47+
@SerializedName("send_time")
48+
private Long sendTime;
49+
50+
}
51+
52+
public static WxCpGroupMsgSendResult fromJson(String json) {
53+
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupMsgSendResult.class);
54+
}
55+
56+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package me.chanjar.weixin.cp.bean.external.contact;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
7+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
8+
9+
import java.io.Serializable;
10+
import java.util.List;
11+
12+
/**
13+
* <pre>
14+
* 获取群发成员发送任务列表
15+
* 参考文档:https://work.weixin.qq.com/api/doc/90000/90135/93338
16+
* </pre>
17+
*
18+
* @author <a href="https://github.com/wslongchen">Mr.Pan</a>
19+
*/
20+
@Getter
21+
@Setter
22+
public class WxCpGroupMsgTaskResult extends WxCpBaseResp implements Serializable {
23+
private static final long serialVersionUID = -5166048319463473186L;
24+
25+
@SerializedName("task_list")
26+
private List<ExternalContactGroupMsgTaskInfo> taskList;
27+
28+
@SerializedName("next_cursor")
29+
private String nextCursor;
30+
31+
@Getter
32+
@Setter
33+
public static class ExternalContactGroupMsgTaskInfo implements Serializable {
34+
private static final long serialVersionUID = 1500416806087532531L;
35+
36+
@SerializedName("userid")
37+
private String userId;
38+
39+
private Integer status;
40+
41+
@SerializedName("send_time")
42+
private Long sendTime;
43+
44+
}
45+
46+
public static WxCpGroupMsgTaskResult fromJson(String json) {
47+
return WxCpGsonBuilder.create().fromJson(json, WxCpGroupMsgTaskResult.class);
48+
}
49+
50+
}

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java

+4
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,9 @@ interface ExternalContact {
205205
String EDIT_CORP_TAG = "/cgi-bin/externalcontact/edit_corp_tag";
206206
String DEL_CORP_TAG = "/cgi-bin/externalcontact/del_corp_tag";
207207
String MARK_TAG = "/cgi-bin/externalcontact/mark_tag";
208+
209+
String GET_GROUP_MSG_SEND_RESULT = "/cgi-bin/externalcontact/get_groupmsg_send_result";
210+
String GET_GROUP_MSG_TASK = "/cgi-bin/externalcontact/get_groupmsg_task";
211+
String GET_GROUP_MSG_LIST_V2 = "/cgi-bin/externalcontact/get_groupmsg_list_v2";
208212
}
209213
}

0 commit comments

Comments
 (0)