前端报错 invalid signature 大概原因知道应该是appid和jsapi_ticket 不匹配造成的
ApiConfig ac = new ApiConfig(); ac.setAppId(appid); ac.setAppSecret(appSecret); ac.setToken(token); ApiConfigKit.putApiConfig(ac); ApiConfigKit.setThreadLocalAppId(ac.getAppId()); JsTicket jsApiTicket = JsTicketApi.getTicket(JsApiType.jsapi); final IAccessTokenCache accessTokenCache = ApiConfigKit.getAccessTokenCache(); String key = ac.getAppId() + ':' + JsApiType.jsapi.name(); System.out.println("缓存:key:"+key+"-"+accessTokenCache.get(key));
情景是两个不同公众号配置进这段代码 第一次运行
缓存:key:wx305749a07abae9b3:jsapi-{"errcode":0,"ticket":"sM4AOVdWfPE4DxkXGEs8VNQEivnUA2nvrGfDcsjuxGSMP1JEMidqwy1rk2GvJXqW7WcgNXcegEC5KdozslXWwg","errmsg":"ok","expiredTime":1554261635650}
缓存:key:wx583e4b51a113fd70:jsapi-{"errcode":0,"ticket":"kgt8ON7yVITDhtdwci0qeRDmZbg7ucLtvlM5YphKJIo2yzGgqZXJk6_N5QN1ipJq1wqtLcrzRxOz64Ksuzthfg","errmsg":"ok","expiredTime":1554261690543}
这时前端不会报错,appid对应一个jsapi_ticket ,但是2个小时后失效重新获取jsapi_ticket 后,两个ticket就一致了
缓存:key:wx583e4b51a113fd70:jsapi-{"errcode":0,"ticket":"sM4AOVdWfPE4DxkXGEs8VNQEivnUA2nvrGfDcsjuxGT6epDEYhlWnprIphgJfqXB7kuHMAMmpwUkB4ztZCEs7Q","errmsg":"ok","expiredTime":1554276489314}
缓存:key:wx305749a07abae9b3:jsapi-{"errcode":0,"ticket":"sM4AOVdWfPE4DxkXGEs8VNQEivnUA2nvrGfDcsjuxGT6epDEYhlWnprIphgJfqXB7kuHMAMmpwUkB4ztZCEs7Q","errmsg":"ok","expiredTime":1554271506336}
有大佬知道如何解决吗
ApiConfigKit.setThreadLocalAppId(ac.getAppId());
threadlocal 操作都是 jfinal weixin 内部的拦截器自动完成的