Skip to content

Commit

Permalink
🎨 #2476【公众号】客服消息增加草稿箱图文消息类型
Browse files Browse the repository at this point in the history
  • Loading branch information
leejuncheng authored Dec 31, 2021
1 parent a647fe8 commit fd8e02a
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ public static class KefuMsgType {
* 模板卡片消息.
*/
public static final String TEMPLATE_CARD = "template_card";

/**
* 发送图文消息(点击跳转到图文消息页面)使用通过 “发布” 系列接口得到的 article_id(草稿箱功能上线后不再支持客服接口中带 media_id 的 mpnews 类型的图文消息)
*/
public static final String MP_NEWS_ARTICLE = "mpnewsarticle";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class WxMpKefuMessage implements Serializable {
private String headContent;
private String tailContent;
private List<WxArticle> articles = new ArrayList<>();
private String mpNewsArticleId;

/**
* 菜单消息里的菜单内容.
Expand Down Expand Up @@ -113,6 +114,13 @@ public static MiniProgramPageBuilder MINIPROGRAMPAGE() {
return new MiniProgramPageBuilder();
}

/**
* 发送图文消息(点击跳转到图文消息页面)使用通过 “发布” 系列接口得到的 article_id(草稿箱功能上线后不再支持客服接口中带 media_id 的 mpnews 类型的图文消息)
*/
public static MpNewsArticleBuilder MPNEWSARTICLE() {
return new MpNewsArticleBuilder();
}

/**
* <pre>
* 请使用
Expand All @@ -127,6 +135,7 @@ public static MiniProgramPageBuilder MINIPROGRAMPAGE() {
* {@link WxConsts.KefuMsgType#MINIPROGRAMPAGE}
* {@link WxConsts.KefuMsgType#TASKCARD}
* {@link WxConsts.KefuMsgType#MSGMENU}
* {@link WxConsts.KefuMsgType#MP_NEWS_ARTICLE}
* </pre>
*/
public void setMsgType(String msgType) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package me.chanjar.weixin.mp.builder.kefu;

import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;

/**
* 图文消息builder
* <pre>
* 用法:
* WxMpKefuMessage m = WxMpKefuMessage.MPNEWSARTICLE().articleId("xxxxx").toUser(...).build();
* </pre>
*
* @author <a href="https://github.com/leejuncheng">JCLee</a>
*/
public final class MpNewsArticleBuilder extends BaseBuilder<MpNewsArticleBuilder>{
private String articleId;

public MpNewsArticleBuilder() {
this.msgType = WxConsts.KefuMsgType.MP_NEWS_ARTICLE;
}

public MpNewsArticleBuilder articleId(String articleId) {
this.articleId = articleId;
return this;
}

@Override
public WxMpKefuMessage build() {
WxMpKefuMessage m = super.build();
m.setMpNewsArticleId(this.articleId);
return m;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public JsonElement serialize(WxMpKefuMessage message, Type typeOfSrc, JsonSerial
messageJson.add("msgmenu", msgmenuJsonObject);
break;
}
case KefuMsgType.MP_NEWS_ARTICLE:
JsonObject mpNewsArticleJson = new JsonObject();
mpNewsArticleJson.addProperty("article_id", message.getMpNewsArticleId());
messageJson.add("mpnewsarticle", mpNewsArticleJson);
break;
default: {
throw new WxRuntimeException("非法消息类型,暂不支持");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,13 @@ public void testMsgMenuBuild() {
"{\"touser\":\"OPENID\",\"msgtype\":\"msgmenu\",\"msgmenu\":{\"head_content\":\"head_content\",\"list\":[{\"id\":\"101\",\"content\":\"msgmenu1\"},{\"id\":\"102\",\"content\":\"msgmenu2\"}],\"tail_content\":\"tail_content\"}}");
}

public void testMpNewsArticleBuilder() {
WxMpKefuMessage reply = WxMpKefuMessage.MPNEWSARTICLE()
.toUser("OPENID")
.articleId("ARTICLE_ID")
.build();
Assert.assertEquals(reply.toJson(),
"{\"touser\":\"OPENID\",\"msgtype\":\"mpnewsarticle\",\"mpnewsarticle\":{\"article_id\":\"ARTICLE_ID\"}}");
}

}

0 comments on commit fd8e02a

Please sign in to comment.