From 77ed232e40813e6b7ac1758d880d307cc3fe115c Mon Sep 17 00:00:00 2001 From: xxm1995 Date: Tue, 12 Mar 2024 18:46:55 +0800 Subject: [PATCH] =?UTF-8?q?feat=20wap=E5=92=8Cweb=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../platform/daxpay/code/PayWayEnum.java | 5 +--- .../daxpay/service/code/UnionPayWay.java | 2 +- .../union/service/UnionPayService.java | 28 +++++++++++++++++-- .../service/sdk/union/api/UnionPayKit.java | 1 - 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayWayEnum.java b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayWayEnum.java index 33708cb1..7a41bd5b 100644 --- a/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayWayEnum.java +++ b/daxpay-single/daxpay-single-core/src/main/java/cn/bootx/platform/daxpay/code/PayWayEnum.java @@ -24,10 +24,7 @@ public enum PayWayEnum { QRCODE("qrcode", "扫码支付"), BARCODE("barcode", "付款码"), // 通用 - JSAPI("jsapi", "公众号/小程序支付"), - // 在非支付宝和微信中, 但支持这两类支付的时候, 需要进行区分 - JSAPI_WX_PAY("jsapi_wx_pay", "微信JS支付"), - JSAPI_ALI_PAY("jsapi_ali_pay", "支付宝JS支付"); + JSAPI("jsapi", "公众号/小程序支付"); /** 编码 */ private final String code; diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/UnionPayWay.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/UnionPayWay.java index 9f9ebb7c..21d627f5 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/UnionPayWay.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/code/UnionPayWay.java @@ -18,7 +18,7 @@ public class UnionPayWay { // 支付方式 private static final List PAY_WAYS = Arrays.asList(PayWayEnum.WAP, PayWayEnum.APP, PayWayEnum.WEB, - PayWayEnum.QRCODE, PayWayEnum.BARCODE); + PayWayEnum.JSAPI, PayWayEnum.QRCODE, PayWayEnum.BARCODE); /** * 根据编码获取 diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/union/service/UnionPayService.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/union/service/UnionPayService.java index f61006c9..80e3d447 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/union/service/UnionPayService.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/core/channel/union/service/UnionPayService.java @@ -4,8 +4,8 @@ import cn.bootx.platform.daxpay.code.PayWayEnum; import cn.bootx.platform.daxpay.exception.pay.PayFailureException; import cn.bootx.platform.daxpay.param.channel.UnionPayParam; import cn.bootx.platform.daxpay.param.pay.PayChannelParam; -import cn.bootx.platform.daxpay.service.code.AliPayWay; import cn.bootx.platform.daxpay.service.code.UnionPayCode; +import cn.bootx.platform.daxpay.service.code.UnionPayWay; import cn.bootx.platform.daxpay.service.common.context.PayLocal; import cn.bootx.platform.daxpay.service.common.local.PaymentContextLocal; import cn.bootx.platform.daxpay.service.core.channel.union.entity.UnionPayConfig; @@ -16,6 +16,7 @@ import cn.hutool.core.collection.CollUtil; import cn.hutool.core.date.DateUtil; import cn.hutool.core.map.MapUtil; import com.egzosn.pay.common.bean.NoticeParams; +import com.egzosn.pay.union.bean.UnionTransactionType; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -46,7 +47,7 @@ public class UnionPayService { throw new PayFailureException("云闪付未配置可用的支付方式"); } // 发起的支付类型是否在支持的范围内 - PayWayEnum payWayEnum = Optional.ofNullable(AliPayWay.findByCode(payChannelParam.getWay())) + PayWayEnum payWayEnum = Optional.ofNullable(UnionPayWay.findByCode(payChannelParam.getWay())) .orElseThrow(() -> new PayFailureException("非法的云闪付支付类型")); if (!unionPayConfig.getPayWays().contains(payWayEnum.getCode())) { throw new PayFailureException("该云闪付支付方式不可用"); @@ -75,10 +76,33 @@ public class UnionPayService { else if (payWayEnum == PayWayEnum.APP) { payBody = this.appPay(totalFee, payOrder, unionPayParam, unionPayKit); } + // web支付 + else if (payWayEnum == PayWayEnum.WEB) { + payBody = this.formPay(totalFee, payOrder, unionPayKit, UnionTransactionType.WEB); + } + // wap支付 + else if (payWayEnum == PayWayEnum.WAP) { + payBody = this.formPay(totalFee, payOrder, unionPayKit, UnionTransactionType.WAP ); + } asyncPayInfo.setPayBody(payBody); } + /** + * jsapi支付 + */ + private String formPay(BigDecimal amount, PayOrder payOrder, UnionPayKit unionPayKit, UnionTransactionType type) { + Date expiredTime = DateUtil.date(payOrder.getExpiredTime()); + + UnionPayOrder unionPayOrder = new UnionPayOrder(); + unionPayOrder.setOutTradeNo(String.valueOf(payOrder.getId())); + unionPayOrder.setSubject(payOrder.getTitle()); + unionPayOrder.setPrice(amount); + unionPayOrder.setExpirationTime(expiredTime); + unionPayOrder.setTransactionType(type); + return unionPayKit.toPay(unionPayOrder); + } + /** * APP支付 */ diff --git a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/sdk/union/api/UnionPayKit.java b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/sdk/union/api/UnionPayKit.java index 9b4e19b7..b4c7e0af 100644 --- a/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/sdk/union/api/UnionPayKit.java +++ b/daxpay-single/daxpay-single-service/src/main/java/cn/bootx/platform/daxpay/service/sdk/union/api/UnionPayKit.java @@ -555,7 +555,6 @@ public class UnionPayKit extends UnionPayService { if (SDKConstants.OK_RESP_CODE.equals(response.get(SDKConstants.param_respCode))) { // //成功,获取tn号 // String tn = (String)response.get(SDKConstants.param_tn); -// //TODO return response; } throw new PayErrorException(new PayException((String) response.get(SDKConstants.param_respCode), (String) response.get(SDKConstants.param_respMsg), response.toJSONString()));