用户的小程序中的消息接收设置为接收,
但是在接收消息时却提示
发送的逻辑也就是
public void sendPublishTaskMsgNew(HashSet<User> userList, TaskInfoVO taskInfoVO, String content) {
List<WxMaSubscribeMessage.MsgData> msgDataList = new ArrayList<>();
//任务类别
WxMaSubscribeMessage.MsgData msgThing1 = new WxMaSubscribeMessage.MsgData();
msgThing1.setName(SubscribeTemplateTypeEnum.THING1.getName());
msgThing1.setValue(DictBizCache.getValue("YJ_RYLB", taskInfoVO.getTaskType()) + "-" + DictBizCache.getValue("YJ_RYLB", taskInfoVO.getTaskSecondType()));
msgDataList.add(msgThing1);
//任务名称
WxMaSubscribeMessage.MsgData msgThing2 = new WxMaSubscribeMessage.MsgData();
msgThing2.setName(SubscribeTemplateTypeEnum.THING2.getName());
msgThing2.setValue(taskInfoVO.getTaskName());
msgDataList.add(msgThing2);
//发送时间
WxMaSubscribeMessage.MsgData msgThing3 = new WxMaSubscribeMessage.MsgData();
msgThing3.setName(SubscribeTemplateTypeEnum.TIME3.getName());
msgThing3.setValue(DatePattern.CHINESE_DATE_TIME_PATTERN.format(DateUtil.now()));
msgDataList.add(msgThing3);
//专长要求
WxMaSubscribeMessage.MsgData msgThing4 = new WxMaSubscribeMessage.MsgData();
msgThing4.setName(SubscribeTemplateTypeEnum.THING4.getName());
if (taskInfoVO.getTaskNeedSkill() != null & !"".equals(taskInfoVO.getTaskNeedSkill())) {
msgThing4.setValue(DictBizCache.getValue("YJ_ZCXX", taskInfoVO.getTaskNeedSkill()));
}else {
msgThing4.setValue("无");
}
msgDataList.add(msgThing4);
userList.forEach(e -> {
log.info("用户姓名{},用户电话{}",e.getName(),e.getAccount());
if (ObjectUtil.isNotEmpty(e.getOpenId())) {
WxMaSubscribeMessage wxMaSubscribeMessage = new WxMaSubscribeMessage();
wxMaSubscribeMessage.setData(msgDataList);
wxMaSubscribeMessage.setPage("pages/index/index");
wxMaSubscribeMessage.setTemplateId(TASK_TEMPLATE_ID);
wxMaSubscribeMessage.setToUser(UserCache.getUser(e.getId()).getOpenId());
try {
wxMaService.getSubscribeService().sendSubscribeMsg(wxMaSubscribeMessage);
} catch (WxErrorException wxErrorException) {
log.error("发送订阅消息失败:" + wxErrorException.getError());
}
}
});
}
43101说明用户取消了订阅或者是没有订阅次数,
用户点击订阅一次才可以发送一次,用户订阅次数不够
那我们可以尝试一下
有长期订阅权限?没有的话订阅一次只能发送一次,再次发就会报错发不出去