diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java index 421dbfe7d..9488c82c0 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/PayClientFactoryImpl.java @@ -4,10 +4,7 @@ import cn.hutool.core.lang.Assert; import cn.iocoder.yudao.framework.pay.core.client.PayClient; import cn.iocoder.yudao.framework.pay.core.client.PayClientConfig; import cn.iocoder.yudao.framework.pay.core.client.PayClientFactory; -import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPayClientConfig; -import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayPcPayClient; -import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayQrPayClient; -import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.AlipayWapPayClient; +import cn.iocoder.yudao.framework.pay.core.client.impl.alipay.*; import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXLitePayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXNativePayClient; import cn.iocoder.yudao.framework.pay.core.client.impl.wx.WXPayClientConfig; @@ -71,6 +68,7 @@ public class PayClientFactoryImpl implements PayClientFactory { case ALIPAY_QR: return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); case ALIPAY_APP: return (AbstractPayClient) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config); case ALIPAY_PC: return (AbstractPayClient) new AlipayPcPayClient(channelId, (AlipayPayClientConfig) config); + case ALIPAY_BAR: return (AbstractPayClient) new AlipayBarPayClient(channelId, (AlipayPayClientConfig) config); } // 创建失败,错误日志 + 抛出异常 log.error("[createPayClient][配置({}) 找不到合适的客户端实现]", config); diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java new file mode 100644 index 000000000..85087ab77 --- /dev/null +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayBarPayClient.java @@ -0,0 +1,66 @@ +package cn.iocoder.yudao.framework.pay.core.client.impl.alipay; + +import cn.hutool.core.util.StrUtil; +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 cn.iocoder.yudao.framework.pay.core.enums.PayDisplayModeEnum; +import com.alipay.api.AlipayApiException; +import com.alipay.api.domain.AlipayTradePayModel; +import com.alipay.api.request.AlipayTradePayRequest; +import com.alipay.api.response.AlipayTradePayResponse; +import lombok.extern.slf4j.Slf4j; + +import static cn.iocoder.yudao.framework.common.util.json.JsonUtils.toJsonString; + +/** + * 支付宝【条码支付】的 PayClient 实现类 + * + * 文档:https://opendocs.alipay.com/open/194/105072 + * + * @author 芋道源码 + */ +@Slf4j +public class AlipayBarPayClient extends AbstractAlipayClient { + + public AlipayBarPayClient(Long channelId, AlipayPayClientConfig config) { + super(channelId, PayChannelEnum.ALIPAY_BAR.getCode(), config, + new AlipayPayCodeMapping()); + } + + @Override + public PayCommonResult doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) { + // 1.1 构建 AlipayTradePayModel 请求 + AlipayTradePayModel model = new AlipayTradePayModel(); + // ① 通用的参数 + model.setOutTradeNo(reqDTO.getMerchantOrderId()); + model.setSubject(reqDTO.getSubject()); + model.setBody(reqDTO.getBody()); + model.setTotalAmount(formatAmount(reqDTO.getAmount())); + model.setScene("bar_code"); // 当面付条码支付场景 + // ② 个性化的参数【无】 + // ③ 支付宝条码支付只有一种展示 + String displayMode = PayDisplayModeEnum.BAR_CODE.getMode(); + + // 1.2 构建 AlipayTradePayRequest 请求 + AlipayTradePayRequest request = new AlipayTradePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(reqDTO.getNotifyUrl()); + request.setReturnUrl(reqDTO.getReturnUrl()); // TODO 芋艿,待搞 + + // 2.1 执行请求 + AlipayTradePayResponse response; + try { + response = client.execute(request); + } catch (AlipayApiException e) { + log.error("[unifiedOrder][request({}) 发起支付失败]", toJsonString(reqDTO), e); + return PayCommonResult.build(e.getErrCode(), e.getErrMsg(), null, codeMapping); + } + // 2.2 处理结果 + PayOrderUnifiedRespDTO respDTO = new PayOrderUnifiedRespDTO() + .setDisplayMode(displayMode).setDisplayContent(response.getCode()); + return PayCommonResult.build(StrUtil.blankToDefault(response.getCode(),"10000"), + response.getMsg(), respDTO, codeMapping); + } +} diff --git a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java index 0754f9dae..c6528ae87 100644 --- a/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java +++ b/yudao-framework/yudao-spring-boot-starter-biz-pay/src/main/java/cn/iocoder/yudao/framework/pay/core/enums/PayChannelEnum.java @@ -25,7 +25,8 @@ public enum PayChannelEnum { ALIPAY_PC("alipay_pc", "支付宝 PC 网站支付", AlipayPayClientConfig.class), ALIPAY_WAP("alipay_wap", "支付宝 Wap 网站支付", AlipayPayClientConfig.class), ALIPAY_APP("alipay_app", "支付宝App 支付", AlipayPayClientConfig.class), - ALIPAY_QR("alipay_qr", "支付宝扫码支付", AlipayPayClientConfig.class); + ALIPAY_QR("alipay_qr", "支付宝扫码支付", AlipayPayClientConfig.class), + ALIPAY_BAR("alipay_bar", "支付宝条码支付", AlipayPayClientConfig.class); /** * 编码 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 index 70cbd697e..a889cef33 100644 --- 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 @@ -17,6 +17,7 @@ public enum PayDisplayModeEnum { FORM("form"), // HTML 表单提交 QR_CODE("qr_code"), // 二维码的文字内容 QR_CODE_URL("qr_code_url"), // 二维码的图片链接 + BAR_CODE("bar_code"), // 条形码 ; /** diff --git a/yudao-ui-admin/src/assets/images/pay/icon/alipay_bar.svg b/yudao-ui-admin/src/assets/images/pay/icon/alipay_bar.svg new file mode 100644 index 000000000..eb1e1e848 --- /dev/null +++ b/yudao-ui-admin/src/assets/images/pay/icon/alipay_bar.svg @@ -0,0 +1,2 @@ + diff --git a/yudao-ui-admin/src/utils/constants.js b/yudao-ui-admin/src/utils/constants.js index 317bcaba6..10819e385 100644 --- a/yudao-ui-admin/src/utils/constants.js +++ b/yudao-ui-admin/src/utils/constants.js @@ -148,6 +148,10 @@ export const PayChannelEnum = { "code": "alipay_qr", "name": "支付宝扫码支付" }, + ALIPAY_BAR: { + "code": "alipay_bar", + "name": "支付宝条码支付" + }, } /** diff --git a/yudao-ui-admin/src/views/pay/app/index.vue b/yudao-ui-admin/src/views/pay/app/index.vue index 21a2c2d78..723d85cb5 100644 --- a/yudao-ui-admin/src/views/pay/app/index.vue +++ b/yudao-ui-admin/src/views/pay/app/index.vue @@ -53,11 +53,6 @@ - - - + + + diff --git a/yudao-ui-admin/src/views/pay/order/submit.vue b/yudao-ui-admin/src/views/pay/order/submit.vue index 80021be23..5dcfbf783 100644 --- a/yudao-ui-admin/src/views/pay/order/submit.vue +++ b/yudao-ui-admin/src/views/pay/order/submit.vue @@ -82,6 +82,7 @@ export default { alipay_app: require("@/assets/images/pay/icon/alipay_app.svg"), alipay_wap: require("@/assets/images/pay/icon/alipay_wap.svg"), alipay_pc: require("@/assets/images/pay/icon/alipay_pc.svg"), + alipay_bar: require("@/assets/images/pay/icon/alipay_bar.svg"), wx_app: require("@/assets/images/pay/icon/wx_app.svg"), wx_lite: require("@/assets/images/pay/icon/wx_lite.svg"), wx_pub: require("@/assets/images/pay/icon/wx_pub.svg"), @@ -102,6 +103,11 @@ export default { form: { // 展示形式:form html: '', }, + barCode: { // 展示形式:条形码 + value: '', + title: '', + visible: false, + }, }; }, created() { @@ -155,6 +161,16 @@ export default { }, /** 提交支付 */ submit(channelCode) { + // 条形码支付,需要特殊处理 + if (channelCode === PayChannelEnum.ALIPAY_BAR.code) { + + return; + } + + // 默认的提交处理 + this.submit0(channelCode) + }, + submit0(channelCode) { this.submitLoading = true submitOrder({ id: this.id,