mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-10-20 18:47:38 +08:00
🎨 #1488 公众号模块支持分布式锁,设置token过期时加锁
This commit is contained in:
@@ -155,7 +155,18 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
||||
*/
|
||||
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
|
||||
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
|
||||
this.getWxOpenConfigStorage().expireComponentAccessToken();
|
||||
Lock lock = this.getWxOpenConfigStorage().getComponentAccessTokenLock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (StringUtils.equals(componentAccessToken, this.getWxOpenConfigStorage().getComponentAccessToken()){
|
||||
this.getWxOpenConfigStorage().expireComponentAccessToken();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
this.getWxOpenConfigStorage().expireComponentAccessToken();
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
|
||||
if (this.getWxOpenConfigStorage().autoRefreshToken()) {
|
||||
return this.post(uri, postData, accessTokenKey);
|
||||
}
|
||||
@@ -188,7 +199,17 @@ public class WxOpenComponentServiceImpl implements WxOpenComponentService {
|
||||
*/
|
||||
if (error.getErrorCode() == 42001 || error.getErrorCode() == 40001 || error.getErrorCode() == 40014) {
|
||||
// 强制设置wxMpConfigStorage它的access token过期了,这样在下一次请求里就会刷新access token
|
||||
this.getWxOpenConfigStorage().expireComponentAccessToken();
|
||||
Lock lock = this.getWxOpenConfigStorage().getComponentAccessTokenLock();
|
||||
lock.lock();
|
||||
try {
|
||||
if (StringUtils.equals(componentAccessToken, this.getWxOpenConfigStorage().getComponentAccessToken()){
|
||||
this.getWxOpenConfigStorage().expireComponentAccessToken();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
this.getWxOpenConfigStorage().expireComponentAccessToken();
|
||||
}finally {
|
||||
lock.unlock();
|
||||
}
|
||||
if (this.getWxOpenConfigStorage().autoRefreshToken()) {
|
||||
return this.get(uri, accessTokenKey);
|
||||
}
|
||||
|
Reference in New Issue
Block a user