-
-
Notifications
You must be signed in to change notification settings - Fork 8.9k
weixin java mp4.5.0 版本,使用 WxCpMessageRouter.route(微信消息); 报错问题处理
springcloud-boot edited this page Jun 2, 2023
·
2 revisions
使用时可见demo https://github.com/Wechat-Group/WxJava/wiki/CP_Quick-Start
这里面 WxCpService wxCpService = new WxCpServiceImpl(); //这里要缓存 wxCpService.setWxCpConfigStorage(config); //传入微信配置信息不做重复 WxCpMessageRouter wxCpMessageRouter = new WxCpMessageRouter(wxCpService);
一般情况下 wxCpService 会作为缓存注入spring容器中. 故使用
WxCpMessageRouter.route时,建源码: me.chanjar.weixin.mp.api.WxMpMessageRouter#route(me.chanjar.weixin.mp.bean.message.WxMpXmlMessage, java.util.Map<java.lang.String,java.lang.Object>, me.chanjar.weixin.mp.api.WxMpService) 212行
这里因为WxMpConfigStorageHolder.THREAD_LOCAL为set值,返回默认值default肯定是拿不到缓存的appid对应的wxCpService.
解决办法: 在自己程序代码使用wxCpMessageRouter.route前面,加上 WxMpConfigStorageHolder.THREAD_LOCAL.set(当前操作的appId)