mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-09-20 10:38:13 +08:00
优化模版消息代码,添加默认构造方法
This commit is contained in:
@@ -1,24 +1,28 @@
|
||||
package cn.binarywang.wx.miniapp.bean;
|
||||
|
||||
import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
import lombok.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 模板消息.
|
||||
* 参考 https://mp.weixin.qq.com/debug/wxadoc/dev/api/notice.html#接口说明 模板消息部分
|
||||
*
|
||||
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||
*/
|
||||
@Data
|
||||
@Getter
|
||||
@Setter
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@Builder
|
||||
public class WxMaTemplateMessage implements Serializable {
|
||||
private static final long serialVersionUID = 5063374783759519418L;
|
||||
|
||||
/**
|
||||
* 接收者(用户)的 openid.
|
||||
* <pre>
|
||||
* 参数:touser
|
||||
* 是否必填: 是
|
||||
@@ -28,6 +32,7 @@ public class WxMaTemplateMessage implements Serializable {
|
||||
private String toUser;
|
||||
|
||||
/**
|
||||
* 所需下发的模板消息的id.
|
||||
* <pre>
|
||||
* 参数:template_id
|
||||
* 是否必填: 是
|
||||
@@ -37,6 +42,7 @@ public class WxMaTemplateMessage implements Serializable {
|
||||
private String templateId;
|
||||
|
||||
/**
|
||||
* 点击模板卡片后的跳转页面,仅限本小程序内的页面.
|
||||
* <pre>
|
||||
* 参数:page
|
||||
* 是否必填: 否
|
||||
@@ -46,6 +52,7 @@ public class WxMaTemplateMessage implements Serializable {
|
||||
private String page;
|
||||
|
||||
/**
|
||||
* 表单提交场景下,为 submit 事件带上的 formId;支付场景下,为本次支付的 prepay_id.
|
||||
* <pre>
|
||||
* 参数:form_id
|
||||
* 是否必填: 是
|
||||
@@ -55,16 +62,17 @@ public class WxMaTemplateMessage implements Serializable {
|
||||
private String formId;
|
||||
|
||||
/**
|
||||
* 模板内容,不填则下发空模板.
|
||||
* <pre>
|
||||
* 参数:data
|
||||
* 是否必填: 是
|
||||
* 描述: 模板内容,不填则下发空模板
|
||||
* </pre>
|
||||
*/
|
||||
@Builder.Default
|
||||
private final List<Data> data = new ArrayList<>();
|
||||
private List<Data> data;
|
||||
|
||||
/**
|
||||
* 模板内容字体的颜色,不填默认黑色.
|
||||
* <pre>
|
||||
* 参数:color
|
||||
* 是否必填: 否
|
||||
@@ -74,6 +82,7 @@ public class WxMaTemplateMessage implements Serializable {
|
||||
private String color;
|
||||
|
||||
/**
|
||||
* 模板需要放大的关键词,不填则默认无放大.
|
||||
* <pre>
|
||||
* 参数:emphasis_keyword
|
||||
* 是否必填: 否
|
||||
@@ -82,6 +91,15 @@ public class WxMaTemplateMessage implements Serializable {
|
||||
*/
|
||||
private String emphasisKeyword;
|
||||
|
||||
public WxMaTemplateMessage addData(Data datum) {
|
||||
if (this.data == null) {
|
||||
this.data = new ArrayList<>();
|
||||
}
|
||||
this.data.add(datum);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return WxMaGsonBuilder.create().toJson(this);
|
||||
}
|
||||
|
@@ -66,7 +66,7 @@ public class WxMaMsgServiceImplTest {
|
||||
.templateId(config.getTemplateId())
|
||||
.emphasisKeyword("keyword1.DATA")
|
||||
.build();
|
||||
|
||||
//templateMessage.addData( new WxMaTemplateMessage.Data("keyword1", "339208499", "#173177"));
|
||||
this.wxService.getMsgService().sendTemplateMsg(templateMessage);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user