我们公司有个阿里云的服务器,部署了一套由tomcat发布的管理系统,框架用的是nutz+nutzwk,其中集成了微信模块,有多个客户的微信公众号都由这个服务器的系统代理,现在出现了一种情况,菜单上绑定的网页的跳转都没问题,唯独点击事件,发送消息事件,关键词回复有问题。
我试了很长时间,发现如果重启了tomcat之后,哪个公众号先触发了上面有问题的事件,那么这个公众号就能正常使用,但是其他代理的公众号都会出现提示:“该公众号号提供的服务出现故障,请稍后再试”,后台打印了一下接口返回的视图内容是:httpStatus:403,Forbidden.
我猜想是不是一个服务器不能代理多个公众号啊,请大神们帮忙给个思路!
11 回复
WxHandler
public WxOutMsg eventClick(WxInMsg msg) {
String eventKey = msg.getEventKey();
log.debug("eventKey: " + eventKey);
log.debug("extKey: " + msg.getExtkey());
打印下 extKey 值,是不是wx_config.id 里的值
原代码:
@IocBean(name = "wxHandler")
public class WxHandler extends AbstractWxHandler {
private final static Log log = Logs.get();
protected String token;
protected String aeskey;
protected WXBizMsgCrypt msgCrypt;
protected String appid;
protected WxApi2 api;
@Inject
private WxConfigService wxConfigService;
@Inject
private WxUserService wxUserService;
@Inject
private WxReplyService wxReplyService;
@Inject
private WxReplyNewsService wxReplyNewsService;
@Inject
private WxReplyTxtService wxReplyTxtService;
@Inject
private WxMsgService wxMsgService;
public boolean check(String signature, String timestamp, String nonce, String key) {
Wx_config appInfo = wxConfigService.fetch(Cnd.where("id", "=", key));
if(appInfo!=null){
this.token=appInfo.getToken();
this.aeskey=appInfo.getEncodingAESKey();
this.appid=appInfo.getAppid();
return Wxs.check(appInfo.getToken(), signature, timestamp, nonce);
}
return false;
}
public WXBizMsgCrypt getMsgCrypt() {
if (this.msgCrypt == null) {
try {
// 若抛异常Illegal key size ,需更新JDK的加密库为不限制长度
this.msgCrypt = new WXBizMsgCrypt(this.token, this.aeskey, this.appid);
} catch (AesException var2) {
throw new RuntimeException(var2);
}
}
return this.msgCrypt;
}
.........
}
修改后的代码
@IocBean(name = "wxHandler")
public class WxHandler extends AbstractWxHandler {
private final static Log log = Logs.getLog(WxHandler.class);
protected WxApi2 api;
private final static ThreadLocal<Wx_config> threadLocal = new ThreadLocal<>();
@Inject
private WxConfigService wxConfigService;
@Inject
private WxUserService wxUserService;
@Inject
private WxReplyService wxReplyService;
@Inject
private WxReplyNewsService wxReplyNewsService;
@Inject
private WxReplyTxtService wxReplyTxtService;
@Inject
private WxMsgService wxMsgService;
public boolean check(String signature, String timestamp, String nonce, String key) {
Wx_config appInfo = wxConfigService.fetch(Cnd.where("id", "=", key));
if(appInfo!=null){
threadLocal.set(appInfo);
return Wxs.check(appInfo.getToken(), signature, timestamp, nonce);
}
return false;
}
public WXBizMsgCrypt getMsgCrypt() {
Wx_config appInfo = threadLocal.get();
if (appInfo != null) {
try {
// 若抛异常Illegal key size ,需更新JDK的加密库为不限制长度
return new WXBizMsgCrypt(appInfo.getToken(), appInfo.getEncodingAESKey(), appInfo.getAppid());
} catch (AesException var2) {
throw new RuntimeException(var2);
}
}
return null;
}
..............
}
@Wizzercn 添加 singleton = false 不可以的,还是会出现问题
添加回复
请先登陆