Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat:【企业微信】增加办公-发送邮件模块相关接口
Browse files Browse the repository at this point in the history
Hugo-Ho committed Jan 31, 2024
1 parent 2ec6a0f commit 2aca9c7
Showing 6 changed files with 874 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
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.oa.mail.WxCpMailCommonSendRequest;
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailMeetingSendRequest;
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailScheduleSendRequest;

/**
* 企业微信y邮件相关接口.
* <a href="https://developer.work.weixin.qq.com/document/path/95486">邮件</a>
*
* @author Hugo
*/
public interface WxCpOaMailService {

/**
* 发送普通邮件
* 应用可以通过该接口发送普通邮件,支持附件能力。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
*
* @param request 发送普通邮件请求参数
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp mailCommonSend(@NonNull WxCpMailCommonSendRequest request) throws WxErrorException;

/**
* 发送日程邮件
* 应用可以通过该接口发送日程邮件。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
*
* @param request 发送日程邮件请求参数
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp mailScheduleSend(@NonNull WxCpMailScheduleSendRequest request) throws WxErrorException;

/**
* 发送会议邮件
* 应用可以通过该接口发送会议邮件。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
*
* @param request 发送会议邮件请求参数
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
WxCpBaseResp mailMeetingSend(@NonNull WxCpMailMeetingSendRequest request) throws WxErrorException;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package me.chanjar.weixin.cp.api.impl;

import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpOaMailService;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailCommonSendRequest;
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailMeetingSendRequest;
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailScheduleSendRequest;

import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.EXMAIL_APP_COMPOSE_SEND;

/**
* 企业微信邮件接口实现类.
*
* @author Hugo
*/
@Slf4j
@RequiredArgsConstructor
public class WxCpOMailServiceImpl implements WxCpOaMailService {
private final WxCpService cpService;

/**
* 发送普通邮件
* 应用可以通过该接口发送普通邮件,支持附件能力。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
*
* @param request 发送普通邮件请求参数
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
@Override
public WxCpBaseResp mailCommonSend(@NonNull WxCpMailCommonSendRequest request) throws WxErrorException {
return this.mailSend(request.toJson());
}

/**
* 发送日程邮件
* 应用可以通过该接口发送日程邮件。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
*
* @param request 发送日程邮件请求参数
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
@Override
public WxCpBaseResp mailScheduleSend(@NonNull WxCpMailScheduleSendRequest request) throws WxErrorException {
return this.mailSend(request.toJson());
}

/**
* 发送会议邮件
* 应用可以通过该接口发送会议邮件。
* <p>
* 请求方式:POST(HTTPS)
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
*
* @param request 发送会议邮件请求参数
* @return wx cp base resp
* @throws WxErrorException the wx error exception
*/
@Override
public WxCpBaseResp mailMeetingSend(@NonNull WxCpMailMeetingSendRequest request) throws WxErrorException {

return this.mailSend(request.toJson());
}

private WxCpBaseResp mailSend(String request) throws WxErrorException {
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(EXMAIL_APP_COMPOSE_SEND);
String responseContent = this.cpService.post(apiUrl, request);
return WxCpBaseResp.fromJson(responseContent);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,243 @@
package me.chanjar.weixin.cp.bean.oa.mail;

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 Hugo
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpMailCommonSendRequest implements Serializable {
private static final long serialVersionUID = -4961239393895454138L;

/**
* 收件人,to.emails 和 to.userids 至少传一个
*/
@SerializedName("to")
private TO to;

/**
* 抄送
*/
@SerializedName("cc")
private CC cc;

/**
* 文档类型, 3:文档 4:表格
*/
@SerializedName("bcc")
private BCC bcc;

/**
* 标题
*/
@SerializedName("subject")
private String subject;

/**
* 内容
*/
@SerializedName("content")
private String content;

/**
* 附件相关
*/
@SerializedName("attachment_list")
private List<Attachment> attachmentList;

/**
* 内容
*/
@SerializedName("content_type")
private String contentType;

/**
* 内容
*/
@SerializedName("enable_id_trans")
private Integer enableIdTrans;

@Getter
@Setter
public static class TO implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

/**
* 收件人,邮箱地址
*/
@SerializedName("emails")
private List<String> emails;

/**
* 收件人,企业内成员的userid
*/
@SerializedName("userids")
private List<String> userIds;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailCommonSendRequest.TO fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.TO.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class CC implements Serializable {
private static final long serialVersionUID = -4863239393895754598L;

/**
* 抄送人,邮箱地址
*/
@SerializedName("emails")
private List<String> emails;

/**
* 抄送人,企业内成员的userid
*/
@SerializedName("userids")
private List<String> userIds;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailCommonSendRequest.CC fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.CC.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class BCC implements Serializable {
private static final long serialVersionUID = -4860239393885754598L;

/**
* 密送人,邮箱地址
*/
@SerializedName("emails")
private List<String> emails;

/**
* 密送人,企业内成员的userid
*/
@SerializedName("userids")
private List<String> userIds;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailCommonSendRequest.BCC fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.BCC.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class Attachment implements Serializable {
private static final long serialVersionUID = -4860230393895754598L;

/**
* 文件名
*/
@SerializedName("file_name")
private String fileName;

/**
* 文件内容(base64编码),所有附件加正文的大小不允许超过50M, 且附件个数不能超过200个
*/
@SerializedName("content")
private String content;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailCommonSendRequest.Attachment fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.Attachment.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

/**
* From json wx cp space create request.
*
* @param json the json
* @return the wx cp space create request
*/
public static WxCpMailCommonSendRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,239 @@
package me.chanjar.weixin.cp.bean.oa.mail;

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 Hugo
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpMailMeetingSendRequest extends WxCpMailScheduleSendRequest implements Serializable {
private static final long serialVersionUID = -4961279393895454138L;

/**
* 会议相关,会议邮件必填,且必须同时带上schedule,会议的基本设置放在schedule里
*/
@SerializedName("meeting")
private Meeting meeting;

@Getter
@Setter
public static class Meeting implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

/**
* 会议相关设置
*/
@SerializedName("option")
private Option option;

/**
* 会议主持人列表,最多10个。定义见收件人字段,只支持填userid
*/
@SerializedName("hosts")
private Hosts hosts;

/**
* 会议管理员字段, , 仅可指定1人,只支持传userid,必须是同企业的用户,且在参与人中
*/
@SerializedName("meeting_admins")
private MeetingAdmins meetingAdmins;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailMeetingSendRequest.Meeting fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailMeetingSendRequest.Meeting.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class Option implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

/**
* 入会密码,仅可输入4-6位纯数字
*/
@SerializedName("password")
private String password;

/**
* 是否自动录制
* 0:未开启自动录制,1:开启自动本地录制,2:开启自动云录制;默认不开启
*/
@SerializedName("auto_record")
private Integer autoRecord;

/**
* 是否开启等候室
* false:不开启等候室;true:开启等候室;默认不开
*/
@SerializedName("enable_waiting_room")
private Boolean enableWaitingRoom;

/**
* 是否允许成员在主持人进会前加入。
* true:允许;false:不允许。默认允许
*/
@SerializedName("allow_enter_before_host")
private Boolean allowEnterBeforeHost;

/**
* 是否限制成员入会
* 0:所有人可入会 2:仅企业内部用户可入会;默认所有人可入会
*/
@SerializedName("enter_restraint")
private Integer enterRestraint;

/**
* 是否开启屏幕水印
* true:开启;false:不开启。默认不开启
*/
@SerializedName("enable_screen_watermark")
private Boolean enableScreenWatermark;

/**
* 成员入会时是否静音
* 1:开启;0:关闭;2:超过6人后自动开启静音。默认超过6人自动开启静音
*/
@SerializedName("enable_enter_mute")
private Integer enableEnterMute;

/**
* 会议开始时是否提醒
* 1:不提醒 2:仅提醒主持人 3:提醒所有成员入会; 默认仅提醒主持人
*/
@SerializedName("remind_scope")
private Integer remindScope;

/**
* 水印类型
* 0:单排水印 1:多排水印;默认单排水印
*/
@SerializedName("water_mark_type")
private Integer waterMarkType;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailMeetingSendRequest.Option fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailMeetingSendRequest.Option.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class Hosts implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

@SerializedName("userids")
private List<String> userIds;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailMeetingSendRequest.Hosts fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailMeetingSendRequest.Hosts.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class MeetingAdmins implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

@SerializedName("userids")
private List<String> userIds;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailMeetingSendRequest.MeetingAdmins fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailMeetingSendRequest.MeetingAdmins.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

/**
* From json wx cp space create request.
*
* @param json the json
* @return the wx cp space create request
*/
public static WxCpMailMeetingSendRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailMeetingSendRequest.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,246 @@
package me.chanjar.weixin.cp.bean.oa.mail;

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 Hugo
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class WxCpMailScheduleSendRequest extends WxCpMailCommonSendRequest implements Serializable {
private static final long serialVersionUID = -4961279393895454138L;

/**
* 标题
*/
@SerializedName("schedule")
private Schedule schedule;

@Getter
@Setter
public static class Schedule implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

/**
* 日程ID (修改/取消日程必须带上schedule_id)
*/
@SerializedName("is_remind")
private String scheduleId;

/**
* 日程方法:
* request-请求(不传schedule_id时是创建日程,传了是修改日程)
* <p>
* cancel-取消日程(必须带上schedule_id)
* <p>
* 默认为request
*/
@SerializedName("method")
private String method;

/**
* 地点
*/
@SerializedName("location")
private String location;

/**
* 日程开始时间,Unix时间戳
*/
@SerializedName("start_time")
private Integer startTime;

/**
* 日程结束时间,Unix时间戳
*/
@SerializedName("end_time")
private Integer endTime;

/**
* 重复和提醒相关字段
*/
@SerializedName("reminders")
private Reminders reminders;


/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailScheduleSendRequest.Schedule fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailScheduleSendRequest.Schedule.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

@Getter
@Setter
public static class Reminders implements Serializable {
private static final long serialVersionUID = -4860239393895754598L;

/**
* 是否有提醒 0-不提醒 1-提醒
*/
@SerializedName("is_remind")
private Integer isRemind;

/**
* 日程开始(start_time)前多少分钟提醒,当is_remind=1时有效。例如:
* 15表示日程开始前15分钟提醒
* <p>
* -15表示日程开始后15分钟提醒
*/
@SerializedName("remind_before_event_mins")
private Integer remindBeforeEventMins;

/**
* 是否重复 0-否 1-是
*/
@SerializedName("is_repeat")
private Integer isRepeat;

/**
* 是否自定义重复 0-否 1-是。当is_repeat为1时有效。
*/
@SerializedName("is_custom_repeat")
private Integer isCustomRepeat;

/**
* 时区。UTC偏移量表示(即偏离零时区的小时数),东区为正数,西区为负数。
* 例如:+8 表示北京时间东八区
* <p>
* 默认为北京时间东八区
* <p>
* 取值范围:-12 ~ +12
*/
@SerializedName("timezone")
private Integer timeZone;

/**
* 重复间隔
* 仅当指定为自定义重复时有效,该字段随repeat_type不同而含义不同
* <p>
* 例如:
* <p>
* repeat_interval指定为2,repeat_type指定为每周重复,那么每2周重复一次;
* <p>
* repeat_interval指定为2,repeat_type指定为每月重复,那么每2月重复一次
*/
@SerializedName("repeat_interval")
private Integer repeatInterval;

/**
* 重复类型,当is_repeat=1时有效。目前支持如下类型:
* 0 - 每日
* <p>
* 1 - 每周
* <p>
* 2 - 每月
* <p>
* 5 - 每年
*/
@SerializedName("repeat_type")
private Integer repeatType;

/**
* 每周周几重复
* 仅当指定为自定义重复且重复类型为每周时有效
* <p>
* 取值范围:1 ~ 7,分别表示周一至周日
*/
@SerializedName("repeat_day_of_week")
private List<Integer> repeatDayOfWeek;

/**
* 每月哪几天重复
* 仅当指定为自定义重复, 且重复类型为每月或每年时有效
* <p>
* 取值范围:1 ~ 31,分别表示1~31号
*/
@SerializedName("repeat_day_of_month")
private List<String> repeatDayOfMonth;

/**
* 标题
*/
@SerializedName("repeat_week_of_month")
private List<String> repeatWeekOfMonth;

/**
* 每年哪几个月重复
* 仅当指定为自定义重复且重复类型为每年时有效
* <p>
* 取值范围:1 ~ 12,分别表示 1月 - 12月(每年重复需要repeat_month_of_year和repeat_day_of_month来指定某一天)
*/
@SerializedName("repeat_month_of_year")
private List<String> repeatMonthOfYear;

/**
* 重复结束时刻,Unix时间戳,当is_repeat=1时有效。不填或填0表示一直重复
*/
@SerializedName("repeat_until")
private Integer repeatUntil;

/**
* From json space info.
*
* @param json the json
* @return the space info
*/
public static WxCpMailScheduleSendRequest.Reminders fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailScheduleSendRequest.Reminders.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}

/**
* From json wx cp space create request.
*
* @param json the json
* @return the wx cp space create request
*/
public static WxCpMailScheduleSendRequest fromJson(String json) {
return WxCpGsonBuilder.create().fromJson(json, WxCpMailScheduleSendRequest.class);
}

/**
* To json string.
*
* @return the string
*/
public String toJson() {
return WxCpGsonBuilder.create().toJson(this);
}

}
Original file line number Diff line number Diff line change
@@ -533,6 +533,15 @@ interface Oa {
*/
String WEDOC_DOC_SHARE = "/cgi-bin/wedoc/doc_share";

/**
* 邮件
* https://developer.work.weixin.qq.com/document/path/95486
*/
/**
* The constant EXMAIL_APP_COMPOSE_SEND.
*/
String EXMAIL_APP_COMPOSE_SEND = "/cgi-bin/exmail/app/compose_send";

}

/**

0 comments on commit 2aca9c7

Please sign in to comment.