diff --git a/pom.xml b/pom.xml index 96a16d5f..f9228393 100644 --- a/pom.xml +++ b/pom.xml @@ -317,6 +317,12 @@ ${ruoyi-vue-plus.version} + + com.ruoyi + ruoyi-alipay + ${ruoyi-vue-plus.version} + + com.ruoyi @@ -339,6 +345,7 @@ ruoyi-yunxin ruoyi-websocket-boot ruoyi-sensitive-word + ruoyi-alipay pom diff --git a/ruoyi-admin/src/main/java/com/ijpay/alipay/AliPayApiConfig.java b/ruoyi-admin/src/main/java/com/ijpay/alipay/AliPayApiConfig.java new file mode 100644 index 00000000..3ceb8e68 --- /dev/null +++ b/ruoyi-admin/src/main/java/com/ijpay/alipay/AliPayApiConfig.java @@ -0,0 +1,400 @@ +package com.ijpay.alipay; + +import cn.hutool.core.util.StrUtil; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.CertAlipayRequest; +import com.alipay.api.DefaultAlipayClient; + +import java.io.Serializable; + +/** + *

IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。

+ * + *

不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。

+ * + *

IJPay 交流群: 723992875、864988890

+ * + *

Node.js 版: https://gitee.com/javen205/TNWXX

+ * + *

支付宝支付配置

+ * + * @author Javen + */ +public class AliPayApiConfig implements Serializable { + private static final long serialVersionUID = -4736760736935998953L; + + /** + * 应用私钥 + */ + private String privateKey; + + /** + * 支付宝公钥 + */ + private String aliPayPublicKey; + + /** + * 应用编号 + */ + private String appId; + + /** + * 支付宝支付网关 + */ + private String serviceUrl; + + /** + * 字符集,为空默认为 UTF-8 + */ + private String charset; + + /** + * 为空默认为 RSA2 + */ + private String signType; + + /** + * 为空默认为 JSON + */ + private String format; + + /** + * 是否为证书模式 + */ + private boolean certModel; + + /** + * 应用公钥证书 (证书模式必须) + */ + private String appCertPath; + + /** + * 应用公钥证书文本内容 + */ + private String appCertContent; + + /** + * 支付宝公钥证书 (证书模式必须) + */ + private String aliPayCertPath; + + /** + * 支付宝公钥证书文本内容 + */ + private String aliPayCertContent; + + /** + * 支付宝根证书 (证书模式必须) + */ + private String aliPayRootCertPath; + + /** + * 支付宝根证书文本内容 + */ + private String aliPayRootCertContent; + + /** + * 支付宝客户端 + */ + private AlipayClient alipayClient; + + /** + * 其他附加参数 + */ + private Object exParams; + + /** + * 域名 + */ + private String domain; + + private Integer proxyPort; + private String proxyIp; + + private AliPayApiConfig() { + } + + public static AliPayApiConfig builder() { + return new AliPayApiConfig(); + } + + /** + * 普通公钥方式 + * + * @return AliPayApiConfig 支付宝配置 + */ + public AliPayApiConfig build() { + this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(), + getCharset(), getAliPayPublicKey(), getSignType()); + return this; + } + + public AliPayApiConfig buildProxy() { + this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(), + getCharset(), getAliPayPublicKey(), getSignType(), getProxyIp(),getProxyPort()); + return this; + } + + /** + * 证书模式 + * + * @return AliPayApiConfig 支付宝配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig buildByCert() throws AlipayApiException { + return build(getAppCertPath(), getAliPayCertPath(), getAliPayRootCertPath()); + } + + /** + * 证书模式 + * + * @return AliPayApiConfig 支付宝配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig buildByCertContent() throws AlipayApiException { + return buildByCertContent(getAppCertContent(), getAliPayCertContent(), getAliPayRootCertContent()); + } + + /** + * @param appCertPath 应用公钥证书路径 + * @param aliPayCertPath 支付宝公钥证书文件路径 + * @param aliPayRootCertPath 支付宝CA根证书文件路径 + * @return {@link AliPayApiConfig} 支付宝支付配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig build(String appCertPath, String aliPayCertPath, String aliPayRootCertPath) throws AlipayApiException { + CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); + certAlipayRequest.setServerUrl(getServiceUrl()); + certAlipayRequest.setAppId(getAppId()); + certAlipayRequest.setPrivateKey(getPrivateKey()); + certAlipayRequest.setFormat(getFormat()); + certAlipayRequest.setCharset(getCharset()); + certAlipayRequest.setSignType(getSignType()); + certAlipayRequest.setCertPath(appCertPath); + certAlipayRequest.setAlipayPublicCertPath(aliPayCertPath); + certAlipayRequest.setRootCertPath(aliPayRootCertPath); + this.alipayClient = new DefaultAlipayClient(certAlipayRequest); + this.certModel = true; + return this; + } + + /** + * @param appCertContent 应用公钥证书 + * @param aliPayCertContent 支付宝公钥证书 + * @param aliPayRootCertContent 支付宝CA根证书 + * @return {@link AliPayApiConfig} 支付宝支付配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig buildByCertContent(String appCertContent, String aliPayCertContent, String aliPayRootCertContent) throws AlipayApiException { + CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); + certAlipayRequest.setServerUrl(getServiceUrl()); + certAlipayRequest.setAppId(getAppId()); + certAlipayRequest.setPrivateKey(getPrivateKey()); + certAlipayRequest.setFormat(getFormat()); + certAlipayRequest.setCharset(getCharset()); + certAlipayRequest.setSignType(getSignType()); + certAlipayRequest.setCertContent(appCertContent); + certAlipayRequest.setAlipayPublicCertContent(aliPayCertContent); + certAlipayRequest.setRootCertContent(aliPayRootCertContent); + this.alipayClient = new DefaultAlipayClient(certAlipayRequest); + this.certModel = true; + return this; + } + + public String getPrivateKey() { + if (StrUtil.isBlank(privateKey)) { + throw new IllegalStateException("privateKey 未被赋值"); + } + return privateKey; + } + + public AliPayApiConfig setPrivateKey(String privateKey) { + if (StrUtil.isEmpty(privateKey)) { + throw new IllegalArgumentException("privateKey 值不能为 null"); + } + this.privateKey = privateKey; + return this; + } + + public String getAliPayPublicKey() { + return aliPayPublicKey; + } + + public AliPayApiConfig setAliPayPublicKey(String aliPayPublicKey) { + this.aliPayPublicKey = aliPayPublicKey; + return this; + } + + public String getAppId() { + if (StrUtil.isEmpty(appId)) { + throw new IllegalStateException("appId 未被赋值"); + } + return appId; + } + + public AliPayApiConfig setAppId(String appId) { + if (StrUtil.isEmpty(appId)) { + throw new IllegalArgumentException("appId 值不能为 null"); + } + this.appId = appId; + return this; + } + + public String getServiceUrl() { + if (StrUtil.isEmpty(serviceUrl)) { + throw new IllegalStateException("serviceUrl 未被赋值"); + } + return serviceUrl; + } + + public AliPayApiConfig setServiceUrl(String serviceUrl) { + if (StrUtil.isEmpty(serviceUrl)) { + serviceUrl = "https://openapi.alipay.com/gateway.do"; + } + this.serviceUrl = serviceUrl; + return this; + } + + public String getCharset() { + if (StrUtil.isEmpty(charset)) { + charset = "UTF-8"; + } + return charset; + } + + public AliPayApiConfig setCharset(String charset) { + if (StrUtil.isEmpty(charset)) { + charset = "UTF-8"; + } + this.charset = charset; + return this; + } + + public String getSignType() { + if (StrUtil.isEmpty(signType)) { + signType = "RSA2"; + } + return signType; + } + + public AliPayApiConfig setSignType(String signType) { + if (StrUtil.isEmpty(signType)) { + signType = "RSA2"; + } + this.signType = signType; + return this; + } + + public String getFormat() { + if (StrUtil.isEmpty(format)) { + format = "json"; + } + return format; + } + + public String getAppCertPath() { + return appCertPath; + } + + public AliPayApiConfig setAppCertPath(String appCertPath) { + this.appCertPath = appCertPath; + return this; + } + + public String getAppCertContent() { + return appCertContent; + } + + public AliPayApiConfig setAppCertContent(String appCertContent) { + this.appCertContent = appCertContent; + return this; + } + + public String getAliPayCertPath() { + return aliPayCertPath; + } + + public AliPayApiConfig setAliPayCertPath(String aliPayCertPath) { + this.aliPayCertPath = aliPayCertPath; + return this; + } + + public String getAliPayCertContent() { + return aliPayCertContent; + } + + public AliPayApiConfig setAliPayCertContent(String aliPayCertContent) { + this.aliPayCertContent = aliPayCertContent; + return this; + } + + public String getAliPayRootCertPath() { + return aliPayRootCertPath; + } + + public AliPayApiConfig setAliPayRootCertPath(String aliPayRootCertPath) { + this.aliPayRootCertPath = aliPayRootCertPath; + return this; + } + + public String getAliPayRootCertContent() { + return aliPayRootCertContent; + } + + public AliPayApiConfig setAliPayRootCertContent(String aliPayRootCertContent) { + this.aliPayRootCertContent = aliPayRootCertContent; + return this; + } + + public boolean isCertModel() { + return certModel; + } + + public AliPayApiConfig setCertModel(boolean certModel) { + this.certModel = certModel; + return this; + } + + public AlipayClient getAliPayClient() { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient; + } + + public Object getExParams() { + return exParams; + } + + public AliPayApiConfig setExParams(Object exParams) { + this.exParams = exParams; + return this; + } + + public String getDomain() { + return domain; + } + + public AliPayApiConfig setDomain(String domain) { + this.domain = domain; + return this; + } + + + public Integer getProxyPort() { + return proxyPort; + } + + public void setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + } + + public String getProxyIp() { + return proxyIp; + } + + public void setProxyIp(String proxyIp) { + this.proxyIp = proxyIp; + } +} diff --git a/ruoyi-alipay/pom.xml b/ruoyi-alipay/pom.xml new file mode 100644 index 00000000..8c9e4750 --- /dev/null +++ b/ruoyi-alipay/pom.xml @@ -0,0 +1,53 @@ + + + 4.0.0 + + com.ruoyi + ruoyi-vue-plus + 4.8.2 + + + ruoyi-alipay + + + 8 + 8 + UTF-8 + 4.38.149.ALL + 2.0.42 + 5.8.23 + + + + + com.alipay.sdk + alipay-sdk-java + ${alipay.version} + + + fastjson + com.alibaba + + + + + javax.servlet + javax.servlet-api + 4.0.1 + provided + + + com.alibaba + fastjson + ${fastjson.version} + + + cn.hutool + hutool-crypto + ${hutool.version} + + + + diff --git a/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApi.java b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApi.java new file mode 100644 index 00000000..2e1ae87e --- /dev/null +++ b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApi.java @@ -0,0 +1,2790 @@ +package com.ijpay.alipay; + +import cn.hutool.core.date.DateUtil; +import com.alibaba.fastjson.JSONObject; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.AlipayRequest; +import com.alipay.api.AlipayResponse; +import com.alipay.api.BatchAlipayRequest; +import com.alipay.api.BatchAlipayResponse; +import com.alipay.api.domain.AlipayCommerceCityfacilitatorStationQueryModel; +import com.alipay.api.domain.AlipayCommerceCityfacilitatorVoucherBatchqueryModel; +import com.alipay.api.domain.AlipayCommerceCityfacilitatorVoucherGenerateModel; +import com.alipay.api.domain.AlipayCommerceCityfacilitatorVoucherRefundModel; +import com.alipay.api.domain.AlipayDataDataserviceBillDownloadurlQueryModel; +import com.alipay.api.domain.AlipayFundAccountQueryModel; +import com.alipay.api.domain.AlipayFundAuthOperationCancelModel; +import com.alipay.api.domain.AlipayFundAuthOperationDetailQueryModel; +import com.alipay.api.domain.AlipayFundAuthOrderFreezeModel; +import com.alipay.api.domain.AlipayFundAuthOrderUnfreezeModel; +import com.alipay.api.domain.AlipayFundAuthOrderVoucherCreateModel; +import com.alipay.api.domain.AlipayFundCouponOperationQueryModel; +import com.alipay.api.domain.AlipayFundCouponOrderAgreementPayModel; +import com.alipay.api.domain.AlipayFundCouponOrderAppPayModel; +import com.alipay.api.domain.AlipayFundCouponOrderDisburseModel; +import com.alipay.api.domain.AlipayFundCouponOrderPagePayModel; +import com.alipay.api.domain.AlipayFundCouponOrderRefundModel; +import com.alipay.api.domain.AlipayFundTransCommonQueryModel; +import com.alipay.api.domain.AlipayFundTransOrderQueryModel; +import com.alipay.api.domain.AlipayFundTransToaccountTransferModel; +import com.alipay.api.domain.AlipayFundTransUniTransferModel; +import com.alipay.api.domain.AlipayOpenAuthTokenAppModel; +import com.alipay.api.domain.AlipayOpenAuthTokenAppQueryModel; +import com.alipay.api.domain.AlipayTradeAppPayModel; +import com.alipay.api.domain.AlipayTradeCancelModel; +import com.alipay.api.domain.AlipayTradeCloseModel; +import com.alipay.api.domain.AlipayTradeCreateModel; +import com.alipay.api.domain.AlipayTradeFastpayRefundQueryModel; +import com.alipay.api.domain.AlipayTradeOrderSettleModel; +import com.alipay.api.domain.AlipayTradePagePayModel; +import com.alipay.api.domain.AlipayTradePageRefundModel; +import com.alipay.api.domain.AlipayTradePayModel; +import com.alipay.api.domain.AlipayTradePrecreateModel; +import com.alipay.api.domain.AlipayTradeQueryModel; +import com.alipay.api.domain.AlipayTradeRefundModel; +import com.alipay.api.domain.AlipayTradeRoyaltyRelationBatchqueryModel; +import com.alipay.api.domain.AlipayTradeRoyaltyRelationBindModel; +import com.alipay.api.domain.AlipayTradeRoyaltyRelationUnbindModel; +import com.alipay.api.domain.AlipayTradeWapPayModel; +import com.alipay.api.domain.ZolozAuthenticationCustomerFacemanageCreateModel; +import com.alipay.api.domain.ZolozAuthenticationCustomerFacemanageDeleteModel; +import com.alipay.api.domain.ZolozAuthenticationCustomerFtokenQueryModel; +import com.alipay.api.domain.ZolozAuthenticationCustomerSmilepayInitializeModel; +import com.alipay.api.domain.ZolozAuthenticationSmilepayInitializeModel; +import com.alipay.api.domain.ZolozIdentificationUserWebInitializeModel; +import com.alipay.api.domain.ZolozIdentificationUserWebQueryModel; +import com.alipay.api.internal.util.StringUtils; +import com.alipay.api.request.AlipayCommerceAdContractSignRequest; +import com.alipay.api.request.AlipayCommerceCityfacilitatorStationQueryRequest; +import com.alipay.api.request.AlipayCommerceCityfacilitatorVoucherBatchqueryRequest; +import com.alipay.api.request.AlipayCommerceCityfacilitatorVoucherGenerateRequest; +import com.alipay.api.request.AlipayCommerceCityfacilitatorVoucherRefundRequest; +import com.alipay.api.request.AlipayDataDataserviceBillDownloadurlQueryRequest; +import com.alipay.api.request.AlipayEbppBillGetRequest; +import com.alipay.api.request.AlipayFundAccountQueryRequest; +import com.alipay.api.request.AlipayFundAuthOperationCancelRequest; +import com.alipay.api.request.AlipayFundAuthOperationDetailQueryRequest; +import com.alipay.api.request.AlipayFundAuthOrderFreezeRequest; +import com.alipay.api.request.AlipayFundAuthOrderUnfreezeRequest; +import com.alipay.api.request.AlipayFundAuthOrderVoucherCreateRequest; +import com.alipay.api.request.AlipayFundCouponOperationQueryRequest; +import com.alipay.api.request.AlipayFundCouponOrderAgreementPayRequest; +import com.alipay.api.request.AlipayFundCouponOrderAppPayRequest; +import com.alipay.api.request.AlipayFundCouponOrderDisburseRequest; +import com.alipay.api.request.AlipayFundCouponOrderPagePayRequest; +import com.alipay.api.request.AlipayFundCouponOrderRefundRequest; +import com.alipay.api.request.AlipayFundTransCommonQueryRequest; +import com.alipay.api.request.AlipayFundTransOrderQueryRequest; +import com.alipay.api.request.AlipayFundTransToaccountTransferRequest; +import com.alipay.api.request.AlipayFundTransUniTransferRequest; +import com.alipay.api.request.AlipayOpenAuthTokenAppQueryRequest; +import com.alipay.api.request.AlipayOpenAuthTokenAppRequest; +import com.alipay.api.request.AlipayTradeAppPayRequest; +import com.alipay.api.request.AlipayTradeCancelRequest; +import com.alipay.api.request.AlipayTradeCloseRequest; +import com.alipay.api.request.AlipayTradeCreateRequest; +import com.alipay.api.request.AlipayTradeFastpayRefundQueryRequest; +import com.alipay.api.request.AlipayTradeOrderSettleRequest; +import com.alipay.api.request.AlipayTradePagePayRequest; +import com.alipay.api.request.AlipayTradePageRefundRequest; +import com.alipay.api.request.AlipayTradePayRequest; +import com.alipay.api.request.AlipayTradePrecreateRequest; +import com.alipay.api.request.AlipayTradeQueryRequest; +import com.alipay.api.request.AlipayTradeRefundRequest; +import com.alipay.api.request.AlipayTradeRoyaltyRelationBatchqueryRequest; +import com.alipay.api.request.AlipayTradeRoyaltyRelationBindRequest; +import com.alipay.api.request.AlipayTradeRoyaltyRelationUnbindRequest; +import com.alipay.api.request.AlipayTradeWapPayRequest; +import com.alipay.api.request.ZolozAuthenticationCustomerFacemanageCreateRequest; +import com.alipay.api.request.ZolozAuthenticationCustomerFacemanageDeleteRequest; +import com.alipay.api.request.ZolozAuthenticationCustomerFtokenQueryRequest; +import com.alipay.api.request.ZolozAuthenticationCustomerSmilepayInitializeRequest; +import com.alipay.api.request.ZolozAuthenticationSmilepayInitializeRequest; +import com.alipay.api.request.ZolozIdentificationUserWebInitializeRequest; +import com.alipay.api.request.ZolozIdentificationUserWebQueryRequest; +import com.alipay.api.response.AlipayCommerceAdContractSignResponse; +import com.alipay.api.response.AlipayCommerceCityfacilitatorStationQueryResponse; +import com.alipay.api.response.AlipayCommerceCityfacilitatorVoucherBatchqueryResponse; +import com.alipay.api.response.AlipayCommerceCityfacilitatorVoucherGenerateResponse; +import com.alipay.api.response.AlipayCommerceCityfacilitatorVoucherRefundResponse; +import com.alipay.api.response.AlipayDataDataserviceBillDownloadurlQueryResponse; +import com.alipay.api.response.AlipayEbppBillGetResponse; +import com.alipay.api.response.AlipayFundAccountQueryResponse; +import com.alipay.api.response.AlipayFundAuthOperationCancelResponse; +import com.alipay.api.response.AlipayFundAuthOperationDetailQueryResponse; +import com.alipay.api.response.AlipayFundAuthOrderFreezeResponse; +import com.alipay.api.response.AlipayFundAuthOrderUnfreezeResponse; +import com.alipay.api.response.AlipayFundAuthOrderVoucherCreateResponse; +import com.alipay.api.response.AlipayFundCouponOperationQueryResponse; +import com.alipay.api.response.AlipayFundCouponOrderAgreementPayResponse; +import com.alipay.api.response.AlipayFundCouponOrderAppPayResponse; +import com.alipay.api.response.AlipayFundCouponOrderDisburseResponse; +import com.alipay.api.response.AlipayFundCouponOrderPagePayResponse; +import com.alipay.api.response.AlipayFundCouponOrderRefundResponse; +import com.alipay.api.response.AlipayFundTransCommonQueryResponse; +import com.alipay.api.response.AlipayFundTransOrderQueryResponse; +import com.alipay.api.response.AlipayFundTransToaccountTransferResponse; +import com.alipay.api.response.AlipayFundTransUniTransferResponse; +import com.alipay.api.response.AlipayOpenAuthTokenAppQueryResponse; +import com.alipay.api.response.AlipayOpenAuthTokenAppResponse; +import com.alipay.api.response.AlipayTradeAppPayResponse; +import com.alipay.api.response.AlipayTradeCancelResponse; +import com.alipay.api.response.AlipayTradeCloseResponse; +import com.alipay.api.response.AlipayTradeCreateResponse; +import com.alipay.api.response.AlipayTradeFastpayRefundQueryResponse; +import com.alipay.api.response.AlipayTradeOrderSettleResponse; +import com.alipay.api.response.AlipayTradePageRefundResponse; +import com.alipay.api.response.AlipayTradePayResponse; +import com.alipay.api.response.AlipayTradePrecreateResponse; +import com.alipay.api.response.AlipayTradeQueryResponse; +import com.alipay.api.response.AlipayTradeRefundResponse; +import com.alipay.api.response.AlipayTradeRoyaltyRelationBatchqueryResponse; +import com.alipay.api.response.AlipayTradeRoyaltyRelationBindResponse; +import com.alipay.api.response.AlipayTradeRoyaltyRelationUnbindResponse; +import com.alipay.api.response.ZolozAuthenticationCustomerFacemanageCreateResponse; +import com.alipay.api.response.ZolozAuthenticationCustomerFacemanageDeleteResponse; +import com.alipay.api.response.ZolozAuthenticationCustomerFtokenQueryResponse; +import com.alipay.api.response.ZolozAuthenticationCustomerSmilepayInitializeResponse; +import com.alipay.api.response.ZolozAuthenticationSmilepayInitializeResponse; +import com.alipay.api.response.ZolozIdentificationUserWebInitializeResponse; +import com.alipay.api.response.ZolozIdentificationUserWebQueryResponse; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.OutputStream; +import java.io.PrintWriter; +import java.io.UnsupportedEncodingException; +import java.net.URLEncoder; +import java.util.Date; +import java.util.HashMap; +import java.util.Iterator; +import java.util.Map; + +/** + *

+ * IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。 + *

+ * + *

+ * 不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。 + *

+ * + *

+ * IJPay 交流群: 723992875、864988890 + *

+ * + *

+ * Node.js 版: https://gitee.com/javen205/TNWX + *

+ * + *

+ * 支付宝支付相关接口 + *

+ * + * @author Javen + */ +public class AliPayApi { + + /** + * 支付宝提供给商户的服务接入网关URL(新) + */ + private static final String GATEWAY_NEW = "https://mapi.alipay.com/gateway.do?"; + + public static T doExecute(AlipayRequest request) throws AlipayApiException { + if (AliPayApiConfigKit.getAliPayApiConfig().isCertModel()) { + return certificateExecute(request); + } else { + return execute(request); + } + } + + public static T doExecute(AlipayClient alipayClient, Boolean certModel, AlipayRequest request) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + if (certModel) { + return certificateExecute(alipayClient, request); + } else { + return execute(alipayClient, request); + } + } + + + public static T doExecute(AlipayClient alipayClient, Boolean certModel, AlipayRequest request, String authToken) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + if (certModel) { + return certificateExecute(alipayClient, request, authToken); + } else { + return execute(alipayClient, request, authToken); + } + } + + + public static T doExecute(AlipayRequest request, String authToken) throws AlipayApiException { + if (AliPayApiConfigKit.getAliPayApiConfig().isCertModel()) { + return certificateExecute(request, authToken); + } else { + return execute(request, authToken); + } + } + + + public static T doExecute(AlipayClient alipayClient, AlipayRequest request, String authToken) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + if (AliPayApiConfigKit.getAliPayApiConfig().isCertModel()) { + return certificateExecute(alipayClient, request, authToken); + } else { + return execute(alipayClient, request, authToken); + } + } + + public static T execute(AlipayRequest request) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().execute(request); + } + + + public static T execute(AlipayClient alipayClient, AlipayRequest request) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.execute(request); + } + + public static T execute(AlipayRequest request, String authToken) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().execute(request, authToken); + } + + public static T execute(AlipayClient alipayClient, AlipayRequest request, String authToken) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.execute(request, authToken); + } + + public static T execute(AlipayRequest request, String accessToken, String appAuthToken) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().execute(request, accessToken, appAuthToken); + } + + public static T execute(AlipayClient alipayClient, AlipayRequest request, String accessToken, String appAuthToken) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.execute(request, accessToken, appAuthToken); + } + + public static T execute(AlipayRequest request, String accessToken, String appAuthToken, String targetAppId) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().execute(request, accessToken, appAuthToken, targetAppId); + } + + public static T execute(AlipayClient alipayClient, AlipayRequest request, String accessToken, String appAuthToken, String targetAppId) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.execute(request, accessToken, appAuthToken, targetAppId); + } + + public static T pageExecute(AlipayRequest request) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().pageExecute(request); + } + + public static T pageExecute(AlipayClient alipayClient, AlipayRequest request) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.pageExecute(request); + } + + public static T pageExecute(AlipayRequest request, String method) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().pageExecute(request, method); + } + + public static T pageExecute(AlipayClient alipayClient, AlipayRequest request, String method) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.pageExecute(request, method); + } + + public static T sdkExecute(AlipayRequest request) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().sdkExecute(request); + } + + public static T sdkExecute(AlipayClient alipayClient, AlipayRequest request) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.sdkExecute(request); + } + + public static BatchAlipayResponse execute(BatchAlipayRequest request) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().execute(request); + } + + public static BatchAlipayResponse execute(AlipayClient alipayClient, BatchAlipayRequest request) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.execute(request); + } + + public static T certificateExecute(AlipayRequest request) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().certificateExecute(request); + } + + public static T certificateExecute(AlipayClient alipayClient, AlipayRequest request) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.certificateExecute(request); + } + + public static T certificateExecute(AlipayRequest request, String authToken) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().certificateExecute(request, authToken); + } + + public static T certificateExecute(AlipayClient alipayClient, AlipayRequest request, String authToken) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.certificateExecute(request, authToken); + } + + public static T certificateExecute(AlipayRequest request, String accessToken, String appAuthToken) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().certificateExecute(request, accessToken, appAuthToken); + } + + public static T certificateExecute(AlipayClient alipayClient, AlipayRequest request, String accessToken, String appAuthToken) throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.certificateExecute(request, accessToken, appAuthToken); + } + + public static T certificateExecute(AlipayRequest request, String accessToken, String appAuthToken, String targetAppId) throws AlipayApiException { + return AliPayApiConfigKit.getAliPayApiConfig().getAliPayClient().certificateExecute(request, accessToken, appAuthToken, targetAppId); + } + + public static T certificateExecute(AlipayClient alipayClient, AlipayRequest request, String accessToken, String appAuthToken, String targetAppId) + throws AlipayApiException { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient.certificateExecute(request, accessToken, appAuthToken, targetAppId); + } + + /** + * APP支付 + * + * @param model {@link AlipayTradeAppPayModel} + * @param notifyUrl 异步通知 URL + * @return {@link AlipayTradeAppPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeAppPayResponse appPayToResponse(AlipayTradeAppPayModel model, String notifyUrl) throws AlipayApiException { + AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return sdkExecute(request); + } + + + /** + * APP支付 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeAppPayModel} + * @param notifyUrl 异步通知 URL + * @return {@link AlipayTradeAppPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeAppPayResponse appPayToResponse(AlipayClient alipayClient, AlipayTradeAppPayModel model, String notifyUrl) throws AlipayApiException { + AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return sdkExecute(alipayClient, request); + } + + /** + * APP支付 + * + * @param model {@link AlipayTradeAppPayModel} + * @param notifyUrl 异步通知 URL + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeAppPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeAppPayResponse appPayToResponse(AlipayTradeAppPayModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + return sdkExecute(request); + } + + + /** + * APP支付 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeAppPayModel} + * @param notifyUrl 异步通知 URL + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeAppPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeAppPayResponse appPayToResponse(AlipayClient alipayClient, AlipayTradeAppPayModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradeAppPayRequest request = new AlipayTradeAppPayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + return sdkExecute(alipayClient, request); + } + + /** + * WAP支付 + * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 同步通知URL + * @param notifyUrl 异步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPay(HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl) throws AlipayApiException, IOException { + String form = wapPayStr(model, returnUrl, notifyUrl); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + + /** + * WAP支付 + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPay(AlipayClient alipayClient, HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl) throws AlipayApiException, IOException { + String form = wapPayStr(alipayClient, model, returnUrl, notifyUrl); + response.setContentType("text/html;charset=UTF-8"); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + + /** + * WAP支付 + * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPay(HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl, String appAuthToken) throws AlipayApiException, IOException { + String form = wapPayStr(model, returnUrl, notifyUrl, appAuthToken); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + + /** + * WAP支付 + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPay(AlipayClient alipayClient, HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl, String appAuthToken) throws AlipayApiException, IOException { + String form = wapPayStr(alipayClient, model, returnUrl, notifyUrl, appAuthToken); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + /** + *

+ * WAP支付 + *

+ * + *

+ * 为了解决 Filter 中使用 OutputStream getOutputStream() 和 PrintWriter getWriter() 冲突异常问题 + *

+ * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPayByOutputStream(HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl, String appAuthToken) + throws AlipayApiException, IOException { + String form = wapPayStr(model, returnUrl, notifyUrl, appAuthToken); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(AliPayApiConfigKit.getAliPayApiConfig().getCharset())); + response.getOutputStream().flush(); + } + + + /** + *

+ * WAP支付 + *

+ * + *

+ * 为了解决 Filter 中使用 OutputStream getOutputStream() 和 PrintWriter getWriter() 冲突异常问题 + *

+ * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPayByOutputStream(AlipayClient alipayClient, HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl, String appAuthToken) + throws AlipayApiException, IOException { + String form = wapPayStr(alipayClient, model, returnUrl, notifyUrl, appAuthToken); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(charset)); + response.getOutputStream().flush(); + } + + /** + *

+ * WAP支付 + *

+ * + *

+ * 为了解决 Filter 中使用 OutputStream getOutputStream() 和 PrintWriter getWriter() 冲突异常问题 + *

+ * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPayByOutputStream(HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl) throws AlipayApiException, IOException { + String form = wapPayStr(model, returnUrl, notifyUrl); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(AliPayApiConfigKit.getAliPayApiConfig().getCharset())); + response.getOutputStream().flush(); + } + + + /** + *

+ * WAP支付 + *

+ * + *

+ * 为了解决 Filter 中使用 OutputStream getOutputStream() 和 PrintWriter getWriter() 冲突异常问题 + *

+ * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void wapPayByOutputStream(AlipayClient alipayClient, HttpServletResponse response, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl) throws AlipayApiException, IOException { + String form = wapPayStr(alipayClient, model, returnUrl, notifyUrl); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(charset)); + response.getOutputStream().flush(); + } + + /** + * WAP支付 + * + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @return {String} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static String wapPayStr(AlipayTradeWapPayModel model, String returnUrl, String notifyUrl) throws AlipayApiException { + AlipayTradeWapPayRequest aliPayRequest = new AlipayTradeWapPayRequest(); + aliPayRequest.setReturnUrl(returnUrl); + aliPayRequest.setNotifyUrl(notifyUrl); + aliPayRequest.setBizModel(model); + return pageExecute(aliPayRequest).getBody(); + } + + /** + * WAP支付 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @return {String} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static String wapPayStr(AlipayClient alipayClient, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl) throws AlipayApiException { + AlipayTradeWapPayRequest aliPayRequest = new AlipayTradeWapPayRequest(); + aliPayRequest.setReturnUrl(returnUrl); + aliPayRequest.setNotifyUrl(notifyUrl); + aliPayRequest.setBizModel(model); + return pageExecute(alipayClient, aliPayRequest).getBody(); + } + + /** + * WAP支付 + * + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @param appAuthToken 应用授权token + * @return {String} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static String wapPayStr(AlipayTradeWapPayModel model, String returnUrl, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradeWapPayRequest aliPayRequest = new AlipayTradeWapPayRequest(); + aliPayRequest.setReturnUrl(returnUrl); + aliPayRequest.setNotifyUrl(notifyUrl); + aliPayRequest.setBizModel(model); + aliPayRequest.putOtherTextParam("app_auth_token", appAuthToken); + return pageExecute(aliPayRequest).getBody(); + } + + /** + * WAP支付 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeWapPayModel} + * @param returnUrl 异步通知URL + * @param notifyUrl 同步通知URL + * @param appAuthToken 应用授权token + * @return {String} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static String wapPayStr(AlipayClient alipayClient, AlipayTradeWapPayModel model, String returnUrl, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradeWapPayRequest aliPayRequest = new AlipayTradeWapPayRequest(); + aliPayRequest.setReturnUrl(returnUrl); + aliPayRequest.setNotifyUrl(notifyUrl); + aliPayRequest.setBizModel(model); + aliPayRequest.putOtherTextParam("app_auth_token", appAuthToken); + return pageExecute(alipayClient, aliPayRequest).getBody(); + } + + /** + * 统一收单交易支付接口接口
+ * 适用于:条形码支付、声波支付等
+ * + * @param model {@link AlipayTradePayModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradePayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePayResponse tradePayToResponse(AlipayTradePayModel model, String notifyUrl) throws AlipayApiException { + AlipayTradePayRequest request = new AlipayTradePayRequest(); + // 填充业务参数 + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(request); + } + + /** + * 统一收单交易支付接口接口
+ * 适用于:条形码支付、声波支付等
+ * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradePayModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradePayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePayResponse tradePayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradePayModel model, String notifyUrl) throws AlipayApiException { + AlipayTradePayRequest request = new AlipayTradePayRequest(); + // 填充业务参数 + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易支付接口接口
+ * 适用于:条形码支付、声波支付等
+ * + * @param model {AlipayTradePayModel} + * @param notifyUrl 异步通知URL + * @param appAuthToken 应用授权token + * @return {AlipayTradePayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePayResponse tradePayToResponse(AlipayTradePayModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradePayRequest request = new AlipayTradePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + return doExecute(request); + } + + /** + * 统一收单交易支付接口接口
+ * 适用于:条形码支付、声波支付等
+ * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {AlipayTradePayModel} + * @param notifyUrl 异步通知URL + * @param appAuthToken 应用授权token + * @return {AlipayTradePayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePayResponse tradePayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradePayModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradePayRequest request = new AlipayTradePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 统一收单线下交易预创建
+ * 适用于:扫码支付等
+ * + * @param model {@link AlipayTradePrecreateModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradePrecreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePrecreateResponse tradePrecreatePayToResponse(AlipayTradePrecreateModel model, String notifyUrl) throws AlipayApiException { + AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(request); + } + + + /** + * 统一收单线下交易预创建
+ * 适用于:扫码支付等
+ * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradePrecreateModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradePrecreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePrecreateResponse tradePrecreatePayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradePrecreateModel model, String notifyUrl) throws AlipayApiException { + AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 统一收单线下交易预创建
+ * 适用于:扫码支付等
+ * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradePrecreateModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradePrecreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePrecreateResponse tradePrecreatePayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradePrecreateModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(alipayClient, certModel, request, appAuthToken); + } + + /** + * 统一收单线下交易预创建
+ * 适用于:扫码支付等
+ * + * @param model {@link AlipayTradePrecreateModel} + * @param notifyUrl 异步通知URL + * @param appAuthToken 应用授权token + * @return {@link AlipayTradePrecreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePrecreateResponse tradePrecreatePayToResponse(AlipayTradePrecreateModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单线下交易预创建
+ * 适用于:扫码支付等
+ * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradePrecreateModel} + * @param notifyUrl 异步通知URL + * @param appAuthToken 应用授权token + * @return {@link AlipayTradePrecreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePrecreateResponse tradePrecreatePayToResponse(AlipayClient alipayClient, AlipayTradePrecreateModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradePrecreateRequest request = new AlipayTradePrecreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 单笔转账到支付宝账户 + * + * @param model {@link AlipayFundTransToaccountTransferModel} + * @return 转账是否成功 + * @throws AlipayApiException 支付宝 Api 异常 + */ + @Deprecated + public static boolean transfer(AlipayFundTransToaccountTransferModel model) throws AlipayApiException { + AlipayFundTransToaccountTransferResponse response = transferToResponse(model); + String result = response.getBody(); + if (response.isSuccess()) { + return true; + } else { + // 调用查询接口查询数据 + JSONObject jsonObject = JSONObject.parseObject(result); + String outBizNo = jsonObject.getJSONObject("alipay_fund_trans_toaccount_transfer_response").getString("out_biz_no"); + AlipayFundTransOrderQueryModel queryModel = new AlipayFundTransOrderQueryModel(); + model.setOutBizNo(outBizNo); + return transferQuery(queryModel); + } + } + + + /** + * 单笔转账到支付宝账户 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundTransToaccountTransferModel} + * @return 转账是否成功 + * @throws AlipayApiException 支付宝 Api 异常 + */ + @Deprecated + public static boolean transfer(AlipayClient alipayClient, Boolean certModel, AlipayFundTransToaccountTransferModel model) throws AlipayApiException { + AlipayFundTransToaccountTransferResponse response = transferToResponse(model); + String result = response.getBody(); + if (response.isSuccess()) { + return true; + } else { + // 调用查询接口查询数据 + JSONObject jsonObject = JSONObject.parseObject(result); + String outBizNo = jsonObject.getJSONObject("alipay_fund_trans_toaccount_transfer_response").getString("out_biz_no"); + AlipayFundTransOrderQueryModel queryModel = new AlipayFundTransOrderQueryModel(); + model.setOutBizNo(outBizNo); + return transferQuery(alipayClient, certModel, queryModel); + } + } + + /** + * 单笔转账到支付宝账户 + * + * @param model {@link AlipayFundTransToaccountTransferModel} + * @return {@link AlipayFundTransToaccountTransferResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransToaccountTransferResponse transferToResponse(AlipayFundTransToaccountTransferModel model) throws AlipayApiException { + AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); + request.setBizModel(model); + return doExecute(request); + } + + + /** + * 单笔转账到支付宝账户 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundTransToaccountTransferModel} + * @return {@link AlipayFundTransToaccountTransferResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransToaccountTransferResponse transferToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundTransToaccountTransferModel model) throws AlipayApiException { + AlipayFundTransToaccountTransferRequest request = new AlipayFundTransToaccountTransferRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 转账查询接口 + * + * @param model {@link AlipayFundTransOrderQueryModel} + * @return 是否存在此 + * @throws AlipayApiException 支付宝 Api 异常 + */ + @Deprecated + public static boolean transferQuery(AlipayFundTransOrderQueryModel model) throws AlipayApiException { + AlipayFundTransOrderQueryResponse response = transferQueryToResponse(model); + return response.isSuccess(); + } + + /** + * 转账查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundTransOrderQueryModel} + * @return 是否存在此 + * @throws AlipayApiException 支付宝 Api 异常 + */ + @Deprecated + public static boolean transferQuery(AlipayClient alipayClient, Boolean certModel, AlipayFundTransOrderQueryModel model) throws AlipayApiException { + AlipayFundTransOrderQueryResponse response = transferQueryToResponse(alipayClient, certModel, model); + return response.isSuccess(); + } + + /** + * 转账查询接口 + * + * @param model {@link AlipayFundTransOrderQueryModel} + * @return {@link AlipayFundTransOrderQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransOrderQueryResponse transferQueryToResponse(AlipayFundTransOrderQueryModel model) throws AlipayApiException { + AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 转账查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundTransOrderQueryModel} + * @return {@link AlipayFundTransOrderQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransOrderQueryResponse transferQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundTransOrderQueryModel model) throws AlipayApiException { + AlipayFundTransOrderQueryRequest request = new AlipayFundTransOrderQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一转账接口 + * + * @param model model {@link AlipayFundTransUniTransferModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayFundTransUniTransferResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransUniTransferResponse uniTransferToResponse(AlipayFundTransUniTransferModel model, String appAuthToken) throws AlipayApiException { + AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); + request.setBizModel(model); + if (!StringUtils.isEmpty(appAuthToken)) { + request.putOtherTextParam("app_auth_token", appAuthToken); + } + return doExecute(request); + } + + /** + * 统一转账接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model model {@link AlipayFundTransUniTransferModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayFundTransUniTransferResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransUniTransferResponse uniTransferToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundTransUniTransferModel model, String appAuthToken) throws AlipayApiException { + AlipayFundTransUniTransferRequest request = new AlipayFundTransUniTransferRequest(); + request.setBizModel(model); + if (!StringUtils.isEmpty(appAuthToken)) { + request.putOtherTextParam("app_auth_token", appAuthToken); + } + return doExecute(alipayClient, certModel, request); + } + + /** + * 转账业务单据查询接口 + * + * @param model model {@link AlipayFundTransCommonQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayFundTransCommonQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransCommonQueryResponse transCommonQueryToResponse(AlipayFundTransCommonQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest(); + request.setBizModel(model); + if (!StringUtils.isEmpty(appAuthToken)) { + request.putOtherTextParam("app_auth_token", appAuthToken); + } + return doExecute(request); + } + + /** + * 转账业务单据查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model model {@link AlipayFundTransCommonQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayFundTransCommonQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundTransCommonQueryResponse transCommonQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundTransCommonQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayFundTransCommonQueryRequest request = new AlipayFundTransCommonQueryRequest(); + request.setBizModel(model); + if (!StringUtils.isEmpty(appAuthToken)) { + request.putOtherTextParam("app_auth_token", appAuthToken); + } + return doExecute(alipayClient, certModel, request); + } + + /** + * 支付宝资金账户资产查询接口 + * + * @param model model {@link AlipayFundAccountQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayFundAccountQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAccountQueryResponse accountQueryToResponse(AlipayFundAccountQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayFundAccountQueryRequest request = new AlipayFundAccountQueryRequest(); + request.setBizModel(model); + if (!StringUtils.isEmpty(appAuthToken)) { + request.putOtherTextParam("app_auth_token", appAuthToken); + } + return doExecute(request); + } + + + /** + * 支付宝资金账户资产查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model model {@link AlipayFundAccountQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayFundAccountQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAccountQueryResponse accountQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundAccountQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayFundAccountQueryRequest request = new AlipayFundAccountQueryRequest(); + request.setBizModel(model); + if (!StringUtils.isEmpty(appAuthToken)) { + request.putOtherTextParam("app_auth_token", appAuthToken); + } + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单线下交易查询接口 + * + * @param model {@link AlipayTradeQueryModel} + * @return {@link AlipayTradeQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeQueryResponse tradeQueryToResponse(AlipayTradeQueryModel model) throws AlipayApiException { + AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单线下交易查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeQueryModel} + * @return {@link AlipayTradeQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeQueryResponse tradeQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeQueryModel model) throws AlipayApiException { + AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单线下交易查询接口 + * + * @param model {@link AlipayTradeQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeQueryResponse tradeQueryToResponse(AlipayTradeQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单线下交易查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeQueryResponse tradeQueryToResponse(AlipayClient alipayClient, AlipayTradeQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeQueryRequest request = new AlipayTradeQueryRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 统一收单交易撤销接口 + * + * @param model {@link AlipayTradeCancelModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeCancelResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCancelResponse tradeCancelToResponse(AlipayTradeCancelModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单交易撤销接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeCancelModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeCancelResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCancelResponse tradeCancelToResponse(AlipayClient alipayClient, AlipayTradeCancelModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 统一收单交易撤销接口 + * + * @param model {@link AlipayTradeCancelModel} + * @return {@link AlipayTradeCancelResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCancelResponse tradeCancelToResponse(AlipayTradeCancelModel model) throws AlipayApiException { + AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单交易撤销接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeCancelModel} + * @return {@link AlipayTradeCancelResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCancelResponse tradeCancelToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeCancelModel model) throws AlipayApiException { + AlipayTradeCancelRequest request = new AlipayTradeCancelRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易关闭接口 + * + * @param model {@link AlipayTradeCloseModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeCloseResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCloseResponse tradeCloseToResponse(AlipayTradeCloseModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + + } + + /** + * 统一收单交易关闭接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeCloseModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeCloseResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCloseResponse tradeCloseToResponse(AlipayClient alipayClient, AlipayTradeCloseModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + + } + + /** + * 统一收单交易关闭接口 + * + * @param model {@link AlipayTradeCloseModel} + * @return {@link AlipayTradeCloseResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCloseResponse tradeCloseToResponse(AlipayTradeCloseModel model) throws AlipayApiException { + AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单交易关闭接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeCloseModel} + * @return {@link AlipayTradeCloseResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCloseResponse tradeCloseToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeCloseModel model) throws AlipayApiException { + AlipayTradeCloseRequest request = new AlipayTradeCloseRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易创建接口 + * + * @param model {@link AlipayTradeCreateModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradeCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCreateResponse tradeCreateToResponse(AlipayTradeCreateModel model, String notifyUrl) throws AlipayApiException { + AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(request); + } + + /** + * 统一收单交易创建接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeCreateModel} + * @param notifyUrl 异步通知URL + * @return {@link AlipayTradeCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCreateResponse tradeCreateToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeCreateModel model, String notifyUrl) throws AlipayApiException { + AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易创建接口 + * + * @param model {@link AlipayTradeCreateModel} + * @param notifyUrl 异步通知URL + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCreateResponse tradeCreateToResponse(AlipayTradeCreateModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单交易创建接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeCreateModel} + * @param notifyUrl 异步通知URL + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeCreateResponse tradeCreateToResponse(AlipayClient alipayClient, AlipayTradeCreateModel model, String notifyUrl, String appAuthToken) throws AlipayApiException { + AlipayTradeCreateRequest request = new AlipayTradeCreateRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 统一收单交易退款接口 + * + * @param model {@link AlipayTradeRefundModel} + * @return {@link AlipayTradeRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRefundResponse tradeRefundToResponse(AlipayTradeRefundModel model) throws AlipayApiException { + AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单交易退款接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeRefundModel} + * @return {@link AlipayTradeRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRefundResponse tradeRefundToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeRefundModel model) throws AlipayApiException { + AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易退款接口 + * + * @param model {@link AlipayTradeRefundModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRefundResponse tradeRefundToResponse(AlipayTradeRefundModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单交易退款接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeRefundModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRefundResponse tradeRefundToResponse(AlipayClient alipayClient, AlipayTradeRefundModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeRefundRequest request = new AlipayTradeRefundRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 统一收单退款页面接口 + * + * @param model {@link AlipayTradePageRefundModel} + * @return {@link AlipayTradePageRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePageRefundResponse tradeRefundToResponse(AlipayTradePageRefundModel model) throws AlipayApiException { + AlipayTradePageRefundRequest request = new AlipayTradePageRefundRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单退款页面接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradePageRefundModel} + * @return {@link AlipayTradePageRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePageRefundResponse tradeRefundToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradePageRefundModel model) throws AlipayApiException { + AlipayTradePageRefundRequest request = new AlipayTradePageRefundRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 统一收单退款页面接口 + * + * @param model {@link AlipayTradePageRefundModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradePageRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePageRefundResponse tradeRefundToResponse(AlipayTradePageRefundModel model, String appAuthToken) throws AlipayApiException { + AlipayTradePageRefundRequest request = new AlipayTradePageRefundRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单退款页面接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradePageRefundModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradePageRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradePageRefundResponse tradeRefundToResponse(AlipayClient alipayClient, AlipayTradePageRefundModel model, String appAuthToken) throws AlipayApiException { + AlipayTradePageRefundRequest request = new AlipayTradePageRefundRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 统一收单交易退款查询 + * + * @param model {@link AlipayTradeFastpayRefundQueryModel} + * @return {@link AlipayTradeFastpayRefundQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeFastpayRefundQueryResponse tradeRefundQueryToResponse(AlipayTradeFastpayRefundQueryModel model) throws AlipayApiException { + AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单交易退款查询 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeFastpayRefundQueryModel} + * @return {@link AlipayTradeFastpayRefundQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeFastpayRefundQueryResponse tradeRefundQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeFastpayRefundQueryModel model) throws AlipayApiException { + AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易退款查询 + * + * @param model {@link AlipayTradeFastpayRefundQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeFastpayRefundQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeFastpayRefundQueryResponse tradeRefundQueryToResponse(AlipayTradeFastpayRefundQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单交易退款查询 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeFastpayRefundQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeFastpayRefundQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeFastpayRefundQueryResponse tradeRefundQueryToResponse(AlipayClient alipayClient, AlipayTradeFastpayRefundQueryModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeFastpayRefundQueryRequest request = new AlipayTradeFastpayRefundQueryRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 查询对账单下载地址 + * + * @param model {@link AlipayDataDataserviceBillDownloadurlQueryModel} + * @return 对账单下载地址 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static String billDownloadUrlQuery(AlipayDataDataserviceBillDownloadurlQueryModel model) throws AlipayApiException { + AlipayDataDataserviceBillDownloadurlQueryResponse response = billDownloadUrlQueryToResponse(model); + return response.getBillDownloadUrl(); + } + + /** + * 查询对账单下载地址 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayDataDataserviceBillDownloadurlQueryModel} + * @return 对账单下载地址 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static String billDownloadUrlQuery(AlipayClient alipayClient, Boolean certModel, AlipayDataDataserviceBillDownloadurlQueryModel model) throws AlipayApiException { + AlipayDataDataserviceBillDownloadurlQueryResponse response = billDownloadUrlQueryToResponse(alipayClient, certModel, model); + return response.getBillDownloadUrl(); + } + + /** + * 查询对账单下载地址 + * + * @param model {@link AlipayDataDataserviceBillDownloadurlQueryModel} + * @return {@link AlipayDataDataserviceBillDownloadurlQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayDataDataserviceBillDownloadurlQueryResponse billDownloadUrlQueryToResponse(AlipayDataDataserviceBillDownloadurlQueryModel model) throws AlipayApiException { + AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 查询对账单下载地址 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayDataDataserviceBillDownloadurlQueryModel} + * @return {@link AlipayDataDataserviceBillDownloadurlQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayDataDataserviceBillDownloadurlQueryResponse billDownloadUrlQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayDataDataserviceBillDownloadurlQueryModel model) throws AlipayApiException { + AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 查询对账单下载地址 + * + * @param model {@link AlipayDataDataserviceBillDownloadurlQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayDataDataserviceBillDownloadurlQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayDataDataserviceBillDownloadurlQueryResponse billDownloadUrlQueryToResponse(AlipayDataDataserviceBillDownloadurlQueryModel model, String appAuthToken) + throws AlipayApiException { + AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest(); + request.setBizModel(model); + request.putOtherTextParam("app_auth_token", appAuthToken); + return doExecute(request); + } + + /** + * 查询对账单下载地址 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayDataDataserviceBillDownloadurlQueryModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayDataDataserviceBillDownloadurlQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayDataDataserviceBillDownloadurlQueryResponse billDownloadUrlQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayDataDataserviceBillDownloadurlQueryModel model, String appAuthToken) + throws AlipayApiException { + AlipayDataDataserviceBillDownloadurlQueryRequest request = new AlipayDataDataserviceBillDownloadurlQueryRequest(); + request.setBizModel(model); + request.putOtherTextParam("app_auth_token", appAuthToken); + return doExecute(alipayClient, certModel, request); + } + + /** + * 统一收单交易结算接口 + * + * @param model {@link AlipayTradeOrderSettleModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeOrderSettleResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeOrderSettleResponse tradeOrderSettleToResponse(AlipayTradeOrderSettleModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); + request.setBizModel(model); + return execute(request, null, appAuthToken); + } + + /** + * 统一收单交易结算接口 + * + * @param alipayClient {@link AlipayClient} + * @param model {@link AlipayTradeOrderSettleModel} + * @param appAuthToken 应用授权token + * @return {@link AlipayTradeOrderSettleResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeOrderSettleResponse tradeOrderSettleToResponse(AlipayClient alipayClient, AlipayTradeOrderSettleModel model, String appAuthToken) throws AlipayApiException { + AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); + request.setBizModel(model); + return execute(alipayClient, request, null, appAuthToken); + } + + /** + * 统一收单交易结算接口 + * + * @param model {@link AlipayTradeOrderSettleModel} + * @return {@link AlipayTradeOrderSettleResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeOrderSettleResponse tradeOrderSettleToResponse(AlipayTradeOrderSettleModel model) throws AlipayApiException { + AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 统一收单交易结算接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeOrderSettleModel} + * @return {@link AlipayTradeOrderSettleResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeOrderSettleResponse tradeOrderSettleToResponse(AlipayClient alipayClient, Boolean certModel, AlipayTradeOrderSettleModel model) throws AlipayApiException { + AlipayTradeOrderSettleRequest request = new AlipayTradeOrderSettleRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 电脑网站支付(PC支付) + * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePage(HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + String form = pageExecute(request).getBody(); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param response {@link HttpServletResponse} + * @param method GET/POST GET 返回url,POST 返回 FORM 参考文章 + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePage(HttpServletResponse response, String method, AlipayTradePagePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + String form = pageExecute(request, method).getBody(); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePage(AlipayClient alipayClient, HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + String form = pageExecute(alipayClient, request).getBody(); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param method GET/POST GET 返回url,POST 返回 FORM 参考文章 + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePage(AlipayClient alipayClient, HttpServletResponse response, String method, AlipayTradePagePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + String form = pageExecute(alipayClient, request, method).getBody(); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + + /** + * 电脑网站支付(PC支付) + * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePage(HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl, String appAuthToken) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + String form = pageExecute(request).getBody(); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePage(AlipayClient alipayClient, HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl, String appAuthToken) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + String form = pageExecute(alipayClient, request).getBody(); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + PrintWriter out = response.getWriter(); + out.write(form); + out.flush(); + out.close(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePageByOutputStream(HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + String form = pageExecute(request).getBody(); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(AliPayApiConfigKit.getAliPayApiConfig().getCharset())); + response.getOutputStream().flush(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePageByOutputStream(AlipayClient alipayClient, HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl) throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + String form = pageExecute(alipayClient, request).getBody(); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(charset)); + response.getOutputStream().flush(); + } + + + /** + * 电脑网站支付(PC支付) + * + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePageByOutputStream(HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl, String appAuthToken) + throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + String form = pageExecute(request).getBody(); + response.setContentType("text/html;charset=" + AliPayApiConfigKit.getAliPayApiConfig().getCharset()); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(AliPayApiConfigKit.getAliPayApiConfig().getCharset())); + response.getOutputStream().flush(); + } + + /** + * 电脑网站支付(PC支付) + * + * @param alipayClient {@link AlipayClient} + * @param response {@link HttpServletResponse} + * @param model {@link AlipayTradePagePayModel} + * @param notifyUrl 异步通知URL + * @param returnUrl 同步通知URL + * @param appAuthToken 应用授权token + * @throws AlipayApiException 支付宝 Api 异常 + * @throws IOException IO 异常 + */ + public static void tradePageByOutputStream(AlipayClient alipayClient, HttpServletResponse response, AlipayTradePagePayModel model, String notifyUrl, String returnUrl, String appAuthToken) + throws AlipayApiException, IOException { + AlipayTradePagePayRequest request = new AlipayTradePagePayRequest(); + request.setBizModel(model); + request.setNotifyUrl(notifyUrl); + request.setReturnUrl(returnUrl); + request.putOtherTextParam("app_auth_token", appAuthToken); + String form = pageExecute(alipayClient, request).getBody(); + String charset = "UTF-8"; + response.setContentType("text/html;charset=" + charset); + OutputStream out = response.getOutputStream(); + out.write(form.getBytes(charset)); + response.getOutputStream().flush(); + } + + /** + * 资金预授权冻结接口 + * + * @param model {@link AlipayFundAuthOrderFreezeModel} + * @return {@link AlipayFundAuthOrderFreezeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOrderFreezeResponse authOrderFreezeToResponse(AlipayFundAuthOrderFreezeModel model) throws AlipayApiException { + AlipayFundAuthOrderFreezeRequest request = new AlipayFundAuthOrderFreezeRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 资金预授权冻结接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundAuthOrderFreezeModel} + * @return {@link AlipayFundAuthOrderFreezeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOrderFreezeResponse authOrderFreezeToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundAuthOrderFreezeModel model) throws AlipayApiException { + AlipayFundAuthOrderFreezeRequest request = new AlipayFundAuthOrderFreezeRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 资金授权解冻接口 + * + * @param model {@link AlipayFundAuthOrderUnfreezeModel} + * @return {@link AlipayFundAuthOrderUnfreezeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOrderUnfreezeResponse authOrderUnfreezeToResponse(AlipayFundAuthOrderUnfreezeModel model) throws AlipayApiException { + AlipayFundAuthOrderUnfreezeRequest request = new AlipayFundAuthOrderUnfreezeRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 资金授权解冻接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundAuthOrderUnfreezeModel} + * @return {@link AlipayFundAuthOrderUnfreezeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOrderUnfreezeResponse authOrderUnfreezeToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundAuthOrderUnfreezeModel model) throws AlipayApiException { + AlipayFundAuthOrderUnfreezeRequest request = new AlipayFundAuthOrderUnfreezeRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 资金预授权冻结接口 + * + * @param model {@link AlipayFundAuthOrderVoucherCreateModel} + * @return {@link AlipayFundAuthOrderVoucherCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOrderVoucherCreateResponse authOrderVoucherCreateToResponse(AlipayFundAuthOrderVoucherCreateModel model) throws AlipayApiException { + AlipayFundAuthOrderVoucherCreateRequest request = new AlipayFundAuthOrderVoucherCreateRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 资金预授权冻结接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundAuthOrderVoucherCreateModel} + * @return {@link AlipayFundAuthOrderVoucherCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOrderVoucherCreateResponse authOrderVoucherCreateToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundAuthOrderVoucherCreateModel model) throws AlipayApiException { + AlipayFundAuthOrderVoucherCreateRequest request = new AlipayFundAuthOrderVoucherCreateRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 资金授权撤销接口 + * + * @param model {@link AlipayFundAuthOperationCancelModel} + * @return {@link AlipayFundAuthOperationCancelResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOperationCancelResponse authOperationCancelToResponse(AlipayFundAuthOperationCancelModel model) throws AlipayApiException { + AlipayFundAuthOperationCancelRequest request = new AlipayFundAuthOperationCancelRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 资金授权撤销接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundAuthOperationCancelModel} + * @return {@link AlipayFundAuthOperationCancelResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOperationCancelResponse authOperationCancelToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundAuthOperationCancelModel model) throws AlipayApiException { + AlipayFundAuthOperationCancelRequest request = new AlipayFundAuthOperationCancelRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 资金授权操作查询接口 + * + * @param model {@link AlipayFundAuthOperationDetailQueryModel} + * @return {@link AlipayFundAuthOperationDetailQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOperationDetailQueryResponse authOperationDetailQueryToResponse(AlipayFundAuthOperationDetailQueryModel model) throws AlipayApiException { + AlipayFundAuthOperationDetailQueryRequest request = new AlipayFundAuthOperationDetailQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 资金授权操作查询接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundAuthOperationDetailQueryModel} + * @return {@link AlipayFundAuthOperationDetailQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundAuthOperationDetailQueryResponse authOperationDetailQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundAuthOperationDetailQueryModel model) throws AlipayApiException { + AlipayFundAuthOperationDetailQueryRequest request = new AlipayFundAuthOperationDetailQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 红包无线支付接口 + * + * @param model {@link AlipayFundCouponOrderAppPayModel} + * @return {@link AlipayFundCouponOrderAppPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderAppPayResponse fundCouponOrderAppPayToResponse(AlipayFundCouponOrderAppPayModel model) throws AlipayApiException { + AlipayFundCouponOrderAppPayRequest request = new AlipayFundCouponOrderAppPayRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 红包无线支付接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundCouponOrderAppPayModel} + * @return {@link AlipayFundCouponOrderAppPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderAppPayResponse fundCouponOrderAppPayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundCouponOrderAppPayModel model) throws AlipayApiException { + AlipayFundCouponOrderAppPayRequest request = new AlipayFundCouponOrderAppPayRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 红包页面支付接口 + * + * @param model {@link AlipayFundCouponOrderPagePayModel} + * @return {@link AlipayFundCouponOrderPagePayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderPagePayResponse fundCouponOrderPagePayToResponse(AlipayFundCouponOrderPagePayModel model) throws AlipayApiException { + AlipayFundCouponOrderPagePayRequest request = new AlipayFundCouponOrderPagePayRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 红包页面支付接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundCouponOrderPagePayModel} + * @return {@link AlipayFundCouponOrderPagePayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderPagePayResponse fundCouponOrderPagePayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundCouponOrderPagePayModel model) throws AlipayApiException { + AlipayFundCouponOrderPagePayRequest request = new AlipayFundCouponOrderPagePayRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 红包协议支付接口 + * + * @param model {@link AlipayFundCouponOrderAgreementPayModel} + * @return {@link AlipayFundCouponOrderAgreementPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderAgreementPayResponse fundCouponOrderAgreementPayToResponse(AlipayFundCouponOrderAgreementPayModel model) throws AlipayApiException { + AlipayFundCouponOrderAgreementPayRequest request = new AlipayFundCouponOrderAgreementPayRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 红包协议支付接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundCouponOrderAgreementPayModel} + * @return {@link AlipayFundCouponOrderAgreementPayResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderAgreementPayResponse fundCouponOrderAgreementPayToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundCouponOrderAgreementPayModel model) throws AlipayApiException { + AlipayFundCouponOrderAgreementPayRequest request = new AlipayFundCouponOrderAgreementPayRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 红包打款接口 + * + * @param model {@link AlipayFundCouponOrderDisburseModel} + * @return {@link AlipayFundCouponOrderDisburseResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderDisburseResponse fundCouponOrderDisburseToResponse(AlipayFundCouponOrderDisburseModel model) throws AlipayApiException { + AlipayFundCouponOrderDisburseRequest request = new AlipayFundCouponOrderDisburseRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 红包打款接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundCouponOrderDisburseModel} + * @return {@link AlipayFundCouponOrderDisburseResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderDisburseResponse fundCouponOrderDisburseToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundCouponOrderDisburseModel model) throws AlipayApiException { + AlipayFundCouponOrderDisburseRequest request = new AlipayFundCouponOrderDisburseRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 红包退回接口 + * + * @param model {@link AlipayFundCouponOrderRefundModel} + * @return {@link AlipayFundCouponOrderRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderRefundResponse fundCouponOrderRefundToResponse(AlipayFundCouponOrderRefundModel model) throws AlipayApiException { + AlipayFundCouponOrderRefundRequest request = new AlipayFundCouponOrderRefundRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 红包退回接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundCouponOrderRefundModel} + * @return {@link AlipayFundCouponOrderRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOrderRefundResponse fundCouponOrderRefundToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundCouponOrderRefundModel model) throws AlipayApiException { + AlipayFundCouponOrderRefundRequest request = new AlipayFundCouponOrderRefundRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 红包退回接口 + * + * @param model {@link AlipayFundCouponOperationQueryModel} + * @return {@link AlipayFundCouponOperationQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOperationQueryResponse fundCouponOperationQueryToResponse(AlipayFundCouponOperationQueryModel model) throws AlipayApiException { + AlipayFundCouponOperationQueryRequest request = new AlipayFundCouponOperationQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 红包退回接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayFundCouponOperationQueryModel} + * @return {@link AlipayFundCouponOperationQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayFundCouponOperationQueryResponse fundCouponOperationQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayFundCouponOperationQueryModel model) throws AlipayApiException { + AlipayFundCouponOperationQueryRequest request = new AlipayFundCouponOperationQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 应用授权 URL 拼装 + * + * @param appId 应用编号 + * @param redirectUri 回调 URI + * @return 应用授权 URL + * @throws UnsupportedEncodingException 编码异常 + */ + public static String getOauth2Url(String appId, String redirectUri) throws UnsupportedEncodingException { + return new StringBuffer().append("https://openauth.alipay.com/oauth2/appToAppAuth.htm?app_id=").append(appId).append("&redirect_uri=").append(URLEncoder.encode(redirectUri, "UTF-8")) + .toString(); + } + + /** + * 使用 app_auth_code 换取 app_auth_token + * + * @param model {@link AlipayOpenAuthTokenAppModel} + * @return {@link AlipayOpenAuthTokenAppResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayOpenAuthTokenAppResponse openAuthTokenAppToResponse(AlipayOpenAuthTokenAppModel model) throws AlipayApiException { + AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 使用 app_auth_code 换取 app_auth_token + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayOpenAuthTokenAppModel} + * @return {@link AlipayOpenAuthTokenAppResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayOpenAuthTokenAppResponse openAuthTokenAppToResponse(AlipayClient alipayClient, Boolean certModel, AlipayOpenAuthTokenAppModel model) throws AlipayApiException { + AlipayOpenAuthTokenAppRequest request = new AlipayOpenAuthTokenAppRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 查询授权信息 + * + * @param model {@link AlipayOpenAuthTokenAppQueryModel} + * @return {@link AlipayOpenAuthTokenAppQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayOpenAuthTokenAppQueryResponse openAuthTokenAppQueryToResponse(AlipayOpenAuthTokenAppQueryModel model) throws AlipayApiException { + AlipayOpenAuthTokenAppQueryRequest request = new AlipayOpenAuthTokenAppQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + + /** + * 查询授权信息 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayOpenAuthTokenAppQueryModel} + * @return {@link AlipayOpenAuthTokenAppQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayOpenAuthTokenAppQueryResponse openAuthTokenAppQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayOpenAuthTokenAppQueryModel model) throws AlipayApiException { + AlipayOpenAuthTokenAppQueryRequest request = new AlipayOpenAuthTokenAppQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 地铁购票发码 + * + * @param model {@link AlipayCommerceCityfacilitatorVoucherGenerateModel} + * @return {@link AlipayCommerceCityfacilitatorVoucherGenerateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorVoucherGenerateResponse voucherGenerateToResponse(AlipayCommerceCityfacilitatorVoucherGenerateModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorVoucherGenerateRequest request = new AlipayCommerceCityfacilitatorVoucherGenerateRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 地铁购票发码 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayCommerceCityfacilitatorVoucherGenerateModel} + * @return {@link AlipayCommerceCityfacilitatorVoucherGenerateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorVoucherGenerateResponse voucherGenerateToResponse(AlipayClient alipayClient, Boolean certModel, AlipayCommerceCityfacilitatorVoucherGenerateModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorVoucherGenerateRequest request = new AlipayCommerceCityfacilitatorVoucherGenerateRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 地铁购票发码退款 + * + * @param model {@link AlipayCommerceCityfacilitatorVoucherRefundModel} + * @return {@link AlipayCommerceCityfacilitatorVoucherRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorVoucherRefundResponse metroRefundToResponse(AlipayCommerceCityfacilitatorVoucherRefundModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorVoucherRefundRequest request = new AlipayCommerceCityfacilitatorVoucherRefundRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 地铁购票发码退款 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayCommerceCityfacilitatorVoucherRefundModel} + * @return {@link AlipayCommerceCityfacilitatorVoucherRefundResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorVoucherRefundResponse metroRefundToResponse(AlipayClient alipayClient, Boolean certModel, AlipayCommerceCityfacilitatorVoucherRefundModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorVoucherRefundRequest request = new AlipayCommerceCityfacilitatorVoucherRefundRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 地铁车站数据查询 + * + * @param model {@link AlipayCommerceCityfacilitatorStationQueryModel} + * @return {@link AlipayCommerceCityfacilitatorStationQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorStationQueryResponse stationQueryToResponse(AlipayCommerceCityfacilitatorStationQueryModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorStationQueryRequest request = new AlipayCommerceCityfacilitatorStationQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + + /** + * 地铁车站数据查询 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayCommerceCityfacilitatorStationQueryModel} + * @return {@link AlipayCommerceCityfacilitatorStationQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorStationQueryResponse stationQueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayCommerceCityfacilitatorStationQueryModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorStationQueryRequest request = new AlipayCommerceCityfacilitatorStationQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 核销码批量查询 + * + * @param model {@link AlipayCommerceCityfacilitatorVoucherBatchqueryModel} + * @return {@link AlipayCommerceCityfacilitatorVoucherBatchqueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorVoucherBatchqueryResponse voucherBatchqueryToResponse(AlipayCommerceCityfacilitatorVoucherBatchqueryModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorVoucherBatchqueryRequest request = new AlipayCommerceCityfacilitatorVoucherBatchqueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 核销码批量查询 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayCommerceCityfacilitatorVoucherBatchqueryModel} + * @return {@link AlipayCommerceCityfacilitatorVoucherBatchqueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceCityfacilitatorVoucherBatchqueryResponse voucherBatchqueryToResponse(AlipayClient alipayClient, Boolean certModel, AlipayCommerceCityfacilitatorVoucherBatchqueryModel model) throws AlipayApiException { + AlipayCommerceCityfacilitatorVoucherBatchqueryRequest request = new AlipayCommerceCityfacilitatorVoucherBatchqueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + public static void batchTrans(Map params, String privateKey, String signType, HttpServletResponse response) throws IOException { + params.put("service", "batch_trans_notify"); + params.put("_input_charset", "UTF-8"); + params.put("pay_date", DateUtil.format(new Date(), "YYYYMMDD")); + Map param = AliPayCore.buildRequestPara(params, privateKey, signType); + response.sendRedirect(GATEWAY_NEW.concat(AliPayCore.createLinkString(param))); + } + + /** + * 将异步通知的参数转化为Map + * + * @param request {HttpServletRequest} + * @return 转化后的Map + */ + public static Map toMap(HttpServletRequest request) { + Map params = new HashMap(); + Map requestParams = request.getParameterMap(); + for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext(); ) { + String name = iter.next(); + String[] values = requestParams.get(name); + String valueStr = ""; + for (int i = 0; i < values.length; i++) { + valueStr = (i == values.length - 1) ? valueStr + values[i] : valueStr + values[i] + ","; + } + params.put(name, valueStr); + } + return params; + } + + /** + * 生活缴费查询账单 + * + * @param orderType 支付宝订单类型 + * @param merchantOrderNo 业务流水号 + * @return {@link AlipayEbppBillGetResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayEbppBillGetResponse ebppBillGet(String orderType, String merchantOrderNo) throws AlipayApiException { + AlipayEbppBillGetRequest request = new AlipayEbppBillGetRequest(); + request.setOrderType(orderType); + request.setMerchantOrderNo(merchantOrderNo); + return doExecute(request); + } + + /** + * 生活缴费查询账单 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param orderType 支付宝订单类型 + * @param merchantOrderNo 业务流水号 + * @return {@link AlipayEbppBillGetResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayEbppBillGetResponse ebppBillGet(AlipayClient alipayClient, Boolean certModel, String orderType, String merchantOrderNo) throws AlipayApiException { + AlipayEbppBillGetRequest request = new AlipayEbppBillGetRequest(); + request.setOrderType(orderType); + request.setMerchantOrderNo(merchantOrderNo); + return doExecute(alipayClient, certModel, request); + } + + /** + * H5刷脸认证初始化 + * + * @param model {@link ZolozIdentificationUserWebInitializeModel} + * @return {@link ZolozIdentificationUserWebInitializeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozIdentificationUserWebInitializeResponse identificationUserWebInitialize(ZolozIdentificationUserWebInitializeModel model) throws AlipayApiException { + ZolozIdentificationUserWebInitializeRequest request = new ZolozIdentificationUserWebInitializeRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * H5刷脸认证初始化 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozIdentificationUserWebInitializeModel} + * @return {@link ZolozIdentificationUserWebInitializeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozIdentificationUserWebInitializeResponse identificationUserWebInitialize(AlipayClient alipayClient, Boolean certModel, ZolozIdentificationUserWebInitializeModel model) throws AlipayApiException { + ZolozIdentificationUserWebInitializeRequest request = new ZolozIdentificationUserWebInitializeRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * H5刷脸认证查询 + * + * @param model {@link ZolozIdentificationUserWebQueryModel} + * @return {@link ZolozIdentificationUserWebQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozIdentificationUserWebQueryResponse identificationUserWebInitialize(ZolozIdentificationUserWebQueryModel model) throws AlipayApiException { + ZolozIdentificationUserWebQueryRequest request = new ZolozIdentificationUserWebQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * H5刷脸认证查询 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozIdentificationUserWebQueryModel} + * @return {@link ZolozIdentificationUserWebQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozIdentificationUserWebQueryResponse identificationUserWebInitialize(AlipayClient alipayClient, Boolean certModel, ZolozIdentificationUserWebQueryModel model) throws AlipayApiException { + ZolozIdentificationUserWebQueryRequest request = new ZolozIdentificationUserWebQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 热脸入库 + * + * @param model {@link ZolozAuthenticationCustomerFacemanageCreateModel} + * @return {@link ZolozAuthenticationCustomerFacemanageCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerFacemanageCreateResponse authenticationCustomerFaceManageCreate(ZolozAuthenticationCustomerFacemanageCreateModel model) throws AlipayApiException { + ZolozAuthenticationCustomerFacemanageCreateRequest request = new ZolozAuthenticationCustomerFacemanageCreateRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 热脸入库 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozAuthenticationCustomerFacemanageCreateModel} + * @return {@link ZolozAuthenticationCustomerFacemanageCreateResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerFacemanageCreateResponse authenticationCustomerFaceManageCreate(AlipayClient alipayClient, Boolean certModel, ZolozAuthenticationCustomerFacemanageCreateModel model) throws AlipayApiException { + ZolozAuthenticationCustomerFacemanageCreateRequest request = new ZolozAuthenticationCustomerFacemanageCreateRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 热脸出库 + * + * @param model {@link ZolozAuthenticationCustomerFacemanageDeleteModel} + * @return {@link ZolozAuthenticationCustomerFacemanageDeleteResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerFacemanageDeleteResponse authenticationCustomerFaceManageDelete(ZolozAuthenticationCustomerFacemanageDeleteModel model) throws AlipayApiException { + ZolozAuthenticationCustomerFacemanageDeleteRequest request = new ZolozAuthenticationCustomerFacemanageDeleteRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 热脸出库 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozAuthenticationCustomerFacemanageDeleteModel} + * @return {@link ZolozAuthenticationCustomerFacemanageDeleteResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerFacemanageDeleteResponse authenticationCustomerFaceManageDelete(AlipayClient alipayClient, Boolean certModel, ZolozAuthenticationCustomerFacemanageDeleteModel model) throws AlipayApiException { + ZolozAuthenticationCustomerFacemanageDeleteRequest request = new ZolozAuthenticationCustomerFacemanageDeleteRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 人脸 ftoken 查询消费接口 + * + * @param model {@link ZolozAuthenticationCustomerFtokenQueryModel} + * @return {@link ZolozAuthenticationCustomerFtokenQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerFtokenQueryResponse authenticationCustomerFTokenQuery(ZolozAuthenticationCustomerFtokenQueryModel model) throws AlipayApiException { + ZolozAuthenticationCustomerFtokenQueryRequest request = new ZolozAuthenticationCustomerFtokenQueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 人脸 ftoken 查询消费接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozAuthenticationCustomerFtokenQueryModel} + * @return {@link ZolozAuthenticationCustomerFtokenQueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerFtokenQueryResponse authenticationCustomerFTokenQuery(AlipayClient alipayClient, Boolean certModel, ZolozAuthenticationCustomerFtokenQueryModel model) throws AlipayApiException { + ZolozAuthenticationCustomerFtokenQueryRequest request = new ZolozAuthenticationCustomerFtokenQueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + + /** + * 人脸初始化刷脸付 + * + * @param model {@link ZolozAuthenticationSmilepayInitializeModel} + * @return {@link ZolozAuthenticationSmilepayInitializeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationSmilepayInitializeResponse authenticationSmilePayInitialize(ZolozAuthenticationSmilepayInitializeModel model) throws AlipayApiException { + ZolozAuthenticationSmilepayInitializeRequest request = new ZolozAuthenticationSmilepayInitializeRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 人脸初始化刷脸付 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozAuthenticationSmilepayInitializeModel} + * @return {@link ZolozAuthenticationSmilepayInitializeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationSmilepayInitializeResponse authenticationSmilePayInitialize(AlipayClient alipayClient, Boolean certModel, ZolozAuthenticationSmilepayInitializeModel model) throws AlipayApiException { + ZolozAuthenticationSmilepayInitializeRequest request = new ZolozAuthenticationSmilepayInitializeRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 人脸初始化唤起zim + * + * @param model {@link ZolozAuthenticationCustomerSmilepayInitializeModel} + * @return {@link ZolozAuthenticationCustomerSmilepayInitializeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerSmilepayInitializeResponse authenticationCustomerSmilePayInitialize(ZolozAuthenticationCustomerSmilepayInitializeModel model) throws AlipayApiException { + ZolozAuthenticationCustomerSmilepayInitializeRequest request = new ZolozAuthenticationCustomerSmilepayInitializeRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 人脸初始化唤起zim + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link ZolozAuthenticationCustomerSmilepayInitializeModel} + * @return {@link ZolozAuthenticationCustomerSmilepayInitializeResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static ZolozAuthenticationCustomerSmilepayInitializeResponse authenticationCustomerSmilePayInitialize(AlipayClient alipayClient, Boolean certModel, ZolozAuthenticationCustomerSmilepayInitializeModel model) throws AlipayApiException { + ZolozAuthenticationCustomerSmilepayInitializeRequest request = new ZolozAuthenticationCustomerSmilepayInitializeRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 生态激励项目ISV代签约接口 + * + * @return {@link AlipayCommerceAdContractSignResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceAdContractSignResponse commerceAdContractSign() throws AlipayApiException { + AlipayCommerceAdContractSignRequest request = new AlipayCommerceAdContractSignRequest(); + return doExecute(request); + } + + /** + * 生态激励项目ISV代签约接口 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @return {@link AlipayCommerceAdContractSignResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayCommerceAdContractSignResponse commerceAdContractSign(AlipayClient alipayClient, Boolean certModel) throws AlipayApiException { + AlipayCommerceAdContractSignRequest request = new AlipayCommerceAdContractSignRequest(); + return doExecute(alipayClient, certModel, request); + } + + /** + * 分账关系绑定 + * + * @param model {@link AlipayTradeRoyaltyRelationBindModel} + * @return {@link AlipayTradeRoyaltyRelationBindResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRoyaltyRelationBindResponse tradeRoyaltyRelationBind(AlipayTradeRoyaltyRelationBindModel model) throws AlipayApiException { + AlipayTradeRoyaltyRelationBindRequest request = new AlipayTradeRoyaltyRelationBindRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 分账关系绑定 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeRoyaltyRelationBindModel} + * @return {@link AlipayTradeRoyaltyRelationBindResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRoyaltyRelationBindResponse tradeRoyaltyRelationBind(AlipayClient alipayClient, Boolean certModel, AlipayTradeRoyaltyRelationBindModel model) throws AlipayApiException { + AlipayTradeRoyaltyRelationBindRequest request = new AlipayTradeRoyaltyRelationBindRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 分账关系解绑 + * + * @param model {@link AlipayTradeRoyaltyRelationUnbindModel} + * @return {@link AlipayTradeRoyaltyRelationUnbindResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRoyaltyRelationUnbindResponse tradeRoyaltyRelationUnBind(AlipayTradeRoyaltyRelationUnbindModel model) throws AlipayApiException { + AlipayTradeRoyaltyRelationUnbindRequest request = new AlipayTradeRoyaltyRelationUnbindRequest(); + request.setBizModel(model); + return doExecute(request); + } + + /** + * 分账关系解绑 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeRoyaltyRelationUnbindModel} + * @return {@link AlipayTradeRoyaltyRelationUnbindResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRoyaltyRelationUnbindResponse tradeRoyaltyRelationUnBind(AlipayClient alipayClient, Boolean certModel, AlipayTradeRoyaltyRelationUnbindModel model) throws AlipayApiException { + AlipayTradeRoyaltyRelationUnbindRequest request = new AlipayTradeRoyaltyRelationUnbindRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + + /** + * 分账关系查询 + * + * @param model {@link AlipayTradeRoyaltyRelationBatchqueryModel} + * @return {@link AlipayTradeRoyaltyRelationBatchqueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRoyaltyRelationBatchqueryResponse tradeRoyaltyRelationBatchQuery(AlipayTradeRoyaltyRelationBatchqueryModel model) throws AlipayApiException { + AlipayTradeRoyaltyRelationBatchqueryRequest request = new AlipayTradeRoyaltyRelationBatchqueryRequest(); + request.setBizModel(model); + return doExecute(request); + } + + + /** + * 分账关系查询 + * + * @param alipayClient {@link AlipayClient} + * @param certModel 是否证书模式 + * @param model {@link AlipayTradeRoyaltyRelationBatchqueryModel} + * @return {@link AlipayTradeRoyaltyRelationBatchqueryResponse} + * @throws AlipayApiException 支付宝 Api 异常 + */ + public static AlipayTradeRoyaltyRelationBatchqueryResponse tradeRoyaltyRelationBatchQuery(AlipayClient alipayClient, Boolean certModel, AlipayTradeRoyaltyRelationBatchqueryModel model) throws AlipayApiException { + AlipayTradeRoyaltyRelationBatchqueryRequest request = new AlipayTradeRoyaltyRelationBatchqueryRequest(); + request.setBizModel(model); + return doExecute(alipayClient, certModel, request); + } + +} diff --git a/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfig.java b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfig.java new file mode 100644 index 00000000..d57adc58 --- /dev/null +++ b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfig.java @@ -0,0 +1,402 @@ +package com.ijpay.alipay; + +import cn.hutool.core.util.StrUtil; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayClient; +import com.alipay.api.CertAlipayRequest; +import com.alipay.api.DefaultAlipayClient; + +import java.io.Serializable; + +/** + *

IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。

+ * + *

不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。

+ * + *

IJPay 交流群: 723992875、864988890

+ * + *

Node.js 版: https://gitee.com/javen205/TNWXX

+ * + *

支付宝支付配置

+ * + * @author Javen + */ +public class AliPayApiConfig implements Serializable { + private static final long serialVersionUID = -4736760736935998953L; + + /** + * 应用私钥 + */ + private String privateKey; + + /** + * 支付宝公钥 + */ + private String aliPayPublicKey; + + /** + * 应用编号 + */ + private String appId; + + /** + * 支付宝支付网关 + */ + private String serviceUrl; + + /** + * 字符集,为空默认为 UTF-8 + */ + private String charset; + + /** + * 为空默认为 RSA2 + */ + private String signType; + + /** + * 为空默认为 JSON + */ + private String format; + + /** + * 是否为证书模式 + */ + private boolean certModel; + + /** + * 应用公钥证书 (证书模式必须) + */ + private String appCertPath; + + /** + * 应用公钥证书文本内容 + */ + private String appCertContent; + + /** + * 支付宝公钥证书 (证书模式必须) + */ + private String aliPayCertPath; + + /** + * 支付宝公钥证书文本内容 + */ + private String aliPayCertContent; + + /** + * 支付宝根证书 (证书模式必须) + */ + private String aliPayRootCertPath; + + /** + * 支付宝根证书文本内容 + */ + private String aliPayRootCertContent; + + /** + * 支付宝客户端 + */ + private AlipayClient alipayClient; + + /** + * 其他附加参数 + */ + private Object exParams; + + /** + * 域名 + */ + private String domain; + + private Integer proxyPort; + private String proxyIp; + + private AliPayApiConfig() { + } + + public static AliPayApiConfig builder() { + return new AliPayApiConfig(); + } + + /** + * 普通公钥方式 + * + * @return AliPayApiConfig 支付宝配置 + */ + public AliPayApiConfig build() { + this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(), + getCharset(), getAliPayPublicKey(), getSignType()); + return this; + } + + public AliPayApiConfig buildProxy() { + this.alipayClient = new DefaultAlipayClient(getServiceUrl(), getAppId(), getPrivateKey(), getFormat(), + getCharset(), getAliPayPublicKey(), getSignType(), getProxyIp(),getProxyPort()); + return this; + } + + /** + * 证书模式 + * + * @return AliPayApiConfig 支付宝配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig buildByCert() throws AlipayApiException { + return build(getAppCertPath(), getAliPayCertPath(), getAliPayRootCertPath()); + } + + /** + * 证书模式 + * + * @return AliPayApiConfig 支付宝配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig buildByCertContent() throws AlipayApiException { + return buildByCertContent(getAppCertContent(), getAliPayCertContent(), getAliPayRootCertContent()); + } + + /** + * @param appCertPath 应用公钥证书路径 + * @param aliPayCertPath 支付宝公钥证书文件路径 + * @param aliPayRootCertPath 支付宝CA根证书文件路径 + * @return {@link AliPayApiConfig} 支付宝支付配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig build(String appCertPath, String aliPayCertPath, String aliPayRootCertPath) throws AlipayApiException { + CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); + certAlipayRequest.setServerUrl(getServiceUrl()); + certAlipayRequest.setAppId(getAppId()); + certAlipayRequest.setPrivateKey(getPrivateKey()); + certAlipayRequest.setFormat(getFormat()); + certAlipayRequest.setCharset(getCharset()); + certAlipayRequest.setSignType(getSignType()); + certAlipayRequest.setCertPath(appCertPath); + certAlipayRequest.setAlipayPublicCertPath(aliPayCertPath); + certAlipayRequest.setRootCertPath(aliPayRootCertPath); + this.alipayClient = new DefaultAlipayClient(certAlipayRequest); + this.certModel = true; + return this; + } + + /** + * @param appCertContent 应用公钥证书 + * @param aliPayCertContent 支付宝公钥证书 + * @param aliPayRootCertContent 支付宝CA根证书 + * @return {@link AliPayApiConfig} 支付宝支付配置 + * @throws AlipayApiException 支付宝 Api 异常 + */ + public AliPayApiConfig buildByCertContent(String appCertContent, String aliPayCertContent, String aliPayRootCertContent) throws AlipayApiException { + CertAlipayRequest certAlipayRequest = new CertAlipayRequest(); + certAlipayRequest.setServerUrl(getServiceUrl()); + certAlipayRequest.setAppId(getAppId()); + certAlipayRequest.setPrivateKey(getPrivateKey()); + certAlipayRequest.setFormat(getFormat()); + certAlipayRequest.setCharset(getCharset()); + certAlipayRequest.setSignType(getSignType()); + certAlipayRequest.setCertContent(appCertContent); + certAlipayRequest.setAlipayPublicCertContent(aliPayCertContent); + certAlipayRequest.setRootCertContent(aliPayRootCertContent); + this.alipayClient = new DefaultAlipayClient(certAlipayRequest); + this.certModel = true; + return this; + } + + public String getPrivateKey() { + if (StrUtil.isBlank(privateKey)) { + throw new IllegalStateException("privateKey 未被赋值"); + } + return privateKey; + } + + public AliPayApiConfig setPrivateKey(String privateKey) { + if (StrUtil.isEmpty(privateKey)) { + throw new IllegalArgumentException("privateKey 值不能为 null"); + } + this.privateKey = privateKey; + return this; + } + + public String getAliPayPublicKey() { + return aliPayPublicKey; + } + + public AliPayApiConfig setAliPayPublicKey(String aliPayPublicKey) { + this.aliPayPublicKey = aliPayPublicKey; + return this; + } + + public String getAppId() { + if (StrUtil.isEmpty(appId)) { + throw new IllegalStateException("appId 未被赋值"); + } + return appId; + } + + public AliPayApiConfig setAppId(String appId) { + if (StrUtil.isEmpty(appId)) { + throw new IllegalArgumentException("appId 值不能为 null"); + } + this.appId = appId; + return this; + } + + public String getServiceUrl() { + if (StrUtil.isEmpty(serviceUrl)) { + throw new IllegalStateException("serviceUrl 未被赋值"); + } + return serviceUrl; + } + + public AliPayApiConfig setServiceUrl(String serviceUrl) { + if (StrUtil.isEmpty(serviceUrl)) { + serviceUrl = "https://openapi.alipay.com/gateway.do"; + } + this.serviceUrl = serviceUrl; + return this; + } + + public String getCharset() { + if (StrUtil.isEmpty(charset)) { + charset = "UTF-8"; + } + return charset; + } + + public AliPayApiConfig setCharset(String charset) { + if (StrUtil.isEmpty(charset)) { + charset = "UTF-8"; + } + this.charset = charset; + return this; + } + + public String getSignType() { + if (StrUtil.isEmpty(signType)) { + signType = "RSA2"; + } + return signType; + } + + public AliPayApiConfig setSignType(String signType) { + if (StrUtil.isEmpty(signType)) { + signType = "RSA2"; + } + this.signType = signType; + return this; + } + + public String getFormat() { + if (StrUtil.isEmpty(format)) { + format = "json"; + } + return format; + } + + public String getAppCertPath() { + return appCertPath; + } + + public AliPayApiConfig setAppCertPath(String appCertPath) { + this.appCertPath = appCertPath; + return this; + } + + public String getAppCertContent() { + return appCertContent; + } + + public AliPayApiConfig setAppCertContent(String appCertContent) { + this.appCertContent = appCertContent; + return this; + } + + public String getAliPayCertPath() { + return aliPayCertPath; + } + + public AliPayApiConfig setAliPayCertPath(String aliPayCertPath) { + this.aliPayCertPath = aliPayCertPath; + return this; + } + + public String getAliPayCertContent() { + return aliPayCertContent; + } + + public AliPayApiConfig setAliPayCertContent(String aliPayCertContent) { + this.aliPayCertContent = aliPayCertContent; + return this; + } + + public String getAliPayRootCertPath() { + return aliPayRootCertPath; + } + + public AliPayApiConfig setAliPayRootCertPath(String aliPayRootCertPath) { + this.aliPayRootCertPath = aliPayRootCertPath; + return this; + } + + public String getAliPayRootCertContent() { + return aliPayRootCertContent; + } + + public AliPayApiConfig setAliPayRootCertContent(String aliPayRootCertContent) { + this.aliPayRootCertContent = aliPayRootCertContent; + return this; + } + + public boolean isCertModel() { + return certModel; + } + + public AliPayApiConfig setCertModel(boolean certModel) { + this.certModel = certModel; + return this; + } + + public AlipayClient getAliPayClient() { + if (alipayClient == null) { + throw new IllegalStateException("aliPayClient 未被初始化"); + } + return alipayClient; + } + + public Object getExParams() { + return exParams; + } + + public AliPayApiConfig setExParams(Object exParams) { + this.exParams = exParams; + return this; + } + + public String getDomain() { + return domain; + } + + public AliPayApiConfig setDomain(String domain) { + this.domain = domain; + return this; + } + + + public Integer getProxyPort() { + return proxyPort; + } + + public AliPayApiConfig setProxyPort(Integer proxyPort) { + this.proxyPort = proxyPort; + return this; + } + + public String getProxyIp() { + return proxyIp; + } + + public AliPayApiConfig setProxyIp(String proxyIp) { + this.proxyIp = proxyIp; + return this; + } +} diff --git a/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfigKit.java b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfigKit.java new file mode 100644 index 00000000..2c28b640 --- /dev/null +++ b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayApiConfigKit.java @@ -0,0 +1,128 @@ +package com.ijpay.alipay; + +import cn.hutool.core.util.StrUtil; + +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; + +/** + *

IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。

+ * + *

不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。

+ * + *

IJPay 交流群: 723992875、864988890

+ * + *

Node.js 版: https://gitee.com/javen205/TNWX

+ * + * @author Javen + */ +public class AliPayApiConfigKit { + private static final ThreadLocal TL = new ThreadLocal(); + + private static final Map CFG_MAP = new ConcurrentHashMap(); + private static final String DEFAULT_CFG_KEY = "_default_key_"; + + /** + *

向缓存中设置 AliPayApiConfig

+ *

每个 appId 只需添加一次,相同 appId 将被覆盖

+ * + * @param aliPayApiConfig 支付宝支付配置 + * @return {@link AliPayApiConfig} + */ + public static AliPayApiConfig putApiConfig(AliPayApiConfig aliPayApiConfig) { + if (CFG_MAP.size() == 0) { + CFG_MAP.put(DEFAULT_CFG_KEY, aliPayApiConfig); + } + CFG_MAP.put(aliPayApiConfig.getAppId(), aliPayApiConfig); + return aliPayApiConfig; + } + + /** + * 向当前线程中设置 {@link AliPayApiConfig} + * + * @param aliPayApiConfig {@link AliPayApiConfig} 支付宝配置对象 + * @return {@link AliPayApiConfig} + */ + public static AliPayApiConfig setThreadLocalAliPayApiConfig(AliPayApiConfig aliPayApiConfig) { + if (StrUtil.isNotEmpty(aliPayApiConfig.getAppId())) { + setThreadLocalAppId(aliPayApiConfig.getAppId()); + } + return putApiConfig(aliPayApiConfig); + } + + /** + * 通过 AliPayApiConfig 移除支付配置 + * + * @param aliPayApiConfig {@link AliPayApiConfig} 支付宝配置对象 + * @return {@link AliPayApiConfig} + */ + public static AliPayApiConfig removeApiConfig(AliPayApiConfig aliPayApiConfig) { + return removeApiConfig(aliPayApiConfig.getAppId()); + } + + /** + * 通过 appId 移除支付配置 + * + * @param appId 支付宝应用编号 + * @return {@link AliPayApiConfig} + */ + public static AliPayApiConfig removeApiConfig(String appId) { + return CFG_MAP.remove(appId); + } + + /** + * 向当前线程中设置 appId + * + * @param appId 支付宝应用编号 + */ + public static void setThreadLocalAppId(String appId) { + if (StrUtil.isEmpty(appId)) { + appId = CFG_MAP.get(DEFAULT_CFG_KEY).getAppId(); + } + TL.set(appId); + } + + /** + * 移除当前线程中的 appId + */ + public static void removeThreadLocalAppId() { + TL.remove(); + } + + /** + * 获取当前线程中的 appId + * + * @return 支付宝应用编号 appId + */ + public static String getAppId() { + String appId = TL.get(); + if (StrUtil.isEmpty(appId)) { + appId = CFG_MAP.get(DEFAULT_CFG_KEY).getAppId(); + } + return appId; + } + + /** + * 获取当前线程中的 AliPayApiConfig + * + * @return {@link AliPayApiConfig} + */ + public static AliPayApiConfig getAliPayApiConfig() { + String appId = getAppId(); + return getApiConfig(appId); + } + + /** + * 通过 appId 获取 AliPayApiConfig + * + * @param appId 支付宝应用编号 + * @return {@link AliPayApiConfig} + */ + public static AliPayApiConfig getApiConfig(String appId) { + AliPayApiConfig cfg = CFG_MAP.get(appId); + if (cfg == null) { + throw new IllegalStateException("需事先调用 AliPayApiConfigKit.putApiConfig(aliPayApiConfig) 将 appId对应的 aliPayApiConfig 对象存入,才可以使用 AliPayApiConfigKit.getAliPayApiConfig() 的系列方法"); + } + return cfg; + } +} diff --git a/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayCore.java b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayCore.java new file mode 100644 index 00000000..60a927c4 --- /dev/null +++ b/ruoyi-alipay/src/main/java/com/ijpay/alipay/AliPayCore.java @@ -0,0 +1,139 @@ +package com.ijpay.alipay; + +import cn.hutool.crypto.SecureUtil; +import com.alipay.api.AlipayApiException; +import com.alipay.api.AlipayConstants; +import com.alipay.api.internal.util.AlipaySignature; +import com.alipay.api.internal.util.AntCertificationUtil; +import com.alipay.api.internal.util.codec.Base64; +import enums.SignType; + +import java.util.*; + +import static com.alipay.api.internal.util.AlipaySignature.rsaCheckV1; + +/** + *

IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。

+ * + *

不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。

+ * + *

IJPay 交流群: 723992875、864988890

+ * + *

Node.js 版: https://gitee.com/javen205/TNWX

+ * + * @author Javen + */ +public class AliPayCore { + + /** + * 生成签名结果 + * + * @param params 要签名的数组 + * @param key 签名密钥 + * @param signType 签名类型 + * @return 签名结果字符串 + */ + public static String buildRequestMySign(Map params, String key, String signType) throws AlipayApiException { + // 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 + String preStr = createLinkString(params); + if (SignType.MD5.getType().equals(signType)) { + return SecureUtil.md5(preStr.concat(key)); + } else if (SignType.RSA2.getType().equals(signType)) { + return AlipaySignature.rsa256Sign(preStr, key, AlipayConstants.CHARSET_UTF8); + } else if (SignType.RSA.getType().equals(signType)) { + return AlipaySignature.rsaSign(preStr, key, AlipayConstants.CHARSET_UTF8); + } + return null; + } + + /** + * 生成要请求给支付宝的参数数组 + * + * @param params 请求前的参数数组 + * @param key 商户的私钥 + * @param signType 签名类型 + * @return 要请求的参数数组 + */ + public static Map buildRequestPara(Map params, String key, String signType) { + // 除去数组中的空值和签名参数 + Map tempMap = paraFilter(params); + // 生成签名结果 + String mySign; + try { + mySign = buildRequestMySign(params, key, signType); + } catch (AlipayApiException e) { + e.printStackTrace(); + return null; + } + // 签名结果与签名方式加入请求提交参数组中 + tempMap.put("sign", mySign); + tempMap.put("sign_type", signType); + return tempMap; + } + + /** + * 除去数组中的空值和签名参数 + * + * @param params 签名参数组 + * @return 去掉空值与签名参数后的新签名参数组 + */ + public static Map paraFilter(Map params) { + if (params == null) { + return null; + } + Map result = new HashMap<>(params.size()); + if (params.size() <= 0) { + return result; + } + for (String key : params.keySet()) { + String value = params.get(key); + if (value == null || "".equals(value) || "sign".equalsIgnoreCase(key) + || "sign_type".equalsIgnoreCase(key)) { + continue; + } + result.put(key, value); + } + return result; + } + + /** + * 把数组所有元素排序 + * + * @param params 需要排序并参与字符拼接的参数组 + * @return 拼接后字符串 + */ + public static String createLinkString(Map params) { + List keys = new ArrayList<>(params.keySet()); + Collections.sort(keys); + StringBuilder content = new StringBuilder(); + for (String key : keys) { + String value = params.get(key); + // 拼接时,不包括最后一个&字符 + content.append(key).append("=").append(value).append("&"); + } + if (content.lastIndexOf("&") == content.length() - 1) { + content.deleteCharAt(content.length() - 1); + } + return content.toString(); + } + + /** + * 从证书内容验签 + * @param params 待验签的从支付宝接收到的参数Map + * @param alipayPublicCertContent 支付宝公钥证书内容 + * @param charset 参数内容编码集 + * @param signType 指定采用的签名方式,RSA或RSA2 + * @return true:验签通过;false:验签不通过 + * @throws AlipayApiException + */ + public static boolean rsaCertCheckV1ByContent(Map params, String alipayPublicCertContent, + String charset, String signType) throws AlipayApiException { + String publicKey = Base64.encodeBase64String( + AntCertificationUtil + .getCertFromContent(alipayPublicCertContent) + .getPublicKey() + .getEncoded() + ); + return rsaCheckV1(params, publicKey, charset, signType); + } +} diff --git a/ruoyi-alipay/src/main/java/enums/SignType.java b/ruoyi-alipay/src/main/java/enums/SignType.java new file mode 100644 index 00000000..96da02a9 --- /dev/null +++ b/ruoyi-alipay/src/main/java/enums/SignType.java @@ -0,0 +1,39 @@ +package enums; + +/** + *

IJPay 让支付触手可及,封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。

+ * + *

不依赖任何第三方 mvc 框架,仅仅作为工具使用简单快速完成支付模块的开发,可轻松嵌入到任何系统里。

+ * + *

IJPay 交流群: 723992875、864988890

+ * + *

Node.js 版: https://gitee.com/javen205/TNWX

+ * + *

签名方式

+ * + * @author Javen + */ +public enum SignType { + /** + * MD5 加密 + */ + MD5("MD5"), + /** + * RSA2 + */ + RSA2("RSA2"), + /** + * RSA + */ + RSA("RSA"); + + SignType(String type) { + this.type = type; + } + + private final String type; + + public String getType() { + return type; + } +} diff --git a/ruoyi-cai/lib/IJPay-AliPay-2.9.10.jar b/ruoyi-cai/lib/IJPay-AliPay-2.9.10.jar new file mode 100644 index 00000000..bcc5745e Binary files /dev/null and b/ruoyi-cai/lib/IJPay-AliPay-2.9.10.jar differ diff --git a/ruoyi-cai/pom.xml b/ruoyi-cai/pom.xml index f0f19220..e559ba56 100644 --- a/ruoyi-cai/pom.xml +++ b/ruoyi-cai/pom.xml @@ -40,10 +40,14 @@ IJPay-WxPay ${ijapy.version}
- + + + com.ruoyi + ruoyi-alipay com.ruoyi diff --git a/ruoyi-cai/src/main/java/com/ruoyi/cai/pay/PayConfigManager.java b/ruoyi-cai/src/main/java/com/ruoyi/cai/pay/PayConfigManager.java index e8344d86..180a35fa 100644 --- a/ruoyi-cai/src/main/java/com/ruoyi/cai/pay/PayConfigManager.java +++ b/ruoyi-cai/src/main/java/com/ruoyi/cai/pay/PayConfigManager.java @@ -87,14 +87,28 @@ public class PayConfigManager { } catch (Exception e) { log.error("实例化AliPayApiConfig..."); // 如果Map中没有当前支付宝的实例就初始化并添加到Map中 - aliPayApiConfig = AliPayApiConfig.builder() - .setAppId(payConfig.getAppid()) - .setAliPayPublicKey(payConfig.getPublicKey()) - .setCharset("UTF-8") - .setPrivateKey(payConfig.getPrivateKey()) - .setServiceUrl(payConfig.getNotifyUrl()) - .setSignType("RSA2") - .build(); + if(caiProperties.isOpenPayProxy()){ + aliPayApiConfig = AliPayApiConfig.builder() + .setAppId(payConfig.getAppid()) + .setAliPayPublicKey(payConfig.getPublicKey()) + .setCharset("UTF-8") + .setPrivateKey(payConfig.getPrivateKey()) + .setServiceUrl(payConfig.getNotifyUrl()) + .setSignType("RSA2") + .setProxyIp(caiProperties.getProxyIp()) + .setProxyPort(caiProperties.getProxyHost()) + .buildProxy(); + }else{ + aliPayApiConfig = AliPayApiConfig.builder() + .setAppId(payConfig.getAppid()) + .setAliPayPublicKey(payConfig.getPublicKey()) + .setCharset("UTF-8") + .setPrivateKey(payConfig.getPrivateKey()) + .setServiceUrl(payConfig.getNotifyUrl()) + .setSignType("RSA2") + .build(); + } + } AliPayApiConfigKit.setThreadLocalAliPayApiConfig(aliPayApiConfig); return true;