Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 #2155 【企业微信】发送新客户欢迎语接口增加对视频类型的支持,同时修复结构不正确的问题 #3

Merged
merged 1 commit into from
Jun 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

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;

/**
* 新客户欢迎语.
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -334,4 +334,24 @@ public static class WorkBenchType {
* */
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";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
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;
Expand Down Expand Up @@ -214,8 +217,22 @@ public void testAddMsgTemplate() {

@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());
}

Expand Down