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 Jun 7, 2022
·
11 revisions
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder()
.toUser(...)
.templateId(...)
.url(...)
.build();
templateMessage.addData(new WxMpTemplateData(name1, value1, color2));
templateMessage.addData(new WxMpTemplateData(name2, value2, color2));
wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
更详细的使用方法请参考单元测试代码:
/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImplTest.java
或者参考在线的javadoc: http://binary.ac.cn/weixin-java-mp-javadoc/me/chanjar/weixin/mp/api/impl/WxMpTemplateMsgServiceImpl.html
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)) { //appid // throw new IllegalArgumentException(String.format("未找到对应appid=[%s]的配置,请核实!", appid)); // }
if (!wxMpService.checkSignature(timestamp, nonce, signature)) {
throw new IllegalArgumentException("非法请求,可能属于伪造的请求!");
}
return ResponseEntity.ok("");