通用交易系统->进件 token切换处理

This commit is contained in:
353259576 2024-11-18 09:52:00 +08:00
parent 09cac40350
commit b4c2a6a702
2 changed files with 17 additions and 2 deletions

View File

@ -7,7 +7,7 @@ public enum TransactionMerchantTokenTypeEnum {
/**
* 服务商身份获取token链接
*/
COMPONENT_ACCESS_TOKEN,
TP_THIRD_V2_TOKEN,
/**
* 非服务商身份获取token链接

View File

@ -11,12 +11,14 @@ import com.dyj.common.domain.ClientTokenInfo;
import com.dyj.common.domain.query.BaseTransactionMerchantQuery;
import com.dyj.common.domain.query.ClientTokenQuery;
import com.dyj.common.domain.vo.ClientTokenVo;
import com.dyj.common.domain.vo.TpThirdV2TokenVo;
import com.dyj.common.enums.TransactionMerchantTokenTypeEnum;
import com.dyj.common.service.IAgentTokenService;
import com.dyj.common.utils.DyConfigUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Component;
import org.springframework.util.StringUtils;
import javax.annotation.Resource;
import java.util.Objects;
@ -45,8 +47,21 @@ public class TransactionMerchantTokenInterceptor implements Interceptor<Object>
transactionMerchantTokenTypeEnum = query.getTransactionMerchantTokenType();
}
}
if (TransactionMerchantTokenTypeEnum.COMPONENT_ACCESS_TOKEN.equals(transactionMerchantTokenTypeEnum)){
if (TransactionMerchantTokenTypeEnum.TP_THIRD_V2_TOKEN.equals(transactionMerchantTokenTypeEnum)){
//处理服务商token
TpThirdV2TokenVo tpThirdV2Token = DyConfigUtils.getAgentTokenService().getTpThirdV2Token(tenantId, clientKey);
if (Objects.isNull(tpThirdV2Token)) {
AgentConfiguration agent = DyConfigUtils.getAgent(tenantId, clientKey);
tpThirdV2Token = authClient.tpThirdV2Token(agent.getClientKey(), agent.getClientSecret(), agent.getTicket());
if (Objects.nonNull(tpThirdV2Token) && StringUtils.hasLength(tpThirdV2Token.getComponent_access_token())) {
DyConfigUtils.getAgentTokenService().setTpThirdV2Token(tenantId, clientKey, tpThirdV2Token);
}
}
if (Objects.isNull(tpThirdV2Token)) {
throw new RuntimeException("component_access_token is null");
}
request.addHeader("access-token", tpThirdV2Token.getComponent_access_token());
}else {
//处理非服务商获取token
IAgentTokenService agentTokenService = DyConfigUtils.getAgentTokenService();