From cdc437b191da9b51191b558310cc556cd1df348a Mon Sep 17 00:00:00 2001 From: Iamasoldier <1272745473@qq.com> Date: Mon, 14 Jul 2025 19:43:54 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=9C=8D=E5=8A=A1=E5=95=86=E6=94=AF?= =?UTF-8?q?=E4=BB=98):=20=E5=AE=8C=E5=96=84=E6=9C=8D=E5=8A=A1=E5=95=86?= =?UTF-8?q?=E6=94=AF=E4=BB=98=E6=B5=81=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/main/resources/application.yml | 24 ++++ .../order/controller/OrderController.java | 122 +++++++++++------- .../config/WechatAutoConfiguration.java | 12 +- 3 files changed, 103 insertions(+), 55 deletions(-) diff --git a/zlt-business/file-center/src/main/resources/application.yml b/zlt-business/file-center/src/main/resources/application.yml index dca69f98..21278625 100644 --- a/zlt-business/file-center/src/main/resources/application.yml +++ b/zlt-business/file-center/src/main/resources/application.yml @@ -75,3 +75,27 @@ zlt: # soTimeout: 1500 # connectTimeout: 600 # trackerList: ${zlt.fdfs.trackerList} + +# CDN配置示例 +aliyun: + cdn: + # 是否启用CDN功能 + enabled: false + # 阿里云AccessKey ID(建议使用环境变量配置) + access-key-id: ${zlt.oss.secretId:your-access-key-id} + # 阿里云AccessKey Secret(建议使用环境变量配置) + access-key-secret: ${zlt.oss.secretKey:your-access-key-secret} + # 地域ID + region-id: cn-beijing + # 默认域名 + domain: cdn.goflytec.com + # 默认批次大小 + default-batch-size: 100 + # 任务等待超时时间(秒) + task-timeout: 300 + +# 日志配置 +logging: + level: + com.central.file.service.impl.CdnServiceImpl: DEBUG + com.central.file.schedule.CdnScheduleTask: INFO diff --git a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java index 8872ecc0..bd635faa 100644 --- a/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java +++ b/zlt-business/order-center/src/main/java/com/central/order/controller/OrderController.java @@ -19,7 +19,11 @@ import com.central.order.service.*; import com.central.wechat.config.WxPayConfigFactory; import com.central.wechat.entity.WechatConfig; import com.central.wechat.feign.WechatConfigService; -import com.wechat.pay.java.service.payments.jsapi.model.*; +import com.wechat.pay.java.service.payments.jsapi.JsapiServiceExtension; +import com.wechat.pay.java.service.payments.jsapi.model.Amount; +import com.wechat.pay.java.service.payments.jsapi.model.Payer; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayRequest; +import com.wechat.pay.java.service.payments.jsapi.model.PrepayWithRequestPaymentResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Parameters; @@ -233,10 +237,11 @@ public class OrderController { @Operation(summary = "生成预支付订单") @PutMapping("/{orderId}/pay") - public Result payOrder(@PathVariable("orderId") Long orderId) { + public Result payOrder(@PathVariable("orderId") Long orderId) { try { // 1. 获取用户和订单信息 - SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId()); +// SysUser user = userCenterService.findUserById(LoginUserContextHolder.getUser().getId()); + SysUser user = userCenterService.findUserById(30l); Order order = orderService.getById(orderId); if (order == null) { return Result.failed("订单数据不存在"); @@ -249,60 +254,89 @@ public class OrderController { } // 3. 创建支付请求 - PrepayRequest request = new PrepayRequest(); WechatConfig wechatConfig = wechatConfigService.getConfig("PAY",qrCode.getTenantId()); - // 设置基本支付信息 - Amount amount = new Amount(); - amount.setTotal(Integer.parseInt(order.getOrderAmount())); - request.setAmount(amount); - request.setAppid(wechatConfig.getAppId()); - request.setMchid(wechatConfig.getMerchantId()); - request.setDescription(qrCode.getName()); - request.setNotifyUrl(wechatConfig.getNotifyUrl()); - request.setOutTradeNo(order.getOrderNo()); + // 4. 根据是否为服务商模式设置不同的支付参数 + if (Boolean.TRUE.equals(wechatConfig.getIsServiceMode())) { + // 服务商模式:使用partnerpayments包下的PrepayRequest + com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayRequest partnerRequest = + new com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayRequest(); - // 设置支付者信息 - Payer payer = new Payer(); - payer.setOpenid(user.getOpenId()); - request.setPayer(payer); + // 设置服务商信息 + partnerRequest.setSpAppid(wechatConfig.getServiceAppId()); + partnerRequest.setSpMchid(wechatConfig.getServiceMchId()); - // 设置分账信息 - SettleInfo settleInfo = new SettleInfo(); - if (isEnableProfit(qrCode)) { - settleInfo.setProfitSharing(true); - request.setSettleInfo(settleInfo); + // 设置子商户信息 + partnerRequest.setSubAppid(wechatConfig.getSubAppId()); + partnerRequest.setSubMchid(wechatConfig.getSubMchId()); + + // 设置其他支付信息 + partnerRequest.setDescription(qrCode.getName()); + partnerRequest.setNotifyUrl(wechatConfig.getNotifyUrl()); + partnerRequest.setOutTradeNo(order.getOrderNo()); + + // 设置金额 + com.wechat.pay.java.service.partnerpayments.jsapi.model.Amount partnerAmount = new com.wechat.pay.java.service.partnerpayments.jsapi.model.Amount(); + partnerAmount.setTotal(Integer.parseInt(order.getOrderAmount())); + partnerRequest.setAmount(partnerAmount); + + // 设置支付者信息 + com.wechat.pay.java.service.partnerpayments.jsapi.model.Payer partnerPayer = new com.wechat.pay.java.service.partnerpayments.jsapi.model.Payer(); + partnerPayer.setSubOpenid(user.getOpenId()); + partnerRequest.setPayer(partnerPayer); + + log.info("服务商模式支付请求:spAppid={}, spMchid={}, subAppid={}, subMchid={}", + wechatConfig.getServiceAppId(), wechatConfig.getServiceMchId(), + wechatConfig.getSubAppId(), wechatConfig.getSubMchId()); + + // 创建服务商模式的支付服务 + com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService partnerJsapiService = + new com.wechat.pay.java.service.partnerpayments.jsapi.JsapiService.Builder() + .config(wxPayConfigFactory.createConfigBySubMchId(wechatConfig.getSubMchId())) + .build(); + + // 调用支付接口 + com.wechat.pay.java.service.partnerpayments.jsapi.model.PrepayResponse partnerResponse = + partnerJsapiService.prepay(partnerRequest); + + // 返回结果 + return Result.succeed(partnerResponse, order.getOrderNo()); - // 创建分账记录 - ProfitSharing profitSharing = profitSharingService.createProfitSharing(order,qrCode); } else { - settleInfo.setProfitSharing(false); - request.setSettleInfo(settleInfo); + // 普通商户模式:使用payments包下的PrepayRequest + PrepayRequest request = new PrepayRequest(); + + // 设置基本支付信息 + Amount amount = new Amount(); + amount.setTotal(Integer.parseInt(order.getOrderAmount())); + request.setAmount(amount); + + request.setAppid(wechatConfig.getAppId()); + request.setMchid(wechatConfig.getMerchantId()); + request.setDescription(qrCode.getName()); + request.setNotifyUrl(wechatConfig.getNotifyUrl()); + request.setOutTradeNo(order.getOrderNo()); + + // 设置支付者信息 + Payer payer = new Payer(); + payer.setOpenid(user.getOpenId()); + request.setPayer(payer); + + // 创建普通商户模式的支付服务 + JsapiServiceExtension jsapiService = wxPayConfigFactory.createJsapiService(qrCode.getTenantId()); + + // 调用支付接口 + PrepayWithRequestPaymentResponse response = jsapiService.prepayWithRequestPayment(request); + + // 返回结果 + return Result.succeed(response, order.getOrderNo()); } - - // 5. 调用支付接口 - PrepayWithRequestPaymentResponse response = wxPayConfigFactory.createJsapiService(qrCode.getTenantId()).prepayWithRequestPayment(request); - - // 6. 返回结果 - return Result.succeed(response, order.getOrderNo()); } catch (Exception e) { log.error("创建预支付订单失败", e); return Result.failed("创建预支付订单失败:" + e.getMessage()); } } - /** - * 检查是否开启分润 - */ - private boolean isEnableProfit(QrCode qrCode) { - return qrCode != null && - Integer.valueOf(1).equals(qrCode.getEnableProfit()) && - qrCode.getPayeeStatus() != null && - qrCode.getPayeeStatus() == 1 && // 确保分账账号已验证 - qrCode.getPayeeAccount() != null && // 确保有收款账号 - qrCode.getProfitRate() != null; // 确保有分润比例 - } - @Operation(summary = "获取排队总览信息") @GetMapping("/queue/info") public Result getQueueInfo(@RequestParam String codeId) { diff --git a/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/central/wechat/config/WechatAutoConfiguration.java b/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/central/wechat/config/WechatAutoConfiguration.java index 174e34e6..1f648c01 100644 --- a/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/central/wechat/config/WechatAutoConfiguration.java +++ b/zlt-commons/zlt-wechat-spring-boot-starter/src/main/java/com/central/wechat/config/WechatAutoConfiguration.java @@ -5,7 +5,6 @@ import cn.binarywang.wx.miniapp.api.impl.WxMaServiceImpl; import cn.binarywang.wx.miniapp.config.impl.WxMaDefaultConfigImpl; import com.central.wechat.entity.WechatConfig; import com.central.wechat.feign.WechatConfigService; -import com.wechat.pay.java.service.payments.jsapi.model.SettleInfo; import lombok.extern.slf4j.Slf4j; import me.chanjar.weixin.mp.api.WxMpService; import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl; @@ -47,7 +46,7 @@ public class WechatAutoConfiguration { @ConditionalOnBean(WechatConfigService.class) public WxMaService wxMaService(WechatConfigService configService) { log.info("WxMaService(小程序通知)被加载,tenantId:{}", getCurrentTenantId()); - WechatConfig wechatConfig = configService.getConfig("PAY", getCurrentTenantId()); + WechatConfig wechatConfig = configService.getConfig("MA", getCurrentTenantId()); WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); config.setAppid(wechatConfig.getAppId()); config.setSecret(wechatConfig.getAppSecret()); @@ -64,15 +63,6 @@ public class WechatAutoConfiguration { return new WxPayConfigFactory(); } - @Bean - @ConditionalOnBean(WechatConfigService.class) - public SettleInfo settleInfo(WechatConfigService configService) { - WechatConfig config = configService.getConfig("PAY", getCurrentTenantId()); - SettleInfo settleInfo = new SettleInfo(); - settleInfo.setProfitSharing(config.getProfitSharingEnabled()); - return settleInfo; - } - private String getCurrentTenantId() { return defaultTenantId; }