pay: 新增支付宝 App 支付的接入

This commit is contained in:
YunaiV 2023-02-19 23:37:29 +08:00
parent 2093c3bdb5
commit 4390e28eea
5 changed files with 60 additions and 7 deletions

View File

@ -66,7 +66,7 @@ public class PayClientFactoryImpl implements PayClientFactory {
case WX_NATIVE: return (AbstractPayClient<Config>) new WXNativePayClient(channelId, (WXPayClientConfig) config);
case ALIPAY_WAP: return (AbstractPayClient<Config>) new AlipayWapPayClient(channelId, (AlipayPayClientConfig) config);
case ALIPAY_QR: return (AbstractPayClient<Config>) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config);
case ALIPAY_APP: return (AbstractPayClient<Config>) new AlipayQrPayClient(channelId, (AlipayPayClientConfig) config);
case ALIPAY_APP: return (AbstractPayClient<Config>) new AlipayAppPayClient(channelId, (AlipayPayClientConfig) config);
case ALIPAY_PC: return (AbstractPayClient<Config>) new AlipayPcPayClient(channelId, (AlipayPayClientConfig) config);
case ALIPAY_BAR: return (AbstractPayClient<Config>) new AlipayBarPayClient(channelId, (AlipayPayClientConfig) config);
}

View File

@ -1,5 +1,57 @@
package cn.iocoder.yudao.framework.pay.core.client.impl.alipay;
// TODO 芋艿待实现
public class AlipayAppPayClient {
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.AlipayTradeAppPayModel;
import com.alipay.api.request.AlipayTradeAppPayRequest;
import com.alipay.api.response.AlipayTradeAppPayResponse;
import lombok.extern.slf4j.Slf4j;
/**
* 支付宝App 支付 PayClient 实现类
*
* 文档<a href="https://opendocs.alipay.com/open/02e7gq">App 支付</a>
*
* // TODO 芋艿未详细测试因为手头没 App
*
* @author 芋道源码
*/
@Slf4j
public class AlipayAppPayClient extends AbstractAlipayClient {
public AlipayAppPayClient(Long channelId, AlipayPayClientConfig config) {
super(channelId, PayChannelEnum.ALIPAY_APP.getCode(), config);
}
@Override
public PayOrderUnifiedRespDTO doUnifiedOrder(PayOrderUnifiedReqDTO reqDTO) throws AlipayApiException {
// 1.1 构建 AlipayTradeAppPayModel 请求
AlipayTradeAppPayModel model = new AlipayTradeAppPayModel();
// 通用的参数
model.setOutTradeNo(reqDTO.getMerchantOrderId());
model.setSubject(reqDTO.getSubject());
model.setBody(reqDTO.getBody());
model.setTotalAmount(formatAmount(reqDTO.getAmount()));
model.setProductCode(" QUICK_MSECURITY_PAY"); // 销售产品码无线快捷支付产品
// 个性化的参数
// 支付宝扫码支付只有一种展示
String displayMode = PayDisplayModeEnum.APP.getMode();
// 1.2 构建 AlipayTradePrecreateRequest 请求
AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest();
request.setBizModel(model);
request.setNotifyUrl(reqDTO.getNotifyUrl());
request.setReturnUrl(reqDTO.getReturnUrl());
// 2.1 执行请求
AlipayTradeAppPayResponse response = client.execute(request);
// 2.2 处理结果
validateSuccess(response);
return new PayOrderUnifiedRespDTO()
.setDisplayMode(displayMode).setDisplayContent("");
}
}

View File

@ -18,6 +18,7 @@ public enum PayDisplayModeEnum {
QR_CODE("qr_code"), // 二维码的文字内容
QR_CODE_URL("qr_code_url"), // 二维码的图片链接
BAR_CODE("bar_code"), // 条形码
APP("app"), // 应用
;
/**

View File

@ -71,8 +71,8 @@ public class PayDemoOrderServiceImpl implements PayDemoOrderService {
spuNames.put(1L, new Object[]{"华为手机", 1});
spuNames.put(2L, new Object[]{"小米电视", 10});
spuNames.put(3L, new Object[]{"苹果手表", 100});
spuNames.put(4L, new Object[]{"华硕笔记本", 200});
spuNames.put(5L, new Object[]{"蔚来汽车", 300});
spuNames.put(4L, new Object[]{"华硕笔记本", 1000});
spuNames.put(5L, new Object[]{"蔚来汽车", 200000});
}
@Override

View File

@ -126,11 +126,11 @@ export default {
}, {
id: 4,
name: '华硕笔记本',
price: 200,
price: 1000,
}, {
id: 5,
name: '蔚来汽车',
price: 300,
price: 200000,
}]
};
},