Преглед изворни кода

优化代码,添加接口

liuchengsen пре 1 месец
родитељ
комит
83ff5b810b

+ 1 - 0
zhijiayun-gateway/src/main/resources/application-dev.yml

@@ -76,6 +76,7 @@ payment:
     alipay-root-cert-path: ${ALIPAY_ROOT_CERT_PATH:certs/dev/alipay/alipayRootCert.crt}
     alipay-root-cert-path: ${ALIPAY_ROOT_CERT_PATH:certs/dev/alipay/alipayRootCert.crt}
   # 安心付(周期卡-小程序会员卡管理):独立小程序应用,与网页应用的 alipay 配置完全独立
   # 安心付(周期卡-小程序会员卡管理):独立小程序应用,与网页应用的 alipay 配置完全独立
   anxin-alipay:
   anxin-alipay:
+    enabled: false
     app-id: ${ALIPAY_ANXIN_APP_ID:}
     app-id: ${ALIPAY_ANXIN_APP_ID:}
     app-private-key: ${ALIPAY_ANXIN_APP_PRIVATE_KEY:}
     app-private-key: ${ALIPAY_ANXIN_APP_PRIVATE_KEY:}
     alipay-public-key: ${ALIPAY_ANXIN_PUBLIC_KEY:}
     alipay-public-key: ${ALIPAY_ANXIN_PUBLIC_KEY:}

+ 1 - 0
zhijiayun-gateway/src/main/resources/application-prod.yml

@@ -126,6 +126,7 @@ payment:
     alipay-root-cert-path: ${ALIPAY_ROOT_CERT_PATH:certs/prod/alipay/alipayRootCert.crt}
     alipay-root-cert-path: ${ALIPAY_ROOT_CERT_PATH:certs/prod/alipay/alipayRootCert.crt}
   # 安心付(周期卡-小程序会员卡管理):独立小程序应用,与网页应用的 alipay 配置完全独立
   # 安心付(周期卡-小程序会员卡管理):独立小程序应用,与网页应用的 alipay 配置完全独立
   anxin-alipay:
   anxin-alipay:
+    enabled: false
     app-id: ${ALIPAY_ANXIN_APP_ID:}
     app-id: ${ALIPAY_ANXIN_APP_ID:}
     app-private-key: ${ALIPAY_ANXIN_APP_PRIVATE_KEY:}
     app-private-key: ${ALIPAY_ANXIN_APP_PRIVATE_KEY:}
     alipay-public-key: ${ALIPAY_ANXIN_PUBLIC_KEY:}
     alipay-public-key: ${ALIPAY_ANXIN_PUBLIC_KEY:}

+ 1 - 0
zhijiayun-gateway/src/main/resources/application.yml

@@ -109,6 +109,7 @@ payment:
   # 支付宝安心付配置(小程序应用 - 周期卡会员管理)
   # 支付宝安心付配置(小程序应用 - 周期卡会员管理)
   # 安心付对应的是支付宝小程序应用,与网页应用(二维码付款)使用不同的 appId、密钥和证书
   # 安心付对应的是支付宝小程序应用,与网页应用(二维码付款)使用不同的 appId、密钥和证书
   anxin-alipay:
   anxin-alipay:
+    enabled: false
     app-id: ${ALIPAY_ANXIN_APP_ID:}
     app-id: ${ALIPAY_ANXIN_APP_ID:}
     app-private-key: ${ALIPAY_ANXIN_APP_PRIVATE_KEY:}
     app-private-key: ${ALIPAY_ANXIN_APP_PRIVATE_KEY:}
     alipay-public-key: ${ALIPAY_ANXIN_PUBLIC_KEY:}
     alipay-public-key: ${ALIPAY_ANXIN_PUBLIC_KEY:}

+ 3 - 1
zhijiayun-payment/src/main/java/com/xuekairui/payment/config/PaymentConfig.java

@@ -169,10 +169,12 @@ public class PaymentConfig {
      * <p>安心付对应的是支付宝小程序应用,与网页应用(二维码付款)使用不同的
      * <p>安心付对应的是支付宝小程序应用,与网页应用(二维码付款)使用不同的
      * appId、密钥和证书,因此需要独立的 AlipayClient,不能共用 {@link #alipayClient()}。
      * appId、密钥和证书,因此需要独立的 AlipayClient,不能共用 {@link #alipayClient()}。
      *
      *
-     * <p>仅当配置了 payment.anxin-alipay.app-id 且 payment.mock=false 时注册。
+     * <p>仅当 payment.anxin-alipay.enabled=true 且 payment.mock=false 时注册。
+     * 当前安心付功能先停止,默认不启用。
      * 支持公钥模式(优先)和证书模式(备选),与 {@link #alipayClient()} 逻辑一致。
      * 支持公钥模式(优先)和证书模式(备选),与 {@link #alipayClient()} 逻辑一致。
      */
      */
     @Bean("anxinAlipayClient")
     @Bean("anxinAlipayClient")
+    @ConditionalOnProperty(prefix = "payment.anxin-alipay", name = "enabled", havingValue = "true")
     @ConditionalOnProperty(prefix = "payment", name = "mock", havingValue = "false")
     @ConditionalOnProperty(prefix = "payment", name = "mock", havingValue = "false")
     public AlipayClient anxinAlipayClient() throws Exception {
     public AlipayClient anxinAlipayClient() throws Exception {
         PaymentProperties.AnxinAlipay ax = paymentProperties.getAnxinAlipay();
         PaymentProperties.AnxinAlipay ax = paymentProperties.getAnxinAlipay();

+ 2 - 0
zhijiayun-payment/src/main/java/com/xuekairui/payment/controller/AlipayAnxinPayController.java

@@ -13,6 +13,7 @@ import jakarta.servlet.http.HttpServletRequest;
 import jakarta.validation.Valid;
 import jakarta.validation.Valid;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.web.bind.annotation.*;
 import org.springframework.web.bind.annotation.*;
 
 
 import java.util.HashMap;
 import java.util.HashMap;
@@ -42,6 +43,7 @@ import java.util.stream.Collectors;
 @Slf4j
 @Slf4j
 @RestController
 @RestController
 @RequiredArgsConstructor
 @RequiredArgsConstructor
+@ConditionalOnProperty(prefix = "payment.anxin-alipay", name = "enabled", havingValue = "true")
 public class AlipayAnxinPayController {
 public class AlipayAnxinPayController {
 
 
     private final AlipayAnxinPayService anxinPayService;
     private final AlipayAnxinPayService anxinPayService;

+ 5 - 15
zhijiayun-payment/src/main/java/com/xuekairui/payment/service/AlipayAnxinPayService.java

@@ -25,8 +25,10 @@ import com.xuekairui.payment.mapper.AlipayAnxinCardMapper;
 import com.xuekairui.payment.mapper.AlipayAnxinOrderRecordMapper;
 import com.xuekairui.payment.mapper.AlipayAnxinOrderRecordMapper;
 import com.xuekairui.user.enums.MembershipLevel;
 import com.xuekairui.user.enums.MembershipLevel;
 import com.xuekairui.user.service.MembershipService;
 import com.xuekairui.user.service.MembershipService;
+import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.ObjectProvider;
 import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
@@ -62,6 +64,8 @@ import java.util.Map;
  */
  */
 @Slf4j
 @Slf4j
 @Service
 @Service
+@RequiredArgsConstructor
+@ConditionalOnProperty(prefix = "payment.anxin-alipay", name = "enabled", havingValue = "true")
 public class AlipayAnxinPayService {
 public class AlipayAnxinPayService {
 
 
     private final AlipayAnxinCardMapper anxinCardMapper;
     private final AlipayAnxinCardMapper anxinCardMapper;
@@ -69,25 +73,11 @@ public class AlipayAnxinPayService {
     private final PaymentPlanService paymentPlanService;
     private final PaymentPlanService paymentPlanService;
     private final PaymentProperties paymentProperties;
     private final PaymentProperties paymentProperties;
     private final MembershipService membershipService;
     private final MembershipService membershipService;
+    @Qualifier("anxinAlipayClient")
     private final ObjectProvider<AlipayClient> anxinAlipayClientProvider;
     private final ObjectProvider<AlipayClient> anxinAlipayClientProvider;
 
 
     private final ObjectMapper objectMapper = new ObjectMapper();
     private final ObjectMapper objectMapper = new ObjectMapper();
 
 
-    public AlipayAnxinPayService(
-            AlipayAnxinCardMapper anxinCardMapper,
-            AlipayAnxinOrderRecordMapper anxinOrderRecordMapper,
-            PaymentPlanService paymentPlanService,
-            PaymentProperties paymentProperties,
-            MembershipService membershipService,
-            @Qualifier("anxinAlipayClient") ObjectProvider<AlipayClient> anxinAlipayClientProvider) {
-        this.anxinCardMapper = anxinCardMapper;
-        this.anxinOrderRecordMapper = anxinOrderRecordMapper;
-        this.paymentPlanService = paymentPlanService;
-        this.paymentProperties = paymentProperties;
-        this.membershipService = membershipService;
-        this.anxinAlipayClientProvider = anxinAlipayClientProvider;
-    }
-
     // ======================== 卡模板管理 ========================
     // ======================== 卡模板管理 ========================
 
 
     /**
     /**

+ 2 - 0
zhijiayun-payment/src/main/java/com/xuekairui/payment/service/PaymentOrderService.java

@@ -29,6 +29,7 @@ import com.xuekairui.user.service.MembershipService;
 import lombok.RequiredArgsConstructor;
 import lombok.RequiredArgsConstructor;
 import lombok.extern.slf4j.Slf4j;
 import lombok.extern.slf4j.Slf4j;
 import org.springframework.beans.factory.ObjectProvider;
 import org.springframework.beans.factory.ObjectProvider;
+import org.springframework.beans.factory.annotation.Qualifier;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.scheduling.annotation.Scheduled;
 import org.springframework.stereotype.Service;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
 import org.springframework.transaction.annotation.Transactional;
@@ -51,6 +52,7 @@ public class PaymentOrderService {
     private final QRCodeService qrCodeService;
     private final QRCodeService qrCodeService;
     private final MembershipService membershipService;
     private final MembershipService membershipService;
     private final PaymentProperties paymentProperties;
     private final PaymentProperties paymentProperties;
+    @Qualifier("alipayClient")
     private final ObjectProvider<AlipayClient> alipayClientProvider;
     private final ObjectProvider<AlipayClient> alipayClientProvider;
     private final ObjectProvider<WxPayService> wxPayServiceProvider;
     private final ObjectProvider<WxPayService> wxPayServiceProvider;
     private final PaymentAgreementService agreementService;
     private final PaymentAgreementService agreementService;