Skip to content

Commit

Permalink
🎨 binarywang#2155 【企业微信】发送新客户欢迎语接口增加对视频类型的支持,同时修复结构不正确的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
chutian0124 authored and hywr committed Jun 23, 2021
1 parent d1e8fe3 commit d6d3625
Show file tree
Hide file tree
Showing 5 changed files with 135 additions and 9 deletions.
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

0 comments on commit d6d3625

Please sign in to comment.