Skip to content

Commit d6d3625

Browse files
chutian0124hywr
authored andcommitted
🎨 binarywang#2155 【企业微信】发送新客户欢迎语接口增加对视频类型的支持,同时修复结构不正确的问题
1 parent d1e8fe3 commit d6d3625

File tree

5 files changed

+135
-9
lines changed

5 files changed

+135
-9
lines changed

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/WxCpWelcomeMsg.java

+3-9
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,11 @@
22

33
import com.google.gson.annotations.SerializedName;
44
import lombok.*;
5-
import me.chanjar.weixin.cp.bean.external.msg.Image;
6-
import me.chanjar.weixin.cp.bean.external.msg.Link;
7-
import me.chanjar.weixin.cp.bean.external.msg.MiniProgram;
8-
import me.chanjar.weixin.cp.bean.external.msg.Text;
5+
import me.chanjar.weixin.cp.bean.external.msg.*;
96
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
107

118
import java.io.Serializable;
9+
import java.util.List;
1210

1311
/**
1412
* 新客户欢迎语.
@@ -28,11 +26,7 @@ public class WxCpWelcomeMsg implements Serializable {
2826

2927
private Text text;
3028

31-
private Image image;
32-
33-
private Link link;
34-
35-
private MiniProgram miniprogram;
29+
private List<Attachment> attachments;
3630

3731
public String toJson() {
3832
return WxCpGsonBuilder.create().toJson(this);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
package me.chanjar.weixin.cp.bean.external.msg;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import me.chanjar.weixin.cp.constant.WxCpConsts;
5+
6+
import java.io.Serializable;
7+
8+
public class Attachment implements Serializable {
9+
private static final long serialVersionUID = -8078748379570640198L;
10+
11+
@SerializedName("msgtype")
12+
private String msgType;
13+
14+
private Image image;
15+
16+
private Link link;
17+
18+
private MiniProgram miniprogram;
19+
20+
private Video video;
21+
22+
@Override
23+
public String toString() {
24+
return "Attachment{" +
25+
"msgType='" + msgType + '\'' +
26+
", image=" + image +
27+
", link=" + link +
28+
", miniprogram=" + miniprogram +
29+
", video=" + video +
30+
'}';
31+
}
32+
33+
private String getMsgType() {
34+
return msgType;
35+
}
36+
37+
private void setMsgType(String msgType) {
38+
this.msgType = msgType;
39+
}
40+
41+
public Image getImage() {
42+
return image;
43+
}
44+
45+
public void setImage(Image image) {
46+
this.image = image;
47+
this.msgType = WxCpConsts.WelcomeMsgType.IMAGE;
48+
}
49+
50+
public Link getLink() {
51+
return link;
52+
}
53+
54+
public void setLink(Link link) {
55+
this.link = link;
56+
this.msgType = WxCpConsts.WelcomeMsgType.LINK;
57+
}
58+
59+
public MiniProgram getMiniprogram() {
60+
return miniprogram;
61+
}
62+
63+
public void setMiniprogram(MiniProgram miniprogram) {
64+
this.miniprogram = miniprogram;
65+
this.msgType = WxCpConsts.WelcomeMsgType.MINIPROGRAM;
66+
}
67+
68+
public Video getVideo() {
69+
return video;
70+
}
71+
72+
public void setVideo(Video video) {
73+
this.video = video;
74+
this.msgType = WxCpConsts.WelcomeMsgType.VIDEO;
75+
}
76+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package me.chanjar.weixin.cp.bean.external.msg;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.Data;
5+
6+
import java.io.Serializable;
7+
8+
/**
9+
* 视频消息
10+
*
11+
* @author pg
12+
* @date 2021-6-21
13+
*/
14+
@Data
15+
public class Video implements Serializable {
16+
private static final long serialVersionUID = -6048642921382867138L;
17+
@SerializedName("media_id")
18+
private String mediaId;
19+
}

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

+20
Original file line numberDiff line numberDiff line change
@@ -334,4 +334,24 @@ public static class WorkBenchType {
334334
* */
335335
public static final String WEBVIEW = "webview";
336336
}
337+
338+
@UtilityClass
339+
public static class WelcomeMsgType {
340+
/**
341+
* 图片消息.
342+
*/
343+
public static final String IMAGE = "image";
344+
/**
345+
* 图文消息.
346+
*/
347+
public static final String LINK = "link";
348+
/**
349+
* 视频消息.
350+
*/
351+
public static final String VIDEO = "video";
352+
/**
353+
* 小程序消息.
354+
*/
355+
public static final String MINIPROGRAM = "miniprogram";
356+
}
337357
}

weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpExternalContactServiceImplTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
99
import me.chanjar.weixin.cp.bean.external.*;
1010
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
11+
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
12+
import me.chanjar.weixin.cp.bean.external.msg.Image;
13+
import me.chanjar.weixin.cp.bean.external.msg.Video;
1114
import org.apache.commons.lang3.time.DateFormatUtils;
1215
import org.testng.annotations.Guice;
1316
import org.testng.annotations.Test;
@@ -214,8 +217,22 @@ public void testAddMsgTemplate() {
214217

215218
@Test
216219
public void testSendWelcomeMsg() throws WxErrorException {
220+
Image image = new Image();
221+
image.setMediaId("123123");
222+
Attachment attachment = new Attachment();
223+
attachment.setImage(image);
224+
225+
Video video = new Video();
226+
video.setMediaId("video_media_id");
227+
Attachment attachment2 = new Attachment();
228+
attachment2.setVideo(video);
229+
230+
List<Attachment> attachments = new ArrayList<>();
231+
attachments.add(attachment);
232+
attachments.add(attachment2);
217233
this.wxCpService.getExternalContactService().sendWelcomeMsg(WxCpWelcomeMsg.builder()
218234
.welcomeCode("abc")
235+
.attachments(attachments)
219236
.build());
220237
}
221238

0 commit comments

Comments
 (0)