forked from chanjarster/weixin-java-tools
-
-
Notifications
You must be signed in to change notification settings - Fork 8.5k
MP_主动发送消息(客服消息)
Binary Wang edited this page Dec 2, 2016
·
4 revisions
更多用例,请参考me.chanjar.weixin.mp.api.impl.WxMpKefuServiceImplTest
WxMpKefuMessage message = ...;
// 设置消息的内容等信息
wxMpService.getKefuService().sendKefuMessage(message);
不同类型的客服消息有不同的构造方法:
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();
String encType = request.getParameter("encrypt_type");
String nonce = request.getParameter("nonce");
String timestamp = request.getParameter("timestamp");
String msgSignature = request.getParameter("msg_signature");
String signature = request.getParameter("signature");
String openid = request.getParameter("openid");
log.info("接收微信请求:[openid=[{}], [openid=[{}],[signature=[{}], encType=[{}], msgSignature=[{}],"
+ " timestamp=[{}], nonce=[{}], requestBody=[{}] ",
appid, openid, signature, encType, msgSignature, timestamp, nonce, requestBody);
if (!this.wxMpService.switchover(appid)) {
throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid));
}
if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
}
return ResponseEntity.ok("");