Merge branch 'release' into develop

# Conflicts:
#	README.md
#	others/weixin-java-osgi/pom.xml
#	pom.xml
#	spring-boot-starters/pom.xml
#	spring-boot-starters/wx-java-miniapp-spring-boot-starter/pom.xml
#	spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/config/WxMaAutoConfiguration.java
#	spring-boot-starters/wx-java-miniapp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/miniapp/properties/WxMaProperties.java
#	spring-boot-starters/wx-java-mp-spring-boot-starter/pom.xml
#	spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/config/WxMpStorageAutoConfiguration.java
#	spring-boot-starters/wx-java-mp-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/mp/properties/WxMpProperties.java
#	spring-boot-starters/wx-java-open-spring-boot-starter/pom.xml
#	spring-boot-starters/wx-java-open-spring-boot-starter/src/main/java/com/binarywang/spring/starter/wxjava/open/config/WxOpenStorageAutoConfiguration.java
#	spring-boot-starters/wx-java-pay-spring-boot-starter/pom.xml
#	weixin-graal/pom.xml
#	weixin-java-common/pom.xml
#	weixin-java-common/src/main/java/me/chanjar/weixin/common/error/WxErrorException.java
#	weixin-java-common/src/main/java/me/chanjar/weixin/common/service/WxOAuth2Service.java
#	weixin-java-cp/pom.xml
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpUserService.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/BaseWxCpServiceImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpGroupRobotServiceImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpUserServiceImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUser.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/WxCpUserExternalContactInfo.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/external/contact/FollowedUser.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpMessageSendStatistics.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpTpXmlMessage.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/bean/message/WxCpXmlOutVideoMessage.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/WxCpTpConfigStorage.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpDefaultConfigImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpRedissonConfigImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpDefaultConfigImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/config/impl/WxCpTpRedissonConfigImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/constant/WxCpApiPathConsts.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/message/WxCpTpMessageRouterRule.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/WxCpTpService.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/BaseWxCpTpServiceImpl.java
#	weixin-java-cp/src/main/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpServiceImpl.java
#	weixin-java-cp/src/test/java/me/chanjar/weixin/cp/bean/message/WxCpTpXmlMessageTest.java
#	weixin-java-miniapp/pom.xml
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaLiveService.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaQrcodeService.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/WxMaService.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/BaseWxMaServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaAnalysisServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCloudServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaCodeServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaExpressServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaImgProcServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaJsapiServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveGoodsServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaLiveServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaOcrServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaQrcodeServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSettingServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/api/impl/WxMaSubscribeServiceImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/bean/live/WxMaLiveRoomInfo.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/config/impl/WxMaDefaultConfigImpl.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheQrcodeBytesRequestExecutor.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/ApacheQrcodeFileRequestExecutor.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/QrcodeBytesRequestExecutor.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/executor/QrcodeRequestExecutor.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/QrcodeBytesRequestExecutor.java
#	weixin-java-miniapp/src/main/java/cn/binarywang/wx/miniapp/util/QrcodeRequestExecutor.java
#	weixin-java-miniapp/src/test/java/cn/binarywang/wx/miniapp/api/impl/WxMaMsgServiceImplTest.java
#	weixin-java-mp/pom.xml
#	weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpGuideService.java
#	weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/WxMpService.java
#	weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImpl.java
#	weixin-java-mp/src/main/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImpl.java
#	weixin-java-mp/src/main/java/me/chanjar/weixin/mp/enums/WxMpApiUrl.java
#	weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBusyRetryTest.java
#	weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpGuideServiceImplTest.java
#	weixin-java-open/pom.xml
#	weixin-java-open/src/main/java/me/chanjar/weixin/open/api/WxOpenComponentService.java
#	weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenComponentServiceImpl.java
#	weixin-java-open/src/main/java/me/chanjar/weixin/open/api/impl/WxOpenMpServiceImpl.java
#	weixin-java-pay/pom.xml
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/PartnerTransactionsResult.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/ProfitSharingRequest.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/config/WxPayConfig.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/EcommerceService.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImpl.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/PayScoreServiceImpl.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/WxPayServiceApacheHttpImpl.java
#	weixin-java-pay/src/main/java/com/github/binarywang/wxpay/v3/auth/AutoUpdateCertificatesVerifier.java
#	weixin-java-pay/src/test/java/com/github/binarywang/wxpay/service/impl/EcommerceServiceImplTest.java
This commit is contained in:
Binary Wang 2021-06-02 20:42:59 +08:00
commit 0c4fb44a79

View File

@ -1,169 +0,0 @@
package me.chanjar.weixin.cp.tp.service.impl;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.bean.WxAccessToken;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.bean.WxCpProviderToken;
import java.util.concurrent.locks.Lock;
/**
* <pre>
* 默认接口实现类使用apache httpclient实现
* Created by zhenjun cai.
* </pre>
* <pre>
* 实现分布式锁基于WxCpTpRedissonConfigImpl存储引擎实现类版本
* 主要封装了suiteAccessTokencorpAccessTokensuiteJsapiTicketcorpJsapiTicket等的获取方法
* Updated by zhangq <zhangq002@gmail.com> on 2021-02-13
* </pre>
*
* @author zhenjun cai
* @author zhangq
*/
@Slf4j
public class WxCpTpServiceImpl extends WxCpTpServiceApacheHttpClientImpl {
@Override
public WxAccessToken getSuiteAccessTokenEntity() throws WxErrorException {
return this.getSuiteAccessTokenEntity(false);
}
@Override
public WxAccessToken getSuiteAccessTokenEntity(boolean forceRefresh) throws WxErrorException {
if (!this.configStorage.isSuiteAccessTokenExpired() && !forceRefresh) {
return this.configStorage.getSuiteAccessTokenEntity();
}
// 此处configStorage推荐使用WxCpTpRedissonConfigImpl实现类
// 它底层采用了redisson提供的并发锁会自动续期无需担心异常中断导致的死锁问题以及锁提前释放导致的并发问题
Lock lock = this.configStorage.getSuiteAccessTokenLock();
lock.lock();
try {
if (!this.configStorage.isSuiteAccessTokenExpired() && !forceRefresh) {
return this.configStorage.getSuiteAccessTokenEntity();
}
super.getSuiteAccessToken(forceRefresh);
return this.configStorage.getSuiteAccessTokenEntity();
} finally {
lock.unlock();
}
}
/**
* 复写父类方法使其支持并发锁模式
* @param forceRefresh
* @return
* @throws WxErrorException
*/
@Override
public String getSuiteAccessToken(boolean forceRefresh) throws WxErrorException {
WxAccessToken suiteToken = this.getSuiteAccessTokenEntity(forceRefresh);
return suiteToken.getAccessToken();
}
@Override
public WxCpProviderToken getWxCpProviderTokenEntity() throws WxErrorException {
return this.getWxCpProviderTokenEntity(false);
}
@Override
public WxCpProviderToken getWxCpProviderTokenEntity(boolean forceRefresh) throws WxErrorException {
if (!this.configStorage.isProviderTokenExpired() && !forceRefresh) {
return this.configStorage.getProviderTokenEntity();
}
Lock lock = this.configStorage.getProviderAccessTokenLock();
lock.lock();
try {
if (!this.configStorage.isProviderTokenExpired() && !forceRefresh) {
return this.configStorage.getProviderTokenEntity();
}
return super.getWxCpProviderTokenEntity(forceRefresh);
} finally {
lock.unlock();
}
}
@Override
public WxAccessToken getCorpToken(String authCorpId, String permanentCode) throws WxErrorException {
return this.getCorpToken(authCorpId, permanentCode, false);
}
@Override
public WxAccessToken getCorpToken(String authCorpId, String permanentCode, boolean forceRefresh)
throws WxErrorException {
if (!this.configStorage.isAccessTokenExpired(authCorpId) && !forceRefresh) {
return this.configStorage.getAccessTokenEntity(authCorpId);
}
Lock lock = this.configStorage.getAccessTokenLock(authCorpId);
lock.lock();
try {
if (!this.configStorage.isAccessTokenExpired(authCorpId) && !forceRefresh) {
return this.configStorage.getAccessTokenEntity(authCorpId);
}
WxAccessToken accessToken = super.getCorpToken(authCorpId, permanentCode);
this.configStorage.updateAccessToken(authCorpId, accessToken.getAccessToken(), accessToken.getExpiresIn());
return accessToken;
} finally {
lock.unlock();
}
}
@Override
public String getAuthCorpJsApiTicket(String authCorpId) throws WxErrorException {
return this.getAuthCorpJsApiTicket(authCorpId, false);
}
@Override
public String getAuthCorpJsApiTicket(String authCorpId, boolean forceRefresh) throws WxErrorException {
if (!this.configStorage.isAuthCorpJsApiTicketExpired(authCorpId) && !forceRefresh) {
return this.configStorage.getAuthCorpJsApiTicket(authCorpId);
}
Lock lock = this.configStorage.getAuthCorpJsapiTicketLock(authCorpId);
lock.lock();
try {
if (!this.configStorage.isAuthCorpJsApiTicketExpired(authCorpId) && !forceRefresh) {
return this.configStorage.getAuthCorpJsApiTicket(authCorpId);
}
if (forceRefresh) {
this.configStorage.expireAuthCorpJsApiTicket(authCorpId);
}
return super.getAuthCorpJsApiTicket(authCorpId);
} finally {
lock.unlock();
}
}
@Override
public String getSuiteJsApiTicket(String authCorpId) throws WxErrorException {
return this.getSuiteJsApiTicket(authCorpId, false);
}
@Override
public String getSuiteJsApiTicket(String authCorpId, boolean forceRefresh) throws WxErrorException {
if (!this.configStorage.isAuthSuiteJsApiTicketExpired(authCorpId) && !forceRefresh) {
return this.configStorage.getAuthSuiteJsApiTicket(authCorpId);
}
Lock lock = this.configStorage.getSuiteJsapiTicketLock(authCorpId);
lock.lock();
try {
if (!this.configStorage.isAuthSuiteJsApiTicketExpired(authCorpId) && !forceRefresh) {
return this.configStorage.getAuthSuiteJsApiTicket(authCorpId);
}
if (forceRefresh) {
this.configStorage.expireAuthSuiteJsApiTicket(authCorpId);
}
return super.getSuiteJsApiTicket(authCorpId);
} finally {
lock.unlock();
}
}
}