Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

【公众号】客服消息增加草稿箱图文消息类型mpnewsarticle #2476

Merged
merged 2 commits into from
Dec 31, 2021
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 @@ -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\"}}");
}

}