@RequestMapping("/wXSubscribeMessage1")
public void wXSubscribeMessage1() {
int count = 0;
while (count < 10) {
// 业务逻辑代码
log.info("询价通知模板: {}", "第 " + (count + 1) + " 次循环");
// 定义用户 OpenID 列表
List<String> userList = Arrays.asList(
"o8qci7eVQYFUICZ4iTGHd9Y5wfVI",
"o8qci7QgJbYWjiMRb6KCwPFgWUIA",
"o8qci7W6_teC1OTOzKF3147CkcN0"
);
String pagePath = "/packages/dealer/pages/message/message?messageType=" + PrivateMessageTypeEnum.QUOTE.getIndex();
// 遍历用户列表并发送消息
for (String openId : userList) {
WXSubscribeSendMsgRequest wxSubscribeSendMsgRequest = new WXSubscribeSendMsgRequest();
wxSubscribeSendMsgRequest.setTouser(openId); // 设置当前用户 OpenID
wxSubscribeSendMsgRequest.setTemplate_id("volTpOHfKwhWYZ1ruZ6daozBoEKdVMG5LGLBZYtBhcg");
wxSubscribeSendMsgRequest.setPage(pagePath);
wxSubscribeSendMsgRequest.setMiniprogram_state("trial");
// 构建消息内容(与原有逻辑一致)
Map<String, Map<String, String>> data = new HashMap<>();
data.put("thing1", new HashMap<String, String>() {{ put("value", "赵赵"); }});
data.put("short_thing2", new HashMap<String, String>() {{ put("value", "单品询价"); }});
data.put("time3", new HashMap<String, String>() {{ put("value", DateUtil.formatDate2LongString(new Date())); }});
wxSubscribeSendMsgRequest.setData(data);
// 发送消息
wxSubscribeService.sendMsg(wxSubscribeSendMsgRequest);
}
count++; // 不要忘记递增计数器!
}
}
o.TestController : 询价通知模板: 第 1 次循环
2025-03-13 16:08:51.066 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:51.352 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29293-425ed78c-24ad2fa4"}
2025-03-13 16:08:51.618 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29293-0bfbd8ce-4f9931b0"}
2025-03-13 16:08:51.619 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 2 次循环
2025-03-13 16:08:51.986 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:52.298 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29294-6af386fe-535cd7f4"}
2025-03-13 16:08:52.591 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29294-33297302-2432d19a"}
2025-03-13 16:08:52.591 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 3 次循环
2025-03-13 16:08:52.933 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:53.205 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29295-3b9c273c-10e670e6"}
2025-03-13 16:08:53.500 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29295-2fce52b9-7121622f"}
2025-03-13 16:08:53.500 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 4 次循环
2025-03-13 16:08:53.905 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:54.193 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29296-36455cd6-0a5a861c"}
2025-03-13 16:08:54.496 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29296-147d8818-4e091111"}
2025-03-13 16:08:54.496 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 5 次循环
2025-03-13 16:08:54.964 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:55.522 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29297-630f8e7c-7d36a40f"}
2025-03-13 16:08:55.842 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29297-5e4de710-54ac54bb"}
2025-03-13 16:08:55.842 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 6 次循环
2025-03-13 16:08:56.275 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:56.542 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29298-720a097b-5e657a3f"}
2025-03-13 16:08:56.892 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29298-531c6308-27e7755c"}
2025-03-13 16:08:56.892 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 7 次循环
2025-03-13 16:08:57.322 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":0,"errmsg":"ok"}
2025-03-13 16:08:57.647 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29299-39fc48ce-7d876619"}
2025-03-13 16:08:57.930 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d29299-16c651bc-668811ce"}
2025-03-13 16:08:57.931 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 8 次循环
2025-03-13 16:08:58.196 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929a-30eb6fa8-5b8b79b1"}
2025-03-13 16:08:58.493 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929a-2da9bf3f-6291eb45"}
2025-03-13 16:08:58.753 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929a-0bc98f0a-2001d9dd"}
2025-03-13 16:08:58.753 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 9 次循环
2025-03-13 16:08:59.062 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929a-2b25b20d-407a89ec"}
2025-03-13 16:08:59.494 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929b-4cb1977c-03cec51f"}
2025-03-13 16:08:59.857 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929b-6bc18fd9-1f6b417e"}
2025-03-13 16:08:59.857 INFO 19288 --- [nio-9005-exec-3] c.z.p.modules.demo.TestController : 询价通知模板: 第 10 次循环
2025-03-13 16:09:00.246 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929c-3c8c990e-6329b95c"}
2025-03-13 16:09:00.538 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929c-1228594d-67be1d69"}
2025-03-13 16:09:00.847 INFO 19288 --- [nio-9005-exec-3] c.z.p.m.w.s.impl.WXSubscribeServiceImpl : wx btxs subscribe sendMsg the res is {"errcode":43101,"errmsg":"user refuse to accept the msg rid: 67d2929c-6021598d-53f8a142"}

你要循环几次,就需要这个用户在你的小程序页面点击订阅多少次。用完就需要重新订阅。
错误信息很明确,用户拒绝接收消息。
在我的一遍遍循环下,从一开始的都允许发送,变成了部分发送成功,或者全部不成功!
是有什么安全限制吗
一次性订阅消息,点一次订阅,只能推送一条。推送次数用完了,是无法继续推送的。
那只是用户订阅的时候不提示是否拒绝,还是只能订阅一次发一条。