From e6f414b918c8661adebe7622156e5604b3e137db Mon Sep 17 00:00:00 2001 From: YunaiV Date: Sat, 18 Feb 2023 22:40:56 +0800 Subject: [PATCH] =?UTF-8?q?pay:=20=E6=8E=A5=E5=85=A5=E6=94=AF=E4=BB=98?= =?UTF-8?q?=E5=AE=9D=20Wap=20=E6=94=AF=E4=BB=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../core/client/impl/AbstractPayClient.java | 23 ++++++-- .../impl/alipay/AbstractAlipayClient.java | 2 +- .../client/impl/alipay/AlipayPcPayClient.java | 19 +++---- .../client/impl/alipay/AlipayQrPayClient.java | 2 +- .../impl/alipay/AlipayWapPayClient.java | 57 +++++++++---------- yudao-ui-admin/src/utils/constants.js | 3 + yudao-ui-admin/src/views/pay/order/submit.vue | 55 ++++++++++-------- 7 files changed, 89 insertions(+), 72 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java index 1a4c2ad07..b94c57c50 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/AbstractPayClient.java @@ -1,5 +1,10 @@ package cn.iocoder.yudao.framework.pay.core.client.impl; +import cn.hutool.core.date.DatePattern; +import cn.hutool.core.date.DateUtil; +import cn.hutool.core.date.LocalDateTimeUtil; +import cn.iocoder.yudao.framework.common.util.date.DateUtils; +import cn.iocoder.yudao.framework.common.util.date.LocalDateTimeUtils; import cn.iocoder.yudao.framework.pay.core.client.AbstractPayCodeMapping; import cn.iocoder.yudao.framework.pay.core.client.PayClient; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; @@ -11,6 +16,9 @@ import lombok.extern.slf4j.Slf4j; import javax.validation.Validation; +import java.time.LocalDateTime; + +import static cn.hutool.core.date.DatePattern.NORM_DATETIME_MS_FORMATTER; import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; /** @@ -69,11 +77,6 @@ public abstract class AbstractPayClient implemen this.init(); } - // TODO 芋艿:后续抽取到工具类里 - protected Double calculateAmount(Integer amount) { - return amount / 100.0; - } - @Override public Long getId() { return channelId; @@ -113,4 +116,14 @@ public abstract class AbstractPayClient implemen protected abstract PayCommonResult doUnifiedRefund(PayRefundUnifiedReqDTO reqDTO) throws Throwable; + + protected String formatAmount(Integer amount) { + return String.valueOf(amount / 100.0); + } + + protected String formatTime(LocalDateTime time) { + // "yyyy-MM-dd HH:mm:ss" + return LocalDateTimeUtil.format(time, NORM_DATETIME_MS_FORMATTER); + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java index 7630c9402..234011e59 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AbstractAlipayClient.java @@ -112,7 +112,7 @@ public abstract class AbstractAlipayClient extends AbstractPayClient doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { - // 构建 AlipayTradeWapPayModel 请求 + public PayCommonResult doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { + // 1.1 构建 AlipayTradeWapPayModel 请求 AlipayTradeWapPayModel model = new AlipayTradeWapPayModel(); + // ① 通用的参数 model.setOutTradeNo(reqDTO.getMerchantOrderId()); model.setSubject(reqDTO.getSubject()); model.setBody(reqDTO.getBody()); - model.setTotalAmount(calculateAmount(reqDTO.getAmount()).toString()); - model.setProductCode("QUICK_WAP_PAY"); // TODO 芋艿:这里咋整 - //TODO 芋艿:这里咋整 jason @芋艿 可以去掉吧, - // TODO 芋艿 似乎这里不用传sellerId - // https://opendocs.alipay.com/apis/api_1/alipay.trade.wap.pay - //model.setSellerId("2088102147948060"); - model.setTimeExpire(DateUtil.format(reqDTO.getExpireTime(),"yyyy-MM-dd HH:mm:ss")); - // TODO 芋艿:userIp - // 构建 AlipayTradeWapPayRequest + model.setTotalAmount(formatAmount(reqDTO.getAmount())); + model.setProductCode("QUICK_WAP_PAY"); // 销售产品码. 目前 Wap 支付场景下仅支持 QUICK_WAP_PAY + // ② 个性化的参数【无】 + // ③ 支付宝 Wap 支付只有一种展示,考虑到前端可能希望二维码扫描后,手机打开 + String displayMode = ObjectUtil.defaultIfNull(reqDTO.getDisplayMode(), + PayDisplayModeEnum.URL.getMode()); + + // 1.2 构建 AlipayTradeWapPayRequest 请求 AlipayTradeWapPayRequest request = new AlipayTradeWapPayRequest(); request.setBizModel(model); request.setNotifyUrl(reqDTO.getNotifyUrl()); - request.setReturnUrl(reqDTO.getReturnUrl()); + request.setReturnUrl(reqDTO.getReturnUrl()); // TODO 芋艿,待搞 + model.setQuitUrl(reqDTO.getReturnUrl()); // TODO 芋艿,待搞 // 执行请求 AlipayTradeWapPayResponse response; @@ -57,21 +62,11 @@ public class AlipayWapPayClient extends AbstractAlipayClient { } System.out.println(response.getBody()); - // TODO 芋艿:sub Code - if(response.isSuccess() && Objects.isNull(response.getCode()) && Objects.nonNull(response.getBody())){ - //成功alipay wap 成功 code 为 null , body 为form 表单 - return PayCommonResult.build("-9999", "Success", response, codeMapping); - }else { - return PayCommonResult.build(response.getCode(), response.getMsg(), response, codeMapping); - } + // 2.2 处理结果 + PayOrderUnifiedRespDTO respDTO = new PayOrderUnifiedRespDTO() + .setDisplayMode(displayMode).setDisplayContent(response.getBody()); + return PayCommonResult.build(StrUtil.blankToDefault(response.getCode(),"10000"), + response.getMsg(), respDTO, codeMapping); } - - - - - - - - } diff --git a/yudao-ui-admin/src/utils/constants.js b/yudao-ui-admin/src/utils/constants.js index 0d9706874..317bcaba6 100644 --- a/yudao-ui-admin/src/utils/constants.js +++ b/yudao-ui-admin/src/utils/constants.js @@ -162,6 +162,9 @@ export const PayDisplayModeEnum = { }, FORM: { "mode": "form" + }, + QR_CODE: { + "mode": "qr_code" } } diff --git a/yudao-ui-admin/src/views/pay/order/submit.vue b/yudao-ui-admin/src/views/pay/order/submit.vue index 8517ab925..80021be23 100644 --- a/yudao-ui-admin/src/views/pay/order/submit.vue +++ b/yudao-ui-admin/src/views/pay/order/submit.vue @@ -44,7 +44,7 @@ - + @@ -53,7 +53,7 @@