【代码优化】PAY:移除 PayClient 缓存,减少复杂性,性能足够(非高频读取)

This commit is contained in:
YunaiV
2024-07-24 23:03:59 +08:00
parent c0df6eab4e
commit f717c0f9c6
6 changed files with 25 additions and 49 deletions

View File

@@ -23,9 +23,10 @@ public interface PayClientFactory {
* @param channelId 渠道编号
* @param channelCode 渠道编码
* @param config 支付配置
* @return 支付客户端
*/
<Config extends PayClientConfig> void createOrUpdatePayClient(Long channelId, String channelCode,
Config config);
<Config extends PayClientConfig> PayClient createOrUpdatePayClient(Long channelId, String channelCode,
Config config);
/**
* 注册支付客户端 Class用于模块中实现的 PayClient

View File

@@ -71,8 +71,8 @@ public class PayClientFactoryImpl implements PayClientFactory {
@Override
@SuppressWarnings("unchecked")
public <Config extends PayClientConfig> void createOrUpdatePayClient(Long channelId, String channelCode,
Config config) {
public <Config extends PayClientConfig> PayClient createOrUpdatePayClient(Long channelId, String channelCode,
Config config) {
AbstractPayClient<Config> client = (AbstractPayClient<Config>) clients.get(channelId);
if (client == null) {
client = this.createPayClient(channelId, channelCode, config);
@@ -81,6 +81,7 @@ public class PayClientFactoryImpl implements PayClientFactory {
} else {
client.refresh(config);
}
return client;
}
@SuppressWarnings("unchecked")

View File

@@ -34,7 +34,8 @@ public class WxNativePayClient extends AbstractWxPayClient {
@Override
protected PayOrderRespDTO doUnifiedOrderV2(PayOrderUnifiedReqDTO reqDTO) throws WxPayException {
// 构建 WxPayUnifiedOrderRequest 对象
WxPayUnifiedOrderRequest request = buildPayUnifiedOrderRequestV2(reqDTO);
WxPayUnifiedOrderRequest request = buildPayUnifiedOrderRequestV2(reqDTO)
.setProductId(reqDTO.getOutTradeNo()); // V2 必须传递 productId无需在微信配置。该参数在 V3 简化,无需传递!
// 执行请求
WxPayNativeOrderResult response = client.createOrder(request);