|
@@ -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<PayOrderUnifiedRespDTO> 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);
|
|
|
|
+ }
|
|
|
|
+}
|