<dependency>
<groupId>com.github.binarywang</groupId>
<artifactId>weixin-java-miniapp</artifactId>
<version>4.6.0</version>
</dependency>
使用这个sdk,给微信发布订阅消息。设置模板
然后代码
WxMaSubscribeMessage message = new WxMaSubscribeMessage();
message.setTemplateId("41N-qxn-T-Rv--YS");
message.setToUser("oGrk");
message.setPage("https://www.baidu.com");
List<WxMaSubscribeMessage.MsgData> subscribeDataList = new ArrayList<>();
WxMaSubscribeMessage.MsgData subscribeData = new WxMaSubscribeMessage.MsgData();
subscribeData.setName("账号"); // 你在小程序自定义的key(比如“商家名称”)
subscribeData.setValue("123"); //key对应的内容
WxMaSubscribeMessage.MsgData subscribeData1 = new WxMaSubscribeMessage.MsgData();
subscribeData1.setName("密码"); // 你在小程序自定义的key(比如“商家名称”)
subscribeData1.setValue("123"); //key对应的内容
subscribeDataList.add(subscribeData);
subscribeDataList.add(subscribeData1);
message.setData(subscribeDataList);
try {
wxMaService.getMsgService().sendSubscribeMsg(message);
之后一直报错
me.chanjar.weixin.common.error.WxErrorException: 错误代码:47003, 错误信息:模板参数不准确,可能为空或者不满足规则,errmsg会提示具体是哪个字段出错,微信原始报文:{"errcode":47003,"errmsg":"argument invalid! data.character_string4.value i rid: 66d866bc-0ad4cc27-608fd25f"}
不太清楚是哪个环节出了问题,看了文档,内容也没有超过文档的说明
你好,麻烦参考下文档的JSON:https://developers.weixin.qq.com/miniprogram/dev/OpenApiDoc/mp-message-management/subscribe-message/sendMessage.html
日志查看请求包:{"touser":"oGrkd7XzByWuFv7Hql5diROrPJqk","template_id":"41N-qxn-T-Rv--YSlCypaHR1xVH8ZWAt5FHKKL34x9Q","page":"https://www.xundzl.com/login?fullPath=/main/index","miniprogram_state":"formal","lang":"zh_CN","data":{"账号":{"value":"123"},"密码":{"value":"123"}}}
date里面是字段不是中文账号
去看看接口文档说明吧,太尴尬了