forked from binarywang/WxJava
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
🆕 binarywang#3228 【企业微信】增加办公-发送邮件模块相关接口
- Loading branch information
Showing
6 changed files
with
875 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpOaMailService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} |
80 changes: 80 additions & 0 deletions
80
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpOMailServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
244 changes: 244 additions & 0 deletions
244
...in-java-cp/src/main/java/me/chanjar/weixin/cp/bean/oa/mail/WxCpMailCommonSendRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,244 @@ | ||
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; | ||
|
||
/** | ||
* 内容类型 html,text(默认是html) | ||
*/ | ||
@SerializedName("content_type") | ||
private String contentType; | ||
|
||
/** | ||
* 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。 | ||
* 目前仅subject、content、attachment_list[].file_name字段支持转译。 | ||
*/ | ||
@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); | ||
} | ||
|
||
} |
Oops, something went wrong.