Skip to content

MP_主动发送消息(客服消息)

Binary Wang edited this page Dec 2, 2016 · 4 revisions

更多用例,请参考me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImplTest

WxMpKefuMessage message = ...;
// 设置消息的内容等信息
wxMpService.getKefuService().sendKefuMessage(message);

WxXmlOutTextMessage

不同类型的客服消息有不同的构造方法:

文本消息

WxMpKefuMessage
  .TEXT()
  .toUser("OPENID")
  .content("sfsfdsdf")
  .build();

图片消息

WxMpKefuMessage
  .IMAGE()
  .toUser("OPENID")
  .mediaId("MEDIA_ID")
  .build();

语音消息

WxMpKefuMessage.VOICE()
  .toUser("OPENID")
  .mediaId("MEDIA_ID")
  .build();

视频消息

WxMpKefuMessage.VIDEO()
  .toUser("OPENID")
  .title("TITLE")
  .mediaId("MEDIA_ID")
  .thumbMediaId("MEDIA_ID")
  .description("DESCRIPTION")
  .build();

音乐消息

WxMpKefuMessage.MUSIC()
  .toUser("OPENID")
  .title("TITLE")
  .thumbMediaId("MEDIA_ID")
  .description("DESCRIPTION")
  .musicUrl("MUSIC_URL")
  .hqMusicUrl("HQ_MUSIC_URL")
  .build();

图文消息

WxMpKefuMessage.WxArticle article1 = new WxMpKefuMessage.WxArticle();
article1.setUrl("URL");
article1.setPicUrl("PIC_URL");
article1.setDescription("Is Really A Happy Day");
article1.setTitle("Happy Day");

WxMpKefuMessage.WxArticle article2 = new WxMpKefuMessage.WxArticle();
article2.setUrl("URL");
article2.setPicUrl("PIC_URL");
article2.setDescription("Is Really A Happy Day");
article2.setTitle("Happy Day");

WxMpKefuMessage.NEWS()
    .toUser("OPENID")
    .addArticle(article1)
    .addArticle(article2)
    .build();
Clone this wiki locally