mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-11-01 00:46:54 +08:00 
			
		
		
		
	🎨 #2476【公众号】客服消息增加草稿箱图文消息类型
This commit is contained in:
		| @@ -37,6 +37,7 @@ public class WxMpKefuMessage implements Serializable { | ||||
|   private String headContent; | ||||
|   private String tailContent; | ||||
|   private List<WxArticle> articles = new ArrayList<>(); | ||||
|   private String mpNewsArticleId; | ||||
|  | ||||
|   /** | ||||
|    * 菜单消息里的菜单内容. | ||||
| @@ -113,6 +114,13 @@ public class WxMpKefuMessage implements Serializable { | ||||
|     return new MiniProgramPageBuilder(); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * 发送图文消息(点击跳转到图文消息页面)使用通过 “发布” 系列接口得到的 article_id(草稿箱功能上线后不再支持客服接口中带 media_id 的 mpnews 类型的图文消息) | ||||
|    */ | ||||
|   public static MpNewsArticleBuilder MPNEWSARTICLE() { | ||||
|     return new MpNewsArticleBuilder(); | ||||
|   } | ||||
|  | ||||
|   /** | ||||
|    * <pre> | ||||
|    * 请使用 | ||||
| @@ -127,6 +135,7 @@ public class WxMpKefuMessage implements Serializable { | ||||
|    * {@link WxConsts.KefuMsgType#MINIPROGRAMPAGE} | ||||
|    * {@link WxConsts.KefuMsgType#TASKCARD} | ||||
|    * {@link WxConsts.KefuMsgType#MSGMENU} | ||||
|    * {@link WxConsts.KefuMsgType#MP_NEWS_ARTICLE} | ||||
|    * </pre> | ||||
|    */ | ||||
|   public void setMsgType(String msgType) { | ||||
|   | ||||
| @@ -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; | ||||
|   } | ||||
| } | ||||
| @@ -96,6 +96,11 @@ public class WxMpKefuMessageGsonAdapter implements JsonSerializer<WxMpKefuMessag | ||||
|           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("非法消息类型,暂不支持"); | ||||
|       } | ||||
|   | ||||
| @@ -166,4 +166,13 @@ public class WxMpKefuMessageTest { | ||||
|       "{\"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\"}}"); | ||||
|   } | ||||
|  | ||||
| } | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 JCLee
					JCLee