mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-05-04 04:37:46 +08:00
🎨 【企业微信】添加AttachmentBuilder,可以更方便的创建新客户欢迎语的附件信息
This commit is contained in:
parent
722c2cfe2b
commit
6e96d7cf55
@ -34,9 +34,10 @@ public class Attachment implements Serializable {
|
||||
*
|
||||
* @param image the image
|
||||
*/
|
||||
public void setImage(Image image) {
|
||||
public Attachment setImage(Image image) {
|
||||
this.image = image;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.IMAGE;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -44,9 +45,10 @@ public class Attachment implements Serializable {
|
||||
*
|
||||
* @param link the link
|
||||
*/
|
||||
public void setLink(Link link) {
|
||||
public Attachment setLink(Link link) {
|
||||
this.link = link;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.LINK;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -54,9 +56,10 @@ public class Attachment implements Serializable {
|
||||
*
|
||||
* @param miniProgram the mini program
|
||||
*/
|
||||
public void setMiniProgram(MiniProgram miniProgram) {
|
||||
public Attachment setMiniProgram(MiniProgram miniProgram) {
|
||||
this.miniProgram = miniProgram;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.MINIPROGRAM;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -64,9 +67,10 @@ public class Attachment implements Serializable {
|
||||
*
|
||||
* @param video the video
|
||||
*/
|
||||
public void setVideo(Video video) {
|
||||
public Attachment setVideo(Video video) {
|
||||
this.video = video;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.VIDEO;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -74,8 +78,9 @@ public class Attachment implements Serializable {
|
||||
*
|
||||
* @param file the file
|
||||
*/
|
||||
public void setFile(File file) {
|
||||
public Attachment setFile(File file) {
|
||||
this.file = file;
|
||||
this.msgType = WxCpConsts.WelcomeMsgType.FILE;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
40
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/AttachmentBuilder.java
vendored
Normal file
40
weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/msg/AttachmentBuilder.java
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import lombok.Builder;
|
||||
|
||||
/**
|
||||
* @author codecrab
|
||||
*/
|
||||
public class AttachmentBuilder {
|
||||
|
||||
@Builder(builderClassName = "ImageBuilder", builderMethodName = "imageBuilder")
|
||||
private static Attachment image(String mediaId, String picUrl) {
|
||||
Image image = new Image().setMediaId(mediaId).setPicUrl(picUrl);
|
||||
return new Attachment().setImage(image);
|
||||
}
|
||||
|
||||
@Builder(builderClassName = "VideoBuilder", builderMethodName = "videoBuilder")
|
||||
private static Attachment video(String mediaId) {
|
||||
Video video = new Video().setMediaId(mediaId);
|
||||
return new Attachment().setVideo(video);
|
||||
}
|
||||
|
||||
@Builder(builderClassName = "FileBuilder", builderMethodName = "fileBuilder")
|
||||
private static Attachment file(String mediaId) {
|
||||
File file = new File().setMediaId(mediaId);
|
||||
return new Attachment().setFile(file);
|
||||
}
|
||||
|
||||
@Builder(builderClassName = "LinkBuilder", builderMethodName = "linkBuilder")
|
||||
private static Attachment link(String title, String url, String picUrl, String desc) {
|
||||
Link link = new Link().setTitle(title).setPicUrl(picUrl).setUrl(url).setDesc(desc);
|
||||
return new Attachment().setLink(link);
|
||||
}
|
||||
|
||||
@Builder(builderClassName = "MiniProgramBuilder", builderMethodName = "miniProgramBuilder")
|
||||
private static Attachment miniProgram(String title, String picMediaId, String appId, String page) {
|
||||
MiniProgram miniProgram = new MiniProgram().setTitle(title).setPicMediaId(picMediaId).setAppid(appId).setPage(page);
|
||||
return new Attachment().setMiniProgram(miniProgram);
|
||||
}
|
||||
|
||||
}
|
@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.io.Serializable;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> created on 2021-08-23
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class File implements Serializable {
|
||||
private static final long serialVersionUID = 2794189478198329090L;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.io.Serializable;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> created on 2020-08-16
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Image implements Serializable {
|
||||
private static final long serialVersionUID = -606286372867787121L;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.io.Serializable;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> created on 2020-08-16
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Link implements Serializable {
|
||||
private static final long serialVersionUID = -8041816740881163875L;
|
||||
private String title;
|
||||
|
@ -1,6 +1,7 @@
|
||||
package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
/**
|
||||
* 地理位置
|
||||
@ -8,6 +9,7 @@ import lombok.Data;
|
||||
* @author leiin created on 2021-10-29
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Location {
|
||||
private String latitude;
|
||||
private String longitude;
|
||||
|
@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.io.Serializable;
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a> created on 2020-08-16
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class MiniProgram implements Serializable {
|
||||
private static final long serialVersionUID = 4242074162638170679L;
|
||||
|
||||
|
@ -2,6 +2,7 @@ package me.chanjar.weixin.cp.bean.external.msg;
|
||||
|
||||
import com.google.gson.annotations.SerializedName;
|
||||
import lombok.Data;
|
||||
import lombok.experimental.Accessors;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@ -11,6 +12,7 @@ import java.io.Serializable;
|
||||
* @author pg created on 2021-6-21
|
||||
*/
|
||||
@Data
|
||||
@Accessors(chain = true)
|
||||
public class Video implements Serializable {
|
||||
private static final long serialVersionUID = -6048642921382867138L;
|
||||
@SerializedName("media_id")
|
||||
|
@ -10,6 +10,7 @@ import me.chanjar.weixin.cp.bean.external.*;
|
||||
import me.chanjar.weixin.cp.bean.external.contact.WxCpExternalContactBatchInfo;
|
||||
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.AttachmentBuilder;
|
||||
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;
|
||||
@ -17,7 +18,10 @@ import org.testng.annotations.Guice;
|
||||
import org.testng.annotations.Test;
|
||||
import org.testng.collections.CollectionUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import static org.testng.Assert.assertNotNull;
|
||||
|
||||
@ -419,6 +423,7 @@ public class WxCpExternalContactServiceImplTest {
|
||||
System.out.println(result);
|
||||
assertNotNull(result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test get user behavior statistic.
|
||||
*/
|
||||
@ -466,6 +471,33 @@ public class WxCpExternalContactServiceImplTest {
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test send welcome msg. use AttachmentBuilder
|
||||
*
|
||||
* @throws WxErrorException the wx error exception
|
||||
*/
|
||||
@Test
|
||||
public void testSendWelcomeMsg2() throws WxErrorException {
|
||||
|
||||
Attachment imageAttachment = AttachmentBuilder.imageBuilder().mediaId("123123").build();
|
||||
Attachment videoAttachment = AttachmentBuilder.videoBuilder().mediaId("video_media_id").build();
|
||||
Attachment miniProgramAttachment = AttachmentBuilder.miniProgramBuilder()
|
||||
.title("title")
|
||||
.picMediaId("123123123")
|
||||
.appId("wxcxxxxxxxxxxx")
|
||||
.page("https://")
|
||||
.build();
|
||||
|
||||
List<Attachment> attachments = new ArrayList<>();
|
||||
attachments.add(imageAttachment);
|
||||
attachments.add(videoAttachment);
|
||||
attachments.add(miniProgramAttachment);
|
||||
this.wxCpService.getExternalContactService().sendWelcomeMsg(WxCpWelcomeMsg.builder()
|
||||
.welcomeCode("abc")
|
||||
.attachments(attachments)
|
||||
.build());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test update remark.
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user