🎨 #2155 【企业微信】发送新客户欢迎语接口增加对视频类型的支持,同时修复结构不正确的问题
This commit is contained in:
@@ -2,13 +2,11 @@ package me.chanjar.weixin.cp.bean.external;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.*;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.Image;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.Link;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.MiniProgram;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.Text;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.*;
|
||||
import me.chanjar.weixin.cp.util.json.WxCpGsonBuilder;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 新客户欢迎语.
|
||||
@@ -28,11 +26,7 @@ public class WxCpWelcomeMsg implements Serializable {
|
||||
|
||||
private Text text;
|
||||
|
||||
private Image image;
|
||||
|
||||
private Link link;
|
||||
|
||||
private MiniProgram miniprogram;
|
||||
private List<Attachment> attachments;
|
||||
|
||||
public String toJson() {
|
||||
return WxCpGsonBuilder.create().toJson(this);
|
||||
|
||||
76
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Attachment.java
vendored
Normal file
76
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Attachment.java
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import me.chanjar.weixin.cp.constant.WxCpConsts;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
public class Attachment implements Serializable {
|
||||
private static final long serialVersionUID = -8078748379570640198L;
|
||||
|
||||
@SerializedName("msgtype")
|
||||
private String msgType;
|
||||
|
||||
private Image image;
|
||||
|
||||
private Link link;
|
||||
|
||||
private MiniProgram miniprogram;
|
||||
|
||||
private Video video;
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Attachment{" +
|
||||
"msgType='" + msgType + '\'' +
|
||||
", image=" + image +
|
||||
", link=" + link +
|
||||
", miniprogram=" + miniprogram +
|
||||
", video=" + video +
|
||||
'}';
|
||||
}
|
||||
|
||||
private String getMsgType() {
|
||||
return msgType;
|
||||
}
|
||||
|
||||
private void setMsgType(String msgType) {
|
||||
this.msgType = msgType;
|
||||
}
|
||||
|
||||
public Image getImage() {
|
||||
return image;
|
||||
}
|
||||
|
||||
public void setImage(Image image) {
|
||||
this.image = image;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.IMAGE;
|
||||
}
|
||||
|
||||
public Link getLink() {
|
||||
return link;
|
||||
}
|
||||
|
||||
public void setLink(Link link) {
|
||||
this.link = link;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.LINK;
|
||||
}
|
||||
|
||||
public MiniProgram getMiniprogram() {
|
||||
return miniprogram;
|
||||
}
|
||||
|
||||
public void setMiniprogram(MiniProgram miniprogram) {
|
||||
this.miniprogram = miniprogram;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.MINIPROGRAM;
|
||||
}
|
||||
|
||||
public Video getVideo() {
|
||||
return video;
|
||||
}
|
||||
|
||||
public void setVideo(Video video) {
|
||||
this.video = video;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.VIDEO;
|
||||
}
|
||||
}
|
||||
19
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Video.java
vendored
Normal file
19
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/Video.java
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* 视频消息
|
||||
*
|
||||
* @author pg
|
||||
* @date 2021-6-21
|
||||
*/
|
||||
@Data
|
||||
public class Video implements Serializable {
|
||||
private static final long serialVersionUID = -6048642921382867138L;
|
||||
@SerializedName("media_id")
|
||||
private String mediaId;
|
||||
}
|
||||
@@ -334,4 +334,24 @@ public class WxCpConsts {
|
||||
* */
|
||||
public static final String WEBVIEW = "webview";
|
||||
}
|
||||
|
||||
@UtilityClass
|
||||
public static class WelcomeMsgType {
|
||||
/**
|
||||
* 图片消息.
|
||||
*/
|
||||
public static final String IMAGE = "image";
|
||||
/**
|
||||
* 图文消息.
|
||||
*/
|
||||
public static final String LINK = "link";
|
||||
/**
|
||||
* 视频消息.
|
||||
*/
|
||||
public static final String VIDEO = "video";
|
||||
/**
|
||||
* 小程序消息.
|
||||
*/
|
||||
public static final String MINIPROGRAM = "miniprogram";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,9 @@ import me.chanjar.weixin.cp.api.WxCpService;
|
||||
import me.chanjar.weixin.cp.bean.WxCpBaseResp;
|
||||
import me.chanjar.weixin.cp.bean.external.*;
|
||||
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactInfo;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.Attachment;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.Image;
|
||||
import me.chanjar.weixin.cp.bean.external.msg.Video;
|
||||
import org.apache.commons.lang3.time.DateFormatUtils;
|
||||
import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
@@ -214,8 +217,22 @@ public class WxCpExternalContactServiceImplTest {
|
||||
|
||||
@Test
|
||||
public void testSendWelcomeMsg() throws WxErrorException {
|
||||
Image image = new Image();
|
||||
image.setMediaId("123123");
|
||||
Attachment attachment = new Attachment();
|
||||
attachment.setImage(image);
|
||||
|
||||
Video video = new Video();
|
||||
video.setMediaId("video_media_id");
|
||||
Attachment attachment2 = new Attachment();
|
||||
attachment2.setVideo(video);
|
||||
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
attachments.add(attachment);
|
||||
attachments.add(attachment2);
|
||||
this.wxCpService.getExternalContactService().sendWelcomeMsg(WxCpWelcomeMsg.builder()
|
||||
.welcomeCode("abc")
|
||||
.attachments(attachments)
|
||||
.build());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user