瀏覽代碼

优化代码,添加接口

liuchengsen 1 月之前
父節點
當前提交
3c0958d260

+ 7 - 69
zhijiayun-payment/src/main/java/com/xuekairui/payment/config/PaymentConfig.java

@@ -163,78 +163,16 @@ public class PaymentConfig {
 
     // ======================== 安心付支付宝客户端(小程序应用) ========================
 
-    /**
-     * 安心付支付宝客户端(小程序应用 - 周期卡会员管理)
+    /*
+     * 安心付支付宝客户端已暂停。
      *
-     * <p>安心付对应的是支付宝小程序应用,与网页应用(二维码付款)使用不同的
-     * appId、密钥和证书,因此需要独立的 AlipayClient,不能共用 {@link #alipayClient()}。
+     * 原因:同一个 Spring 容器不允许同时存在两个 AlipayClient Bean,
+     * 使用 @Qualifier 或 @ConditionalOnProperty 在本项目实际运行中仍会导致
+     * NoUniqueBeanDefinitionException。安心付功能先停止,后续如恢复需重新设计
+     * (例如独立服务、非 Spring 容器管理客户端、或彻底拆分上下文)。
      *
-     * <p>仅当 payment.anxin-alipay.enabled=true 且 payment.mock=false 时注册。
-     * 当前安心付功能先停止,默认不启用。
-     * 支持公钥模式(优先)和证书模式(备选),与 {@link #alipayClient()} 逻辑一致。
+     * 原实现保留在 Git 历史中,如需恢复可参考历史提交。
      */
-    @Bean("anxinAlipayClient")
-    @ConditionalOnProperty(prefix = "payment.anxin-alipay", name = "enabled", havingValue = "true")
-    @ConditionalOnProperty(prefix = "payment", name = "mock", havingValue = "false")
-    public AlipayClient anxinAlipayClient() throws Exception {
-        PaymentProperties.AnxinAlipay ax = paymentProperties.getAnxinAlipay();
-
-        if (ax.getAppId() == null || ax.getAppId().isBlank()) {
-            log.warn("未配置 payment.anxin-alipay.app-id,跳过安心付支付宝客户端初始化");
-            return null;
-        }
-
-        // 公钥模式(优先)
-        if (ax.getAlipayPublicKey() != null && !ax.getAlipayPublicKey().isBlank()) {
-            log.info("初始化安心付支付宝客户端(公钥模式): appId={}, serverUrl={}",
-                    ax.getAppId(), ax.getServerUrl());
-
-            String privateKey = ax.getAppPrivateKey();
-            if ((privateKey == null || privateKey.isBlank())
-                    && ax.getAppPrivateKeyPath() != null && !ax.getAppPrivateKeyPath().isBlank()) {
-                privateKey = readFileContent(ax.getAppPrivateKeyPath());
-                log.info("已从文件读取安心付应用私钥: {}", ax.getAppPrivateKeyPath());
-            }
-
-            return new DefaultAlipayClient(
-                    ax.getServerUrl(),
-                    ax.getAppId(),
-                    privateKey,
-                    ax.getFormat(),
-                    ax.getCharset(),
-                    ax.getAlipayPublicKey(),
-                    ax.getSignType()
-            );
-        }
-
-        // 证书模式(备选)
-        if (ax.getAppCertPath() != null && !ax.getAppCertPath().isBlank()) {
-            log.info("初始化安心付支付宝客户端(证书模式): appId={}, serverUrl={}",
-                    ax.getAppId(), ax.getServerUrl());
-
-            String privateKey = ax.getAppPrivateKey();
-            if (ax.getAppPrivateKeyPath() != null && !ax.getAppPrivateKeyPath().isBlank()) {
-                privateKey = readFileContent(ax.getAppPrivateKeyPath());
-                log.info("安心付应用私钥: {}", ax.getAppPrivateKeyPath());
-            }
-
-            CertAlipayRequest certRequest = new CertAlipayRequest();
-            certRequest.setServerUrl(ax.getServerUrl());
-            certRequest.setAppId(ax.getAppId());
-            certRequest.setPrivateKey(privateKey);
-            certRequest.setFormat(ax.getFormat());
-            certRequest.setCharset(ax.getCharset());
-            certRequest.setSignType(ax.getSignType());
-            certRequest.setCertPath(resolveFilePath(ax.getAppCertPath()));
-            certRequest.setAlipayPublicCertPath(resolveFilePath(ax.getAlipayCertPath()));
-            certRequest.setRootCertPath(resolveFilePath(ax.getAlipayRootCertPath()));
-
-            return new DefaultAlipayClient(certRequest);
-        }
-
-        log.warn("安心付配置不完整:需要配置公钥模式(alipay-public-key)或证书模式(app-cert-path),并确保已配置应用私钥(app-private-key),跳过安心付支付宝客户端初始化");
-        return null;
-    }
 
     /**
      * 微信支付客户端(仅 payment.mock=false 时注册)

+ 1 - 3
zhijiayun-payment/src/main/java/com/xuekairui/payment/controller/AlipayAnxinPayController.java

@@ -13,7 +13,6 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.HashMap;
@@ -41,9 +40,8 @@ import java.util.stream.Collectors;
  * </ul>
  */
 @Slf4j
-@RestController
+// @RestController  // 安心付已暂停:同一个容器不允许同时存在两个 AlipayClient,避免 Spring 扫描注册
 @RequiredArgsConstructor
-@ConditionalOnProperty(prefix = "payment.anxin-alipay", name = "enabled", havingValue = "true")
 public class AlipayAnxinPayController {
 
     private final AlipayAnxinPayService anxinPayService;

+ 1 - 4
zhijiayun-payment/src/main/java/com/xuekairui/payment/service/AlipayAnxinPayService.java

@@ -28,9 +28,7 @@ import com.xuekairui.user.service.MembershipService;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.ObjectProvider;
-import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.beans.factory.annotation.Qualifier;
-import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 
 import java.math.BigDecimal;
@@ -63,9 +61,8 @@ import java.util.Map;
  * @see <a href="https://opendocs.alipay.com/solution/0d3p55">安心付-先享周期卡</a>
  */
 @Slf4j
-@Service
+// @Service  // 安心付已暂停:同一个容器不允许同时存在两个 AlipayClient,避免 Spring 扫描注册
 @RequiredArgsConstructor
-@ConditionalOnProperty(prefix = "payment.anxin-alipay", name = "enabled", havingValue = "true")
 public class AlipayAnxinPayService {
 
     private final AlipayAnxinCardMapper anxinCardMapper;