Commit 1cd467ea by 孙喜旺 Committed by linkwechat8856@163.com

新增消息群发相关接口

1 parent bd67b406
package com.linkwechat.wecom.client;
import com.dtflys.forest.annotation.*;
import com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDataObjectDto;
import com.linkwechat.wecom.domain.dto.message.QueryCustomerMessageStatusResultDto;
import com.linkwechat.wecom.domain.dto.message.SendMessageResultDto;
import com.linkwechat.wecom.domain.dto.message.WeCustomerMessagePushDto;
import com.linkwechat.wecom.domain.dto.message.*;
import com.linkwechat.wecom.domain.query.WeAddMsgTemplateQuery;
import com.linkwechat.wecom.domain.query.WeGetGroupMsgListQuery;
import com.linkwechat.wecom.domain.query.WeGroupMsgListQuery;
import com.linkwechat.wecom.interceptor.WeAccessTokenInterceptor;
import com.linkwechat.wecom.retry.WeCommonRetryWhen;
......@@ -22,10 +22,11 @@ public interface WeCustomerMessagePushClient {
* 添加企业群发消息任务
* <a href="https://work.weixin.qq.com/api/doc/90000/90135/92135">API文档地址</a>
*/
@Request(url = "/externalcontact/add_msg_template",
type = "POST"
)
SendMessageResultDto sendCustomerMessageToUser(@JSONBody WeCustomerMessagePushDto customerMessagePushDto);
@Deprecated
@Request(url = "/externalcontact/add_msg_template", type = "POST")
SendMessageResultDto sendCustomerMessageToUser(@Body WeCustomerMessagePushDto customerMessagePushDto);
/**
* 获取企业群发消息发送结果
......@@ -33,13 +34,45 @@ public interface WeCustomerMessagePushClient {
*
* @param queryCustomerMessageStatusResultDataObjectDto{msgid} <a href="https://work.weixin.qq.com/api/doc/90000/90135/92135">添加企业群发消息任务返回的msgid</a>
*/
@Request(url = "/externalcontact/get_group_msg_result",
type = "POST"
)
@Deprecated
@Request(url = "/externalcontact/get_group_msg_result", type = "POST")
QueryCustomerMessageStatusResultDto queryCustomerMessageStatus(@JSONBody QueryCustomerMessageStatusResultDataObjectDto queryCustomerMessageStatusResultDataObjectDto);
/**
* 创建企业群发
*
* @param query {@link WeAddMsgTemplateQuery}
*/
@Request(url = "/externalcontact/add_msg_template", type = "POST")
SendMessageResultDto addMsgTemplate(@JSONBody WeAddMsgTemplateQuery query);
/**
* 获取群发记录列表
*
* @param query {@link WeGroupMsgListQuery}
* @return {@link WeGroupMsgListDto}
*/
@Request(url = "/externalcontact/get_groupmsg_list_v2",type = "POST")
WeGroupMsgListDto getGroupMsgResult(@JSONBody WeGroupMsgListQuery query);
/**
* 获取群发成员发送任务列表
*
* @param query {@link WeGetGroupMsgListQuery}
* @return {@link WeGroupMsgListDto}
*/
@Request(url = "/externalcontact/get_groupmsg_task",type = "POST")
WeGroupMsgListDto getGroupMsgTask(@JSONBody WeGetGroupMsgListQuery query);
/**
* 获取企业群发成员执行结果
*
* @param query {@link WeGetGroupMsgListQuery}
* @return {@link WeGroupMsgListDto}
*/
@Request(url = "/externalcontact/get_groupmsg_send_result",type = "POST")
WeGroupMsgListDto getGroupMsgSendResult(@JSONBody WeGetGroupMsgListQuery query);
}
package com.linkwechat.wecom.domain;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import javax.validation.constraints.NotNull;
/**
* @author danmo
* @description 应用消息通知入参
* @date 2021/10/3 11:59
**/
@ApiModel
@Data
public class WeMessageTemplate {
@ApiModelProperty("消息类型 文本:text, 图片:image, 语音:voice, 视频:video, 文件:file, 文本卡片:textcard, 图文:news, 图文消息:link, 小程序:miniprogram")
@NotNull(message = "消息类型不能为空")
private String msgType;
@ApiModelProperty("文本内容(文本消息必传)")
private String content;
@ApiModelProperty("素材id(语音、视频、文件 必传)")
private String mediaId;
@ApiModelProperty("消息的标题(视频、文本卡片、图文 必传)")
private String title;
@ApiModelProperty("消息的描述(视频、文本卡片、图文 必传)")
private String description;
@ApiModelProperty("点击后跳转的链接。最长2048字节,请确保包含了协议头(http/https) (文本卡片、图文 必传)")
private String linkUrl;
@ApiModelProperty("图文消息的图片链接,支持JPG、PNG格式,较好的效果为大图 1068*455,小图150*150。(文本卡片、图文 必传)")
private String picUrl;
@ApiModelProperty("小程序appid(可以在微信公众平台上查询),必须是关联到企业的小程序应用")
private String appId;
}
package com.linkwechat.wecom.domain.dto.message;
import com.alibaba.fastjson.JSONObject;
import com.linkwechat.wecom.domain.query.WeAddMsgTemplateQuery;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author danmo
* @description 消息
* @date 2021/10/3 16:35
**/
@ApiModel
@Data
public class WeGroupMsgDto {
@ApiModelProperty("企业群发消息的id")
private String msgId;
@ApiModelProperty("群发消息创建者userid,API接口创建的群发消息不返回该字段")
private String creator;
@ApiModelProperty("创建时间")
private Long createTime;
@ApiModelProperty("群发消息创建来源。0:企业 1:个人")
private String createType;
@ApiModelProperty("消息文本内容,最多4000个字节")
private WeAddMsgTemplateQuery.Text text;
@ApiModelProperty("企业群发消息的id")
private List<JSONObject> attachments;
}
package com.linkwechat.wecom.domain.dto.message;
import com.linkwechat.wecom.domain.dto.WeResultDto;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.List;
/**
* @author danmo
* @description 群发记录列表返回值
* @date 2021/10/3 16:30
**/
@ApiModel
@Data
public class WeGroupMsgListDto extends WeResultDto {
@ApiModelProperty("分页游标,再下次请求时填写以获取之后分页的记录,如果已经没有更多的数据则返回空")
private String nextCursor;
@ApiModelProperty("群发记录列表")
private List<WeGroupMsgDto> groupMsgList;
@ApiModelProperty("群发成员发送任务列表")
private List<WeGroupMsgTaskDto> taskList;
@ApiModelProperty("群成员发送结果列表")
private List<WeGroupMsgSendDto> sendList;
}
package com.linkwechat.wecom.domain.dto.message;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author sxw
* @description 群成员发送结果列表
* @date 2021/10/19 17:02
**/
@ApiModel
@Data
public class WeGroupMsgSendDto {
@ApiModelProperty("外部联系人userid,群发消息到企业的客户群不返回该字段")
private String externalUserId;
@ApiModelProperty("外部客户群id,群发消息到客户不返回该字段")
private String chatId;
@ApiModelProperty("企业服务人员的userid")
private String userId;
@ApiModelProperty("发送状态:0-未发送 1-已发送 2-因客户不是好友导致发送失败 3-因客户已经收到其他群发消息导致发送失败")
private Integer status;
@ApiModelProperty("发送时间,发送状态为1时返回")
private Long sendTime;
}
package com.linkwechat.wecom.domain.dto.message;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author sxw
* @description 群发成员发送任务列表
* @date 2021/10/19 16:56
**/
@Data
public class WeGroupMsgTaskDto {
@ApiModelProperty("企业服务人员的userid")
private String userId;
@ApiModelProperty("发送状态:0-未发送 2-已发送")
private Integer status;
@ApiModelProperty("发送时间,未发送时不返回")
private Long sendTime;
}
package com.linkwechat.wecom.domain.query;
import cn.hutool.core.util.ObjectUtil;
import com.linkwechat.common.exception.wecom.WeComException;
import com.linkwechat.wecom.domain.WeMessageTemplate;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import java.util.ArrayList;
import java.util.List;
/**
* 消息发送的对象入参
*
* @author danmo
* @date 2021-10-3
*/
@ApiModel
@Data
public class WeAddMsgTemplateQuery {
@ApiModelProperty("群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群")
private String chat_type;
@ApiModelProperty("客户的外部联系人id列表,仅在chat_type为single时有效,不可与sender同时为空,最多可传入1万个客户")
private List<String> external_userid;
@ApiModelProperty("发送企业群发消息的成员userid,当类型为发送给客户群时必填")
private String sender;
@ApiModelProperty("消息文本内容,最多4000个字节")
private Text text;
@ApiModelProperty("附件,最多支持添加9个附件 ru")
private List<Attachments> attachments;
public void setAttachments(List<WeMessageTemplate> messageTemplates) {
final int size = 9;
this.attachments = new ArrayList<>(16);
if (messageTemplates != null && messageTemplates.size() <= size) {
messageTemplates.forEach(messageTemplate -> {
if (ObjectUtil.equal("image", messageTemplate.getMsgType())) {
Attachments images = new Images(messageTemplate.getMsgType(), messageTemplate.getMediaId(),
messageTemplate.getPicUrl());
attachments.add(images);
} else if (ObjectUtil.equal("link", messageTemplate.getMsgType())) {
Attachments links = new Links(messageTemplate.getMsgType(), messageTemplate.getTitle(),
messageTemplate.getPicUrl(), messageTemplate.getDescription(), messageTemplate.getLinkUrl());
attachments.add(links);
} else if (ObjectUtil.equal("miniprogram", messageTemplate.getMsgType())) {
Attachments miniprograms = new Miniprograms(messageTemplate.getMsgType(), messageTemplate.getTitle(),
messageTemplate.getMediaId(), messageTemplate.getAppId(), messageTemplate.getLinkUrl());
attachments.add(miniprograms);
} else if (ObjectUtil.equal("video", messageTemplate.getMsgType())) {
Attachments videos = new Videos(messageTemplate.getMsgType(), messageTemplate.getMediaId());
attachments.add(videos);
} else if (ObjectUtil.equal("file", messageTemplate.getMsgType())) {
Attachments files = new Files(messageTemplate.getMsgType(), messageTemplate.getMediaId());
attachments.add(files);
}
});
} else {
throw new WeComException("仅支持最多同时发送9个附件");
}
}
@Data
public static class Attachments {
@ApiModelProperty("附件类型,可选image、link、miniprogram或者video")
private String msgtype;
}
@Data
public static class Images extends Attachments {
private Image image;
public Images(String msgType, String mediaId, String picUrl) {
super.setMsgtype(msgType);
this.image = new Image();
this.image.setMedia_id(mediaId);
this.image.setPic_url(picUrl);
}
@Data
public static class Image {
private String media_id;
private String pic_url;
}
}
@Data
public static class Links extends Attachments {
private Link link;
public Links(String msgType, String title, String picUrl, String desc, String url) {
super.setMsgtype(msgType);
this.link = new Link();
this.link.setTitle(title);
this.link.setPicurl(picUrl);
this.link.setDesc(desc);
this.link.setUrl(url);
}
@Data
public static class Link {
private String title;
private String picurl;
private String desc;
private String url;
}
}
@Data
public static class Miniprograms extends Attachments {
private Miniprogram miniprogram;
public Miniprograms(String msgType, String title, String mediaId, String appId, String page) {
super.setMsgtype(msgType);
this.miniprogram = new Miniprogram();
this.miniprogram.setTitle(title);
this.miniprogram.setPic_media_id(mediaId);
this.miniprogram.setAppid(appId);
this.miniprogram.setPage(page);
}
@Data
public static class Miniprogram {
private String title;
private String pic_media_id;
private String appid;
private String page;
}
}
@Data
public static class Videos extends Attachments {
private Video video;
public Videos(String msgType, String mediaId) {
super.setMsgtype(msgType);
this.video = new Video();
this.video.setMedia_id(mediaId);
}
@Data
public static class Video {
private String media_id;
}
}
@Data
public static class Files extends Attachments {
private File file;
public Files(String msgType, String mediaId) {
super.setMsgtype(msgType);
this.file = new File();
this.file.setMedia_id(mediaId);
}
@Data
public static class File {
private String media_id;
}
}
@ApiModel
@Data
public static class Text {
@ApiModelProperty("文本消息内容")
private String content;
}
}
package com.linkwechat.wecom.domain.query;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author sxw
* @description 群发成员发送任务列表入参
* @date 2021/10/19 16:49
**/
@ApiModel
@Data
public class WeGetGroupMsgListQuery {
@ApiModelProperty("群发消息的id")
private String msgId;
@ApiModelProperty("发送成员userid")
private String userId;
@ApiModelProperty("返回的最大记录数,整型,最大值1000,默认值500")
private Integer limit;
@ApiModelProperty("用于分页查询的游标")
private String cursor;
}
package com.linkwechat.wecom.domain.query;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
/**
* @author danmo
* @description 获取群发记录入参
* @date 2021/10/3 16:25
**/
@ApiModel
@Data
public class WeGroupMsgListQuery {
@ApiModelProperty("群发任务的类型,默认为single,表示发送给客户,group表示发送给客户群")
private String chat_type;
@ApiModelProperty("群发任务记录开始时间")
private Long start_time;
@ApiModelProperty("群发任务记录结束时间")
private Long end_time;
@ApiModelProperty("群发任务创建人企业账号id")
private String creator;
@ApiModelProperty("创建人类型。0:企业发表 1:个人发表 2:所有,包括个人创建以及企业创建,默认情况下为所有类型")
private Integer filter_type;
@ApiModelProperty("返回的最大记录数,整型,最大值100,默认值50")
private Integer limit;
@ApiModelProperty("用于分页查询的游标,字符串类型,由上一次调用返回,首次调用可不填")
private String cursor;
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!