diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedReqDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedReqDTO.java index 89bf3c1ac..e1f54f7bb 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedReqDTO.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedReqDTO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.framework.pay.core.client.dto.order; +import cn.iocoder.yudao.framework.pay.core.enums.PayDisplayModeEnum; import lombok.Data; import org.hibernate.validator.constraints.Length; import org.hibernate.validator.constraints.URL; @@ -7,6 +8,7 @@ import org.hibernate.validator.constraints.URL; import javax.validation.constraints.DecimalMin; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.awt.*; import java.time.LocalDateTime; import java.util.Map; @@ -78,4 +80,13 @@ public class PayOrderUnifiedReqDTO { */ private Map channelExtras; + /** + * 展示模式 + * + * 如果不传递,则每个支付渠道使用默认的方式 + * + * 枚举 {@link PayDisplayModeEnum} + */ + private String displayMode; + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedRespDTO.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedRespDTO.java new file mode 100644 index 000000000..ae6bed40f --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/dto/order/PayOrderUnifiedRespDTO.java @@ -0,0 +1,23 @@ +package cn.iocoder.yudao.framework.pay.core.client.dto.order; + +import lombok.AllArgsConstructor; +import lombok.Data; + +/** + * 统一下单 Response DTO + * + * @author 芋道源码 + */ +@Data +public class PayOrderUnifiedRespDTO { + + /** + * 展示模式 + */ + private String displayMode; + /** + * 展示内容 + */ + private String displayContent; + +} 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 7038de66b..1a4c2ad07 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 @@ -69,6 +69,7 @@ public abstract class AbstractPayClient implemen this.init(); } + // TODO 芋艿:后续抽取到工具类里 protected Double calculateAmount(Integer amount) { return amount / 100.0; } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java index f7101d4dc..4da7d78d0 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClient.java @@ -1,18 +1,26 @@ package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; +import cn.hutool.core.lang.Pair; +import cn.hutool.core.map.MapUtil; +import cn.hutool.core.util.ObjectUtil; import cn.hutool.core.util.StrUtil; import cn.hutool.http.Method; +import cn.iocoder.yudao.framework.common.util.collection.MapUtils; import cn.iocoder.yudao.framework.common.util.json.JsonUtils; import cn.iocoder.yudao.framework.pay.core.client.PayCommonResult; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedRespDTO; import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; -import com.alibaba.fastjson.JSONObject; +import cn.iocoder.yudao.framework.pay.core.enums.PayDisplayModeEnum; import com.alipay.api.AlipayApiException; import com.alipay.api.domain.AlipayTradePagePayModel; import com.alipay.api.request.AlipayTradePagePayRequest; import com.alipay.api.response.AlipayTradePagePayResponse; import lombok.extern.slf4j.Slf4j; +import java.util.HashMap; +import java.util.Objects; + /** * 支付宝【PC网站支付】的 PayClient 实现类 @@ -28,35 +36,72 @@ public class AlipayPcPayClient extends AbstractAlipayClient { } @Override - public PayCommonResult doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { - // 构建 AlipayTradePagePayModel 请求 + public PayCommonResult doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { + // 1.1 构建 AlipayTradePagePayModel 请求 AlipayTradePagePayModel model = new AlipayTradePagePayModel(); - // 构建 AlipayTradePagePayRequest + // ① 通用的参数 + model.setOutTradeNo(reqDTO.getMerchantOrderId()); + model.setSubject(reqDTO.getSubject()); + model.setTotalAmount(String.valueOf(calculateAmount(reqDTO.getAmount()))); + model.setProductCode("FAST_INSTANT_TRADE_PAY"); // 销售产品码. 目前电脑支付场景下仅支持 FAST_INSTANT_TRADE_PAY + // ② 个性化的参数 + // 参考 https://www.pingxx.com/api/支付渠道 extra 参数说明.html 的 alipay_pc_direct 部分 + model.setQrPayMode(MapUtil.getStr(reqDTO.getChannelExtras(), "qr_pay_mode")); + model.setQrcodeWidth(MapUtil.getLong(reqDTO.getChannelExtras(), "qr_code_width")); + // ③ 支付宝 PC 支付有多种展示模式,因此这里需要计算 + String displayMode = getDisplayMode(reqDTO.getDisplayMode(), model.getQrPayMode()); + + // 1.2 构建 AlipayTradePagePayRequest 请求 AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); request.setBizModel(model); - JSONObject bizContent = new JSONObject(); - // 参数说明可查看: https://opendocs.alipay.com/open/028r8t?scene=22 - bizContent.put("out_trade_no", reqDTO.getMerchantOrderId()); - bizContent.put("subject", reqDTO.getSubject()); - bizContent.put("total_amount", calculateAmount(reqDTO.getAmount())); - bizContent.put("product_code", "FAST_INSTANT_TRADE_PAY"); // 销售产品码. 目前电脑支付场景下仅支持 FAST_INSTANT_TRADE_PAY - // PC扫码支付的方式:支持前置模式和跳转模式。4: 订单码-可定义宽度的嵌入式二维码 -// bizContent.put("qr_pay_mode", "4"); - // 自定义二维码宽度 -// bizContent.put("qrcode_width", "150"); - request.setBizContent(bizContent.toJSONString()); request.setNotifyUrl(reqDTO.getNotifyUrl()); - request.setReturnUrl(""); - // 执行请求 + request.setReturnUrl(""); // TODO 芋艿,待搞 + + // 2.1 执行请求 AlipayTradePagePayResponse response; try { - response = client.pageExecute(request, Method.GET.name()); + if (Objects.equals(displayMode, PayDisplayModeEnum.FORM.getMode())) { + response = client.pageExecute(request, Method.POST.name()); // 需要特殊使用 POST 请求 + } else { + response = client.pageExecute(request, Method.GET.name()); + } } catch (AlipayApiException e) { log.error("[unifiedOrder][request({}) 发起支付失败]", JsonUtils.toJsonString(reqDTO), e); return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); } + // 1. form + // 2. url + // 3. code + // 4. code url + + // 2.2 处理结果 System.out.println(response.getBody()); + PayOrderUnifiedRespDTO respDTO = new PayOrderUnifiedRespDTO() + .setDisplayMode(displayMode).setDisplayContent(response.getBody()); // 响应为表单格式,前端可嵌入响应的页面或关闭当前支付窗口 - return PayCommonResult.build(StrUtil.blankToDefault(response.getCode(),"10000") ,response.getMsg(), response, codeMapping); + return PayCommonResult.build(StrUtil.blankToDefault(response.getCode(),"10000"), + response.getMsg(), respDTO, codeMapping); } + + /** + * 获得最终的支付 UI 展示模式 + * + * @param displayMode 前端传递的 UI 展示模式 + * @param qrPayMode 前端传递的二维码模式 + * @return 最终的支付 UI 展示模式 + */ + private String getDisplayMode(String displayMode, String qrPayMode) { + // 1.1 支付宝二维码的前置模式 + if (StrUtil.equalsAny(qrPayMode, "0", "1", "3", "4")) { + return PayDisplayModeEnum.IFRAME.getMode(); + } + // 1.2 支付宝二维码的跳转模式 + if (StrUtil.equals(qrPayMode, "2")) { + return PayDisplayModeEnum.URL.getMode(); + } + // 2. 前端传递了 UI 展示模式 + return displayMode != null ? displayMode : + PayDisplayModeEnum.URL.getMode(); // 模式使用 URL 跳转 + } + } diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayDisplayModeEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayDisplayModeEnum.java new file mode 100644 index 000000000..70cbd697e --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayDisplayModeEnum.java @@ -0,0 +1,27 @@ +package cn.iocoder.yudao.framework.pay.core.enums; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 支付 UI 展示模式 + * + * @author 芋道源码 + */ +@Getter +@AllArgsConstructor +public enum PayDisplayModeEnum { + + URL("url"), // Redirect 跳转链接的方式 + IFRAME("iframe"), // IFrame 内嵌链接的方式 + FORM("form"), // HTML 表单提交 + QR_CODE("qr_code"), // 二维码的文字内容 + QR_CODE_URL("qr_code_url"), // 二维码的图片链接 + ; + + /** + * 展示模式 + */ + private final String mode; + +} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java index be908a048..09c24c4a8 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/PayOrderController.java @@ -2,9 +2,13 @@ package cn.iocoder.yudao.module.pay.controller.admin.order; import cn.hutool.core.collection.CollectionUtil; import cn.hutool.core.util.ObjectUtil; +import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.framework.common.pojo.PageResult; +import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; +import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; +import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; +import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*; -import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitReqVO; -import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO; import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayAppDO; import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayMerchantDO; @@ -14,16 +18,9 @@ import cn.iocoder.yudao.module.pay.service.merchant.PayAppService; import cn.iocoder.yudao.module.pay.service.merchant.PayMerchantService; import cn.iocoder.yudao.module.pay.service.order.PayOrderExtensionService; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; -import cn.iocoder.yudao.framework.common.pojo.CommonResult; -import cn.iocoder.yudao.framework.common.pojo.PageResult; -import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.framework.excel.core.util.ExcelUtils; -import cn.iocoder.yudao.framework.operatelog.core.annotations.OperateLog; -import cn.iocoder.yudao.framework.pay.core.enums.PayChannelEnum; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitRespBO; -import io.swagger.v3.oas.annotations.tags.Tag; -import io.swagger.v3.oas.annotations.Parameter; import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.Parameter; +import io.swagger.v3.oas.annotations.tags.Tag; import org.springframework.security.access.prepost.PreAuthorize; import org.springframework.validation.annotation.Validated; import org.springframework.web.bind.annotation.*; @@ -94,10 +91,9 @@ public class PayOrderController { @PostMapping("/submit") @Operation(summary = "提交支付订单") - public CommonResult submitPayOrder(@RequestBody PayOrderSubmitReqVO reqVO) { - PayOrderSubmitRespBO respDTO = payOrderService.submitPayOrder( - PayOrderConvert.INSTANCE.convert(reqVO, getClientIP())); - return success(new AppPayOrderSubmitRespVO(respDTO.getInvokeResponse())); + public CommonResult submitPayOrder(@RequestBody PayOrderSubmitReqVO reqVO) { + PayOrderSubmitRespVO respVO = payOrderService.submitPayOrder(reqVO, getClientIP()); + return success(respVO); } @GetMapping("/page") diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitReqVO.java index 109bb3a9b..dac965aa0 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitReqVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitReqVO.java @@ -6,11 +6,11 @@ import lombok.experimental.Accessors; import javax.validation.constraints.NotEmpty; import javax.validation.constraints.NotNull; +import java.awt.*; import java.util.Map; @Schema(description = "管理后台 - 支付订单提交 Request VO") @Data -@Accessors(chain = true) public class PayOrderSubmitReqVO { @Schema(description = "支付单编号", required = true, example = "1024") @@ -24,4 +24,6 @@ public class PayOrderSubmitReqVO { @Schema(description = "支付渠道的额外参数,例如说,微信公众号需要传递 openid 参数") private Map channelExtras; + @Schema(description = "展示模式", example = "url") // 参见 {@link PayDisplayModeEnum} 枚举。如果不传递,则每个支付渠道使用默认的方式 + private String displayMode; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitRespVO.java index 760bb949f..162569626 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitRespVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/admin/order/vo/PayOrderSubmitRespVO.java @@ -9,15 +9,12 @@ import lombok.experimental.Accessors; @Schema(description = "管理后台 - 支付订单提交 Response VO") @Data -@Accessors(chain = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor public class PayOrderSubmitRespVO { - /** - * 调用支付渠道的响应结果 - */ - private Object invokeResponse; + @Schema(description = "展示模式", required = true, example = "url") // 参见 PayDisplayModeEnum 枚举 + private String displayMode; + + @Schema(description = "展示内容", required = true) + private String displayContent; } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.java index 786cfb8b8..24a208662 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/AppPayOrderController.java @@ -1,11 +1,11 @@ package cn.iocoder.yudao.module.pay.controller.app.order; import cn.iocoder.yudao.framework.common.pojo.CommonResult; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO; import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitReqVO; import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO; import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; import cn.iocoder.yudao.module.pay.service.order.PayOrderService; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitRespBO; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.extern.slf4j.Slf4j; @@ -33,9 +33,8 @@ public class AppPayOrderController { @PostMapping("/submit") @Operation(summary = "提交支付订单") public CommonResult submitPayOrder(@RequestBody AppPayOrderSubmitReqVO reqVO) { - PayOrderSubmitRespBO respDTO = orderService.submitPayOrder( - PayOrderConvert.INSTANCE.convert(reqVO, getClientIP())); - return success(new AppPayOrderSubmitRespVO(respDTO.getInvokeResponse())); + PayOrderSubmitRespVO respVO = orderService.submitPayOrder(reqVO, getClientIP()); + return success(PayOrderConvert.INSTANCE.convert3(respVO)); } } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitReqVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitReqVO.java index 38f19c735..8f18c6cec 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitReqVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitReqVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.pay.controller.app.order.vo; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitReqVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.Data; import lombok.experimental.Accessors; @@ -10,18 +11,5 @@ import java.util.Map; @Schema(description = "用户 APP - 支付订单提交 Request VO") @Data -@Accessors(chain = true) -public class AppPayOrderSubmitReqVO { - - @Schema(description = "支付单编号", required = true, example = "1024") - @NotNull(message = "支付单编号不能为空") - private Long id; - - @Schema(description = "支付渠道", required = true, example = "wx_pub") - @NotEmpty(message = "支付渠道不能为空") - private String channelCode; - - @Schema(description = "支付渠道的额外参数,例如说,微信公众号需要传递 openid 参数") - private Map channelExtras; - +public class AppPayOrderSubmitReqVO extends PayOrderSubmitReqVO { } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitRespVO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitRespVO.java index 1eb4a852d..106535efd 100644 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitRespVO.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/controller/app/order/vo/AppPayOrderSubmitRespVO.java @@ -1,5 +1,6 @@ package cn.iocoder.yudao.module.pay.controller.app.order.vo; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO; import io.swagger.v3.oas.annotations.media.Schema; import lombok.AllArgsConstructor; import lombok.Builder; @@ -9,15 +10,6 @@ import lombok.experimental.Accessors; @Schema(description = "用户 APP - 支付订单提交 Response VO") @Data -@Accessors(chain = true) -@Builder -@NoArgsConstructor -@AllArgsConstructor -public class AppPayOrderSubmitRespVO { - - /** - * 调用支付渠道的响应结果 - */ - private Object invokeResponse; +public class AppPayOrderSubmitRespVO extends PayOrderSubmitRespVO { } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java index 0fb0e376c..825b8e740 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/convert/order/PayOrderConvert.java @@ -2,13 +2,14 @@ package cn.iocoder.yudao.module.pay.convert.order; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedRespDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderRespDTO; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.*; import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitReqVO; +import cn.iocoder.yudao.module.pay.controller.app.order.vo.AppPayOrderSubmitRespVO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderExtensionDO; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitReqBO; import org.mapstruct.Mapper; import org.mapstruct.Mapping; import org.mapstruct.factory.Mappers; @@ -29,6 +30,8 @@ public interface PayOrderConvert { PayOrderRespVO convert(PayOrderDO bean); + PayOrderRespDTO convert2(PayOrderDO order); + PayOrderDetailsRespVO orderDetailConvert(PayOrderDO bean); PayOrderDetailsRespVO.PayOrderExtension orderDetailExtensionConvert(PayOrderExtensionDO bean); @@ -86,18 +89,15 @@ public interface PayOrderConvert { return payOrderExcelVO; } - PayOrderDO convert(PayOrderCreateReqDTO bean); @Mapping(target = "id", ignore = true) - PayOrderExtensionDO convert(PayOrderSubmitReqBO bean); + PayOrderExtensionDO convert(PayOrderSubmitReqVO bean, String userIp); - PayOrderUnifiedReqDTO convert2(PayOrderSubmitReqBO bean); + PayOrderUnifiedReqDTO convert2(PayOrderSubmitReqVO reqVO); - PayOrderRespDTO convert2(PayOrderDO bean); + PayOrderSubmitRespVO convert(PayOrderUnifiedRespDTO bean); - PayOrderSubmitReqBO convert(AppPayOrderSubmitReqVO bean, String userIp); - - PayOrderSubmitReqBO convert(PayOrderSubmitReqVO bean, String userIp); + AppPayOrderSubmitRespVO convert3(PayOrderSubmitRespVO bean); } diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java index d03987300..c550fa179 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderService.java @@ -1,16 +1,17 @@ package cn.iocoder.yudao.module.pay.service.order; -import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; -import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO; -import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO; import cn.iocoder.yudao.framework.common.pojo.PageResult; import cn.iocoder.yudao.framework.common.util.collection.CollectionUtils; -import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; +import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitReqBO; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitRespBO; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitReqVO; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO; +import cn.iocoder.yudao.module.pay.dal.dataobject.order.PayOrderDO; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import java.util.Collection; import java.util.List; import java.util.Map; @@ -81,10 +82,12 @@ public interface PayOrderService { * 提交支付 * 此时,会发起支付渠道的调用 * - * @param reqDTO 提交请求 + * @param reqVO 提交请求 + * @param userIp 提交 IP * @return 提交结果 */ - PayOrderSubmitRespBO submitPayOrder(@Valid PayOrderSubmitReqBO reqDTO); + PayOrderSubmitRespVO submitPayOrder(@Valid PayOrderSubmitReqVO reqVO, + @NotEmpty(message = "提交 IP 不能为空") String userIp); /** * 通知支付单成功 diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java index f41a6b542..a6a68390b 100755 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java +++ b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/PayOrderServiceImpl.java @@ -12,10 +12,13 @@ import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayNotifyDataDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.notify.PayOrderNotifyRespDTO; import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedReqDTO; +import cn.iocoder.yudao.framework.pay.core.client.dto.order.PayOrderUnifiedRespDTO; import cn.iocoder.yudao.framework.tenant.core.util.TenantUtils; import cn.iocoder.yudao.module.pay.api.order.dto.PayOrderCreateReqDTO; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderExportReqVO; import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderPageReqVO; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitReqVO; +import cn.iocoder.yudao.module.pay.controller.admin.order.vo.PayOrderSubmitRespVO; import cn.iocoder.yudao.module.pay.convert.order.PayOrderConvert; import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayAppDO; import cn.iocoder.yudao.module.pay.dal.dataobject.merchant.PayChannelDO; @@ -31,8 +34,6 @@ import cn.iocoder.yudao.module.pay.service.merchant.PayAppService; import cn.iocoder.yudao.module.pay.service.merchant.PayChannelService; import cn.iocoder.yudao.module.pay.service.notify.PayNotifyService; import cn.iocoder.yudao.module.pay.service.notify.dto.PayNotifyTaskCreateReqDTO; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitReqBO; -import cn.iocoder.yudao.module.pay.service.order.bo.PayOrderSubmitRespBO; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -126,22 +127,22 @@ public class PayOrderServiceImpl implements PayOrderService { } @Override - public PayOrderSubmitRespBO submitPayOrder(PayOrderSubmitReqBO reqBO) { + public PayOrderSubmitRespVO submitPayOrder(PayOrderSubmitReqVO reqVO, String userIp) { // 1. 获得 PayOrderDO ,并校验其是否存在 - PayOrderDO order = validatePayOrderCanSubmit(reqBO.getId()); + PayOrderDO order = validatePayOrderCanSubmit(reqVO.getId()); // 1.2 校验支付渠道是否有效 - PayChannelDO channel = validatePayChannelCanSubmit(order.getAppId(), reqBO.getChannelCode()); + PayChannelDO channel = validatePayChannelCanSubmit(order.getAppId(), reqVO.getChannelCode()); PayClient client = payClientFactory.getPayClient(channel.getId()); // 2. 插入 PayOrderExtensionDO - PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqBO) + PayOrderExtensionDO orderExtension = PayOrderConvert.INSTANCE.convert(reqVO, userIp) .setOrderId(order.getId()).setNo(generateOrderExtensionNo()) .setChannelId(channel.getId()).setChannelCode(channel.getCode()) .setStatus(PayOrderStatusEnum.WAITING.getStatus()); orderExtensionMapper.insert(orderExtension); // 3. 调用三方接口 - PayOrderUnifiedReqDTO unifiedOrderReqDTO = PayOrderConvert.INSTANCE.convert2(reqBO) + PayOrderUnifiedReqDTO unifiedOrderReqDTO = PayOrderConvert.INSTANCE.convert2(reqVO) // 商户相关的字段 .setMerchantOrderId(orderExtension.getNo()) // 注意,此处使用的是 PayOrderExtensionDO.no 属性! .setSubject(order.getSubject()).setBody(order.getBody()) @@ -152,10 +153,11 @@ public class PayOrderServiceImpl implements PayOrderService { CommonResult unifiedOrderResult = client.unifiedOrder(unifiedOrderReqDTO); unifiedOrderResult.checkError(); + PayOrderUnifiedRespDTO xx = (PayOrderUnifiedRespDTO) unifiedOrderResult.getData(); + // TODO 轮询三方接口,是否已经支付的任务 // 返回成功 - return new PayOrderSubmitRespBO().setExtensionId(orderExtension.getId()) - .setInvokeResponse(unifiedOrderResult.getData()); + return PayOrderConvert.INSTANCE.convert(xx); } private PayOrderDO validatePayOrderCanSubmit(Long id) { diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/bo/PayOrderSubmitReqBO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/bo/PayOrderSubmitReqBO.java deleted file mode 100644 index 13e49c80c..000000000 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/bo/PayOrderSubmitReqBO.java +++ /dev/null @@ -1,41 +0,0 @@ -package cn.iocoder.yudao.module.pay.service.order.bo; - -import lombok.Data; -import lombok.experimental.Accessors; - -import javax.validation.constraints.NotEmpty; -import javax.validation.constraints.NotNull; -import java.io.Serializable; -import java.util.Map; - -/** - * 支付单提交 Request BO - */ -@Data -@Accessors(chain = true) -public class PayOrderSubmitReqBO implements Serializable { - - /** - * 支付单编号 - */ - @NotNull(message = "支付单编号不能为空") - private Long id; - - /** - * 支付渠道 - */ - @NotEmpty(message = "支付渠道不能为空") - private String channelCode; - - /** - * 用户 IP - */ - @NotEmpty(message = "用户 IP 不能为空") - private String userIp; - - /** - * 支付渠道的额外参数 - */ - private Map channelExtras; - -} diff --git a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/bo/PayOrderSubmitRespBO.java b/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/bo/PayOrderSubmitRespBO.java deleted file mode 100644 index 9472d8038..000000000 --- a/yudao-module-pay/yudao-module-pay-biz/src/main/java/cn/iocoder/yudao/module/pay/service/order/bo/PayOrderSubmitRespBO.java +++ /dev/null @@ -1,23 +0,0 @@ -package cn.iocoder.yudao.module.pay.service.order.bo; - -import lombok.Data; - -import java.io.Serializable; - -/** - * 支付单提交 Response BO - */ -@Data -public class PayOrderSubmitRespBO implements Serializable { - - /** - * 支付拓展单的编号 - */ - private Long extensionId; - - /** - * 调用支付渠道的响应结果 - */ - private Object invokeResponse; - -} diff --git a/yudao-ui-admin/src/utils/constants.js b/yudao-ui-admin/src/utils/constants.js index e8147510f..fee84a59a 100644 --- a/yudao-ui-admin/src/utils/constants.js +++ b/yudao-ui-admin/src/utils/constants.js @@ -150,6 +150,18 @@ export const PayChannelEnum = { }, } +/** + * 支付的展示模式每局 + */ +export const PayDisplayModeEnum = { + URL: { + "mode": "url", + }, + IFRAME: { + "mode": "iframe", + }, +} + /** * 支付类型枚举 */ diff --git a/yudao-ui-admin/src/views/pay/order/submit.vue b/yudao-ui-admin/src/views/pay/order/submit.vue index 032ff2375..7e8849ee1 100644 --- a/yudao-ui-admin/src/views/pay/order/submit.vue +++ b/yudao-ui-admin/src/views/pay/order/submit.vue @@ -12,7 +12,6 @@ - @@ -42,12 +41,18 @@ - + + + +