Skip to content

Commit d3f8216

Browse files
authored
🆕 #3228 【企业微信】增加办公-发送邮件模块相关接口
1 parent 1490800 commit d3f8216

File tree

6 files changed

+875
-0
lines changed

6 files changed

+875
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package me.chanjar.weixin.cp.api;
2+
3+
import lombok.NonNull;
4+
import me.chanjar.weixin.common.error.WxErrorException;
5+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
6+
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailCommonSendRequest;
7+
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailMeetingSendRequest;
8+
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailScheduleSendRequest;
9+
10+
/**
11+
* 企业微信y邮件相关接口.
12+
* <a href="https://developer.work.weixin.qq.com/document/path/95486">邮件</a>
13+
*
14+
* @author Hugo
15+
*/
16+
public interface WxCpOaMailService {
17+
18+
/**
19+
* 发送普通邮件
20+
* 应用可以通过该接口发送普通邮件,支持附件能力。
21+
* <p>
22+
* 请求方式:POST(HTTPS)
23+
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
24+
*
25+
* @param request 发送普通邮件请求参数
26+
* @return wx cp base resp
27+
* @throws WxErrorException the wx error exception
28+
*/
29+
WxCpBaseResp mailCommonSend(@NonNull WxCpMailCommonSendRequest request) throws WxErrorException;
30+
31+
/**
32+
* 发送日程邮件
33+
* 应用可以通过该接口发送日程邮件。
34+
* <p>
35+
* 请求方式:POST(HTTPS)
36+
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
37+
*
38+
* @param request 发送日程邮件请求参数
39+
* @return wx cp base resp
40+
* @throws WxErrorException the wx error exception
41+
*/
42+
WxCpBaseResp mailScheduleSend(@NonNull WxCpMailScheduleSendRequest request) throws WxErrorException;
43+
44+
/**
45+
* 发送会议邮件
46+
* 应用可以通过该接口发送会议邮件。
47+
* <p>
48+
* 请求方式:POST(HTTPS)
49+
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
50+
*
51+
* @param request 发送会议邮件请求参数
52+
* @return wx cp base resp
53+
* @throws WxErrorException the wx error exception
54+
*/
55+
WxCpBaseResp mailMeetingSend(@NonNull WxCpMailMeetingSendRequest request) throws WxErrorException;
56+
57+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
package me.chanjar.weixin.cp.api.impl;
2+
3+
import lombok.NonNull;
4+
import lombok.RequiredArgsConstructor;
5+
import lombok.extern.slf4j.Slf4j;
6+
import me.chanjar.weixin.common.error.WxErrorException;
7+
import me.chanjar.weixin.cp.api.WxCpOaMailService;
8+
import me.chanjar.weixin.cp.api.WxCpService;
9+
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
10+
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailCommonSendRequest;
11+
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailMeetingSendRequest;
12+
import me.chanjar.weixin.cp.bean.oa.mail.WxCpMailScheduleSendRequest;
13+
14+
import static me.chanjar.weixin.cp.constant.WxCpApiPathConsts.Oa.EXMAIL_APP_COMPOSE_SEND;
15+
16+
/**
17+
* 企业微信邮件接口实现类.
18+
*
19+
* @author Hugo
20+
*/
21+
@Slf4j
22+
@RequiredArgsConstructor
23+
public class WxCpOMailServiceImpl implements WxCpOaMailService {
24+
private final WxCpService cpService;
25+
26+
/**
27+
* 发送普通邮件
28+
* 应用可以通过该接口发送普通邮件,支持附件能力。
29+
* <p>
30+
* 请求方式:POST(HTTPS)
31+
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
32+
*
33+
* @param request 发送普通邮件请求参数
34+
* @return wx cp base resp
35+
* @throws WxErrorException the wx error exception
36+
*/
37+
@Override
38+
public WxCpBaseResp mailCommonSend(@NonNull WxCpMailCommonSendRequest request) throws WxErrorException {
39+
return this.mailSend(request.toJson());
40+
}
41+
42+
/**
43+
* 发送日程邮件
44+
* 应用可以通过该接口发送日程邮件。
45+
* <p>
46+
* 请求方式:POST(HTTPS)
47+
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
48+
*
49+
* @param request 发送日程邮件请求参数
50+
* @return wx cp base resp
51+
* @throws WxErrorException the wx error exception
52+
*/
53+
@Override
54+
public WxCpBaseResp mailScheduleSend(@NonNull WxCpMailScheduleSendRequest request) throws WxErrorException {
55+
return this.mailSend(request.toJson());
56+
}
57+
58+
/**
59+
* 发送会议邮件
60+
* 应用可以通过该接口发送会议邮件。
61+
* <p>
62+
* 请求方式:POST(HTTPS)
63+
* 请求地址: <a href="https://qyapi.weixin.qq.com/cgi-bin/exmail/app/compose_send?access_token=ACCESS_TOKEN">...</a>
64+
*
65+
* @param request 发送会议邮件请求参数
66+
* @return wx cp base resp
67+
* @throws WxErrorException the wx error exception
68+
*/
69+
@Override
70+
public WxCpBaseResp mailMeetingSend(@NonNull WxCpMailMeetingSendRequest request) throws WxErrorException {
71+
72+
return this.mailSend(request.toJson());
73+
}
74+
75+
private WxCpBaseResp mailSend(String request) throws WxErrorException {
76+
String apiUrl = this.cpService.getWxCpConfigStorage().getApiUrl(EXMAIL_APP_COMPOSE_SEND);
77+
String responseContent = this.cpService.post(apiUrl, request);
78+
return WxCpBaseResp.fromJson(responseContent);
79+
}
80+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,244 @@
1+
package me.chanjar.weixin.cp.bean.oa.mail;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
import lombok.experimental.Accessors;
6+
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* 发送普通邮件请求.
13+
*
14+
* @author Hugo
15+
*/
16+
@Data
17+
@Builder
18+
@NoArgsConstructor
19+
@AllArgsConstructor
20+
@Accessors(chain = true)
21+
public class WxCpMailCommonSendRequest implements Serializable {
22+
private static final long serialVersionUID = -4961239393895454138L;
23+
24+
/**
25+
* 收件人,to.emails 和 to.userids 至少传一个
26+
*/
27+
@SerializedName("to")
28+
private TO to;
29+
30+
/**
31+
* 抄送
32+
*/
33+
@SerializedName("cc")
34+
private CC cc;
35+
36+
/**
37+
* 文档类型, 3:文档 4:表格
38+
*/
39+
@SerializedName("bcc")
40+
private BCC bcc;
41+
42+
/**
43+
* 标题
44+
*/
45+
@SerializedName("subject")
46+
private String subject;
47+
48+
/**
49+
* 内容
50+
*/
51+
@SerializedName("content")
52+
private String content;
53+
54+
/**
55+
* 附件相关
56+
*/
57+
@SerializedName("attachment_list")
58+
private List<Attachment> attachmentList;
59+
60+
/**
61+
* 内容类型 html,text(默认是html)
62+
*/
63+
@SerializedName("content_type")
64+
private String contentType;
65+
66+
/**
67+
* 表示是否开启id转译,0表示否,1表示是,默认0。仅第三方应用需要用到,企业自建应用可以忽略。
68+
* 目前仅subject、content、attachment_list[].file_name字段支持转译。
69+
*/
70+
@SerializedName("enable_id_trans")
71+
private Integer enableIdTrans;
72+
73+
@Getter
74+
@Setter
75+
public static class TO implements Serializable {
76+
private static final long serialVersionUID = -4860239393895754598L;
77+
78+
/**
79+
* 收件人,邮箱地址
80+
*/
81+
@SerializedName("emails")
82+
private List<String> emails;
83+
84+
/**
85+
* 收件人,企业内成员的userid
86+
*/
87+
@SerializedName("userids")
88+
private List<String> userIds;
89+
90+
/**
91+
* From json space info.
92+
*
93+
* @param json the json
94+
* @return the space info
95+
*/
96+
public static WxCpMailCommonSendRequest.TO fromJson(String json) {
97+
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.TO.class);
98+
}
99+
100+
/**
101+
* To json string.
102+
*
103+
* @return the string
104+
*/
105+
public String toJson() {
106+
return WxCpGsonBuilder.create().toJson(this);
107+
}
108+
109+
}
110+
111+
@Getter
112+
@Setter
113+
public static class CC implements Serializable {
114+
private static final long serialVersionUID = -4863239393895754598L;
115+
116+
/**
117+
* 抄送人,邮箱地址
118+
*/
119+
@SerializedName("emails")
120+
private List<String> emails;
121+
122+
/**
123+
* 抄送人,企业内成员的userid
124+
*/
125+
@SerializedName("userids")
126+
private List<String> userIds;
127+
128+
/**
129+
* From json space info.
130+
*
131+
* @param json the json
132+
* @return the space info
133+
*/
134+
public static WxCpMailCommonSendRequest.CC fromJson(String json) {
135+
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.CC.class);
136+
}
137+
138+
/**
139+
* To json string.
140+
*
141+
* @return the string
142+
*/
143+
public String toJson() {
144+
return WxCpGsonBuilder.create().toJson(this);
145+
}
146+
147+
}
148+
149+
@Getter
150+
@Setter
151+
public static class BCC implements Serializable {
152+
private static final long serialVersionUID = -4860239393885754598L;
153+
154+
/**
155+
* 密送人,邮箱地址
156+
*/
157+
@SerializedName("emails")
158+
private List<String> emails;
159+
160+
/**
161+
* 密送人,企业内成员的userid
162+
*/
163+
@SerializedName("userids")
164+
private List<String> userIds;
165+
166+
/**
167+
* From json space info.
168+
*
169+
* @param json the json
170+
* @return the space info
171+
*/
172+
public static WxCpMailCommonSendRequest.BCC fromJson(String json) {
173+
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.BCC.class);
174+
}
175+
176+
/**
177+
* To json string.
178+
*
179+
* @return the string
180+
*/
181+
public String toJson() {
182+
return WxCpGsonBuilder.create().toJson(this);
183+
}
184+
185+
}
186+
187+
@Getter
188+
@Setter
189+
public static class Attachment implements Serializable {
190+
private static final long serialVersionUID = -4860230393895754598L;
191+
192+
/**
193+
* 文件名
194+
*/
195+
@SerializedName("file_name")
196+
private String fileName;
197+
198+
/**
199+
* 文件内容(base64编码),所有附件加正文的大小不允许超过50M, 且附件个数不能超过200个
200+
*/
201+
@SerializedName("content")
202+
private String content;
203+
204+
/**
205+
* From json space info.
206+
*
207+
* @param json the json
208+
* @return the space info
209+
*/
210+
public static WxCpMailCommonSendRequest.Attachment fromJson(String json) {
211+
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.Attachment.class);
212+
}
213+
214+
/**
215+
* To json string.
216+
*
217+
* @return the string
218+
*/
219+
public String toJson() {
220+
return WxCpGsonBuilder.create().toJson(this);
221+
}
222+
223+
}
224+
225+
/**
226+
* From json wx cp space create request.
227+
*
228+
* @param json the json
229+
* @return the wx cp space create request
230+
*/
231+
public static WxCpMailCommonSendRequest fromJson(String json) {
232+
return WxCpGsonBuilder.create().fromJson(json, WxCpMailCommonSendRequest.class);
233+
}
234+
235+
/**
236+
* To json string.
237+
*
238+
* @return the string
239+
*/
240+
public String toJson() {
241+
return WxCpGsonBuilder.create().toJson(this);
242+
}
243+
244+
}

0 commit comments

Comments
 (0)