我是靠谱客的博主 直率舞蹈,这篇文章主要介绍微信订阅消息推送(记录),现在分享给大家,希望可以做个参考。

1.打开微信公众平台,选用订阅消息模板(可在公共库选用,也可自己申请:审核时间3-7天);

2.打开微信官方文档,了解订阅消息的方法subscribeMessage.send | 微信开放文档

3.建实体类:

接收者(用户)的openid
所需下发的模板消息的id

模板1/模板2/模板3....

eg:模板1

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
@Data @AllArgsConstructor @NoArgsConstructor public class News { private Form1 formList; @Data @NoArgsConstructor public static class Form1 implements Serializable{ private static final long serialVersionUID = -3472703477288173984L; /**订单编号 */ private String character_string21; /**服务时间*/ private String time15; /**订单金额*/ private String amount6; } }

4.在config建立配置类,编写公共方法,将实体类作为参数传递

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
@Slf4j @Configuration @Data public class NewsConfiguration { public static void post(News news){ String appId = WxPayConfiguration.getAppId(); WxMaService wxMaService = WxMaConfiguration.getMaService(appId); WxMaMsgService msgService = wxMaService.getMsgService(); ArrayList<WxMaSubscribeMessage.MsgData> msgData = new ArrayList<>(); //支付成功通知(微信小程序只有支付成功后才能开启第一次订阅消息推送) if(news.getId().equals(WxNewsEnum.STATUS_1.getValue())){ news.setTemplateId(WxNewsEnum.STATUS_1.getDesc()); News.Form1 formList1 = news.getFormList1(); msgData.add(new WxMaSubscribeMessage.MsgData("character_string21",tempList1.getCharacter_string21())); msgData.add(new WxMaSubscribeMessage.MsgData("time15",tempList1.getTime15())); msgData.add(new WxMaSubscribeMessage.MsgData("amount6",tempList1.getAmount6())); } try { WxMaSubscribeMessage build = WxMaSubscribeMessage.builder() .toUser(news.getTouser()) .templateId(news.getTemplateId()) .data(msgData) .build(); msgService.sendSubscribeMsg(build); } catch (Exception e) { e.printStackTrace(); }

 5.在需要推送消息的位置进行post方法调用,注意实体类各参数的格式及字数要求(比如,time格式要求为15:01,或:2019年10月1日 15:01。具体可参考微信开发平台的官方文档)

6.注意事项:需要和前端对接好模板ID是否一致;订阅消息最多推送3条;47003模板参数不准确,可能为空或者不满足规则,errmsg会提示具体是哪个字段出错;43101注意检查模板ID及是否是支付成功后开始的消息推送。 

最后

以上就是直率舞蹈最近收集整理的关于微信订阅消息推送(记录)的全部内容,更多相关微信订阅消息推送(记录)内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(67)

评论列表共有 0 条评论

立即
投稿
返回
顶部