Skip to content
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 @@ -30,6 +30,7 @@ public class WxConsts {
public static final String CUSTOM_MSG_MUSIC = "music";
public static final String CUSTOM_MSG_NEWS = "news";
public static final String CUSTOM_MSG_FILE = "file";
public static final String CUSTOM_MSG_WXCARD = "wxcard";
public static final String CUSTOM_MSG_TRANSFER_CUSTOMER_SERVICE = "transfer_customer_service";
public static final String CUSTOM_MSG_SAFE_NO = "0";
public static final String CUSTOM_MSG_SAFE_YES = "1";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/
public class WxMpCustomMessage implements Serializable {
private static final long serialVersionUID = -9196732086954365246L;

private String toUser;
private String msgType;
private String content;
Expand All @@ -25,8 +25,9 @@ public class WxMpCustomMessage implements Serializable {
private String musicUrl;
private String hqMusicUrl;
private String kfAccount;
private String cardId;
private List<WxArticle> articles = new ArrayList<>();

public String getToUser() {
return this.toUser;
}
Expand All @@ -36,7 +37,7 @@ public void setToUser(String toUser) {
public String getMsgType() {
return this.msgType;
}

/**
* <pre>
* 请使用
Expand All @@ -46,6 +47,7 @@ public String getMsgType() {
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_MUSIC}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_VIDEO}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_NEWS}
* {@link me.chanjar.weixin.common.api.WxConsts#CUSTOM_MSG_WXCARD}
* </pre>
* @param msgType
*/
Expand Down Expand Up @@ -94,24 +96,33 @@ public String getHqMusicUrl() {
public void setHqMusicUrl(String hqMusicUrl) {
this.hqMusicUrl = hqMusicUrl;
}

public String getCardId() {
return cardId;
}

public void setCardId(String cardId) {
this.cardId = cardId;
}

public List<WxArticle> getArticles() {
return this.articles;
}
public void setArticles(List<WxArticle> articles) {
this.articles = articles;
}

public String toJson() {
return WxMpGsonBuilder.INSTANCE.create().toJson(this);
}

public static class WxArticle {

private String title;
private String description;
private String url;
private String picUrl;

public String getTitle() {
return this.title;
}
Expand All @@ -136,9 +147,9 @@ public String getPicUrl() {
public void setPicUrl(String picUrl) {
this.picUrl = picUrl;
}

}

/**
* 获得文本消息builder
*/
Expand All @@ -159,34 +170,42 @@ public static ImageBuilder IMAGE() {
public static VoiceBuilder VOICE() {
return new VoiceBuilder();
}

/**
* 获得视频消息builder
*/
public static VideoBuilder VIDEO() {
return new VideoBuilder();
}

/**
* 获得音乐消息builder
*/
public static MusicBuilder MUSIC() {
return new MusicBuilder();
}

/**
* 获得图文消息builder
*/
public static NewsBuilder NEWS() {
return new NewsBuilder();
}



/**
* 获得卡券消息builder
* @return

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

感谢提交PR,不过javadoc能规范下吗?比如这里,return 后面最好加上注释,否则打包生成javadoc时会有警告产生

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

我再交一个pr

*/
public static WxCardBuilder WXCARD() {
return new WxCardBuilder();
}

public String getKfAccount() {
return this.kfAccount;
}

public void setKfAccount(String kfAccount) {
this.kfAccount = kfAccount;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package me.chanjar.weixin.mp.bean.custombuilder;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.bean.WxMpCustomMessage;

/**
* 卡券消息builder
* <pre>
* 用法: WxMpCustomMessage m = WxMpCustomMessage.WXCARD().cardId(...).toUser(...).build();
* </pre>
* @author mgcnrx11
*
*/
public final class WxCardBuilder extends BaseBuilder<WxCardBuilder> {
private String cardId;

public WxCardBuilder() {
this.msgType = WxConsts.CUSTOM_MSG_WXCARD;
}

public WxCardBuilder cardId(String cardId) {
this.cardId = cardId;
return this;
}

public WxMpCustomMessage build() {
WxMpCustomMessage m = super.build();
m.setCardId(this.cardId);
return m;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ public JsonElement serialize(WxMpCustomMessage message, Type typeOfSrc, JsonSeri
newsJsonObject.add("articles", articleJsonArray);
messageJson.add("news", newsJsonObject);
}

if (WxConsts.CUSTOM_MSG_WXCARD.equals(message.getMsgType())) {
JsonObject wxcard = new JsonObject();
wxcard.addProperty("card_id", message.getCardId());
messageJson.add("wxcard", wxcard);
}

if (StringUtils.isNotBlank(message.getKfAccount())){
JsonObject newsJsonObject = new JsonObject();
Expand Down