diff --git a/service/README.md b/service/README.md index de4e088d..290251bb 100644 --- a/service/README.md +++ b/service/README.md @@ -31,3 +31,7 @@ | billdownload | 账单下载 |✔️|✔️| | ecommercesubsidy | 电商收付通补差 | |✔️| | ecommercerefund | 电商收付通退款 | |✔️| +| ecommercecombinepayments/app | 电商收付通 APP 支付 | | ✔️ | +| ecommercecombinepayments/jsapi | 电商收付通 JSAPI 支付 | | ✔️ | +| ecommercecombinepayments/nativepay | 电商收付通 Native 支付 | | ✔️ | +| ecommercecombinepayments/h5 | 电商收付通 H5 支付 | | ✔️ | diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExample.java new file mode 100644 index 00000000..b948cc46 --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExample.java @@ -0,0 +1,51 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.app; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.app.model.*; + +/** AppService使用示例 */ +public class AppServiceExample { + + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static AppService service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + + // 初始化服务 + service = new AppService.Builder().config(config).build(); + // ... 调用接口 + } + + /** APP支付下单 */ + public static PrepayResponse prepay() { + PrepayRequest request = new PrepayRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.prepay(request); + } + +} diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtensionExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtensionExample.java new file mode 100644 index 00000000..ced94549 --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtensionExample.java @@ -0,0 +1,60 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.app; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.app.model.*; + +public class AppServiceExtensionExample { + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static AppServiceExtension service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + // 初始化服务 + service = new AppServiceExtension.Builder().config(config).build(); + try { + // ... 调用接口 + PrepayWithRequestPaymentResponse response = prepayWithRequestPayment(); + System.out.println(response); + } catch (HttpException e) { // 发送HTTP请求失败 + // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义 + } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500 + // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义 + } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败 + // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义 + } + } + + /** APP支付下单,并返回APP调起支付数据 */ + public static PrepayWithRequestPaymentResponse prepayWithRequestPayment() { + // 微信开放平台审核通过的移动应用appid + String requestPaymentAppid = "test-appid"; + PrepayRequest request = new PrepayRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.prepayWithRequestPayment(request, requestPaymentAppid); + } + +} diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5ServiceExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5ServiceExample.java new file mode 100644 index 00000000..55e0780b --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5ServiceExample.java @@ -0,0 +1,51 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.h5; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.h5.model.*; + +/** H5Service使用示例 */ +public class H5ServiceExample { + + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static H5Service service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + + // 初始化服务 + service = new H5Service.Builder().config(config).build(); + // ... 调用接口 + } + + /** H5支付下单 */ + public static PrepayResponse prepay() { + PrepayRequest request = new PrepayRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.prepay(request); + } + +} diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExample.java new file mode 100644 index 00000000..d3cf05bc --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExample.java @@ -0,0 +1,52 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model.*; + +/** JsapiService使用示例 */ +public class JsapiServiceExample { + + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static JsapiService service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + + // 初始化服务 + service = new JsapiService.Builder().config(config).build(); + // ... 调用接口 + } + + + /** JSAPI支付下单 */ + public static PrepayResponse prepay() { + PrepayRequest request = new PrepayRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.prepay(request); + } + +} diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExtensionExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExtensionExample.java new file mode 100644 index 00000000..b1f97b79 --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExtensionExample.java @@ -0,0 +1,64 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model.*; + +public class JsapiServiceExtensionExample { + + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static com.wechat.pay.java.service.ecommercecombinepayments.jsapi.JsapiServiceExtension service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + // 初始化服务 + service = + new JsapiServiceExtension.Builder() + .config(config) + .signType("RSA") // 不填则默认为RSA + .build(); + try { + PrepayWithRequestPaymentResponse response = prepayWithRequestPayment(); + System.out.println(response); + } catch (HttpException e) { // 发送HTTP请求失败 + // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义 + } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500 + // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义 + } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败 + // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义 + } + } + + /** JSAPI支付下单,并返回JSAPI调起支付数据 */ + public static PrepayWithRequestPaymentResponse prepayWithRequestPayment() { + // 商户申请的公众号对应的appid,由微信支付生成,可在公众号后台查看 + String requestPaymentAppid = "test-request-payment-appid"; + PrepayRequest request = new PrepayRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.prepayWithRequestPayment(request, requestPaymentAppid); + } + +} diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/NativePayServiceExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/NativePayServiceExample.java new file mode 100644 index 00000000..dc0edf7e --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/NativePayServiceExample.java @@ -0,0 +1,52 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model.*; + +/** NativePayService使用示例 */ +public class NativePayServiceExample { + + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static NativePayService service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + + // 初始化服务 + service = new NativePayService.Builder().config(config).build(); + // ... 调用接口 + } + + /** Native支付预下单 */ + public static PrepayResponse prepay() { + PrepayRequest request = new PrepayRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.prepay(request); + } + + +} diff --git a/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/order/OrderServiceExample.java b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/order/OrderServiceExample.java new file mode 100644 index 00000000..3a1f9b24 --- /dev/null +++ b/service/src/example/java/com/wechat/pay/java/service/ecommercecombinepayments/order/OrderServiceExample.java @@ -0,0 +1,71 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.order; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.RSAAutoCertificateConfig; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.service.ecommercecombinepayments.order.model.CloseOrderRequest; +import com.wechat.pay.java.service.ecommercecombinepayments.order.model.QueryOrderByCombineOutTradeNoRequest; +import com.wechat.pay.java.service.ecommercecombinepayments.order.model.Transaction; + +/** OrderService使用示例 */ +public class OrderServiceExample { + + /** 商户号 */ + public static String merchantId = "190000****"; + + /** 商户API私钥路径 */ + public static String privateKeyPath = "/Users/yourname/your/path/apiclient_key.pem"; + + /** 商户证书序列号 */ + public static String merchantSerialNumber = "5157F09EFDC096DE15EBE81A47057A72********"; + + /** 商户APIV3密钥 */ + public static String apiV3Key = "..."; + + public static OrderService service; + + public static void main(String[] args) { + // 初始化商户配置 + Config config = + new RSAAutoCertificateConfig.Builder() + .merchantId(merchantId) + // 使用 com.wechat.pay.java.core.util 中的函数从本地文件中加载商户私钥,商户私钥会用来生成请求的签名 + .privateKeyFromPath(privateKeyPath) + .merchantSerialNumber(merchantSerialNumber) + .apiV3Key(apiV3Key) + .build(); + + // 初始化服务 + service = new OrderService.Builder().config(config).build(); + // ... 调用接口 + try { + closeOrder(); + } catch (HttpException e) { // 发送HTTP请求失败 + // 调用e.getHttpRequest()获取请求打印日志或上报监控,更多方法见HttpException定义 + } catch (ServiceException e) { // 服务返回状态小于200或大于等于300,例如500 + // 调用e.getResponseBody()获取返回体打印日志或上报监控,更多方法见ServiceException定义 + } catch (MalformedMessageException e) { // 服务返回成功,返回体类型不合法,或者解析返回体失败 + // 调用e.getMessage()获取信息打印日志或上报监控,更多方法见MalformedMessageException定义 + } + } + + /** 关闭订单 */ + public static void closeOrder() { + + CloseOrderRequest request = new CloseOrderRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + service.closeOrder(request); + } + + /** 商户订单号查询订单 */ + public static Transaction queryOrderByCombineOutTradeNo() { + + QueryOrderByCombineOutTradeNoRequest request = new QueryOrderByCombineOutTradeNoRequest(); + // 调用request.setXxx(val)设置所需参数,具体参数可见Request定义 + // 调用接口 + return service.queryOrderByCombineOutTradeNo(request); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppService.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppService.java new file mode 100644 index 00000000..935567cf --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppService.java @@ -0,0 +1,120 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.*; +import com.wechat.pay.java.service.ecommercecombinepayments.app.model.*; + +import static com.wechat.pay.java.core.util.GsonUtil.toJson; +import static java.util.Objects.requireNonNull; + +/** AppService服务 */ +public class AppService { + + private final HttpClient httpClient; + private final HostName hostName; + + private AppService(HttpClient httpClient, HostName hostName) { + this.httpClient = requireNonNull(httpClient); + this.hostName = hostName; + } + + /** AppService构造器 */ + public static class Builder { + + private HttpClient httpClient; + private HostName hostName; + + /** + * 设置请求配置,以该配置构造默认的httpClient,若未调用httpClient()方法,则必须调用该方法 + * + * @param config 请求配置 + * @return Builder + */ + public Builder config(Config config) { + this.httpClient = new DefaultHttpClientBuilder().config(config).build(); + + return this; + } + + /** + * 设置微信支付域名,可选,默认为api.mch.weixin.qq.com + * + * @param hostName 微信支付域名 + * @return Builder + */ + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + /** + * 设置自定义httpClient,若未调用config(),则必须调用该方法 + * + * @param httpClient httpClient + * @return Builder + */ + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * 构造服务 + * + * @return AppService + */ + public AppService build() { + return new AppService(httpClient, hostName); + } + } + + /** + * APP支付下单 + * + * @param request 请求参数 + * @return PrepayResponse + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public PrepayResponse prepay(PrepayRequest request) { + String requestPath = "https://api.mch.weixin.qq.com/v3/combine-transactions/app"; + PrepayRequest realRequest = request; + if (this.hostName != null) { + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); + } + HttpHeaders headers = new HttpHeaders(); + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); + HttpRequest httpRequest = + new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url(requestPath) + .headers(headers) + .body(createRequestBody(realRequest)) + .build(); + HttpResponse httpResponse = + httpClient.execute(httpRequest, PrepayResponse.class); + return httpResponse.getServiceResponse(); + } + + private RequestBody createRequestBody(Object request) { + return new JsonRequestBody.Builder().body(toJson(request)).build(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtension.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtension.java new file mode 100644 index 00000000..a3db0706 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtension.java @@ -0,0 +1,99 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.app; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.cipher.Signer; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.HostName; +import com.wechat.pay.java.core.http.HttpClient; +import com.wechat.pay.java.core.util.NonceUtil; +import com.wechat.pay.java.service.ecommercecombinepayments.app.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.Instant; + +/** + * APP 支付的扩展类。 + * + *

它封装了 AppService,并提供了一个增强的 APP 下单方法 prepayWithRequestPayment。 + */ +public class AppServiceExtension { + private final Signer signer; + private final AppService appService; + private static final Logger logger = LoggerFactory.getLogger(AppServiceExtension.class); + + private AppServiceExtension(Config config, HttpClient httpClient, HostName hostName) { + this.signer = config.createSigner(); + AppService.Builder builder = new AppService.Builder().config(config); + if (httpClient != null) { + builder.httpClient(httpClient); + } + if (hostName != null) { + builder.hostName(hostName); + } + this.appService = builder.build(); + } + + /** + * APP 支付下单,并返回 APP 调起支付数据。推荐使用! + * + *

请求成功后,该方法返回预支付交易会话标识 prepay_id 和客户端 APP 调起支付所需参数。 它相比 AppService.prepay + * 更简单易用,因为无需开发者自行计算调起支付签名。 + * + * @param request 请求参数 + * @param requestPaymentAppid 商户申请的公众号对应的appid + * @return PrepayWithRequestPaymentResponse + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public PrepayWithRequestPaymentResponse prepayWithRequestPayment( + PrepayRequest request, String requestPaymentAppid) { + String prepayId = appService.prepay(request).getPrepayId(); + long timestamp = Instant.now().getEpochSecond(); + String nonceStr = NonceUtil.createNonce(32); + String message = + requestPaymentAppid + "\n" + timestamp + "\n" + nonceStr + "\n" + prepayId + "\n"; + logger.debug("Message for RequestPayment signatures is[{}]", message); + String sign = signer.sign(message).getSign(); + PrepayWithRequestPaymentResponse response = new PrepayWithRequestPaymentResponse(); + response.setAppid(requestPaymentAppid); + response.setPartnerId(request.getCombineMchid()); + response.setPrepayId(prepayId); + response.setPackageVal("Sign=WXPay"); + response.setNonceStr(nonceStr); + response.setTimestamp(String.valueOf(timestamp)); + response.setSign(sign); + return response; + } + + public static class Builder { + private Config config; + + private HttpClient httpClient; + private HostName hostName; + + public Builder config(Config config) { + this.config = config; + return this; + } + + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + public AppServiceExtension build() { + return new AppServiceExtension(config, httpClient, hostName); + } + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/Amount.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/Amount.java new file mode 100644 index 00000000..d2bcbfda --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/Amount.java @@ -0,0 +1,53 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** Amount */ +public class Amount { + /** 总金额 说明:订单总金额,单位为分 */ + @SerializedName("total") + private Integer total; + + /** 货币类型 说明:CNY:人民币,境内商户号仅支持人民币。 */ + @SerializedName("currency") + private String currency; + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Amount {\n"); + sb.append(" total: ").append(toIndentedString(total)).append("\n"); + sb.append(" currency: ").append(toIndentedString(currency)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/CombinePayerInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/CombinePayerInfo.java new file mode 100644 index 00000000..4d98956e --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/CombinePayerInfo.java @@ -0,0 +1,24 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +public class CombinePayerInfo { + + @SerializedName("openid") + private String openid; + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Override + public String toString() { + return "CombinePayerInfo{" + + "openid='" + openid + '\'' + + '}'; + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayRequest.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayRequest.java new file mode 100644 index 00000000..498e81e2 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayRequest.java @@ -0,0 +1,148 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayRequest */ +public class PrepayRequest { + + + /** 合单商户appid 说明:合单发起方的appid */ + @SerializedName("combine_appid") + private String combineAppid; + + /** 合单商户号 说明:合单发起方商户号,服务商和电商模式下,传服务商商户号。*/ + @SerializedName("combine_mchid") + private String combineMchid; + + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + private String combineOutTradeNo; + + /** sceneInfo */ + @SerializedName("scene_info") + private SceneInfo sceneInfo; + + /** 子单信息 最多支持子单条数:50 */ + @SerializedName("sub_orders") + private List subOrders; + + /** 支付者信息 */ + @SerializedName("combine_payer_info") + private CombinePayerInfo combinePayerInfo; + + /** 交易起始时间 说明:交易起始时间,格式为rfc3339格式 */ + @SerializedName("time_start") + private String timeStart; + + /** 交易结束时间 说明:订单失效时间,格式为rfc3339格式 */ + @SerializedName("time_expire") + private String timeExpire; + + /** 通知地址 说明:有效性:1. HTTPS;2. 不允许携带查询串。 */ + @SerializedName("notify_url") + private String notifyUrl; + + public String getCombineAppid() { + return combineAppid; + } + + public void setCombineAppid(String combineAppid) { + this.combineAppid = combineAppid; + } + + public String getCombineMchid() { + return combineMchid; + } + + public void setCombineMchid(String combineMchid) { + this.combineMchid = combineMchid; + } + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String combineOutTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + public SceneInfo getSceneInfo() { + return sceneInfo; + } + + public void setSceneInfo(SceneInfo sceneInfo) { + this.sceneInfo = sceneInfo; + } + + public List getSubOrders() { + return subOrders; + } + + public void setSubOrders(List subOrders) { + this.subOrders = subOrders; + } + + public CombinePayerInfo getCombinePayerInfo() { + return combinePayerInfo; + } + + public void setCombinePayerInfo(CombinePayerInfo combinePayerInfo) { + this.combinePayerInfo = combinePayerInfo; + } + + public String getTimeStart() { + return timeStart; + } + + public void setTimeStart(String timeStart) { + this.timeStart = timeStart; + } + + public String getTimeExpire() { + return timeExpire; + } + + public void setTimeExpire(String timeExpire) { + this.timeExpire = timeExpire; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public void setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayRequest {\n"); + sb.append(" combineAppid: ").append(toIndentedString(combineAppid)).append("\n"); + sb.append(" combineMchid: ").append(toIndentedString(combineMchid)).append("\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append(" sceneInfo: ").append(toIndentedString(sceneInfo)).append("\n"); + sb.append(" subOrders: ").append(toIndentedString(subOrders)).append("\n"); + sb.append(" combinePayerInfo: ").append(toIndentedString(combinePayerInfo)).append("\n"); + sb.append(" timeStart: ").append(toIndentedString(timeStart)).append("\n"); + sb.append(" timeExpire: ").append(toIndentedString(timeExpire)).append("\n"); + sb.append(" notifyUrl: ").append(toIndentedString(notifyUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayResponse.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayResponse.java new file mode 100644 index 00000000..7ac3b562 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayResponse.java @@ -0,0 +1,40 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayResponse */ +public class PrepayResponse { + /** prepayId 说明:预支付交易会话标识 */ + @SerializedName("prepay_id") + private String prepayId; + + public String getPrepayId() { + return prepayId; + } + + public void setPrepayId(String prepayId) { + this.prepayId = prepayId; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayResponse {\n"); + sb.append(" prepayId: ").append(toIndentedString(prepayId)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayWithRequestPaymentResponse.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayWithRequestPaymentResponse.java new file mode 100644 index 00000000..be6d7d55 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/PrepayWithRequestPaymentResponse.java @@ -0,0 +1,100 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class PrepayWithRequestPaymentResponse { + + @SerializedName("appid") + private String appid; + + @SerializedName("partnerid") + private String partnerId; + + @SerializedName("prepayid") + private String prepayId; + + @SerializedName("package") + private String packageVal; + + @SerializedName("noncestr") + private String nonceStr; + + @SerializedName("timestamp") + private String timestamp; + + @SerializedName("sign") + private String sign; + + public String getAppid() { + return appid; + } + + public void setAppid(String appid) { + this.appid = appid; + } + + public String getPartnerId() { + return partnerId; + } + + public void setPartnerId(String partnerId) { + this.partnerId = partnerId; + } + + public String getPrepayId() { + return prepayId; + } + + public void setPrepayId(String prepayId) { + this.prepayId = prepayId; + } + + public String getPackageVal() { + return packageVal; + } + + public void setPackageVal(String packageVal) { + this.packageVal = packageVal; + } + + public String getNonceStr() { + return nonceStr; + } + + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; + } + + public String getTimestamp() { + return timestamp; + } + + public void setTimestamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getSign() { + return sign; + } + + public void setSign(String sign) { + this.sign = sign; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayWithRequestPaymentRequest {\n"); + sb.append(" appid: ").append(toIndentedString(appid)).append("\n"); + sb.append(" partnerId: ").append(toIndentedString(partnerId)).append("\n"); + sb.append(" prepayId: ").append(toIndentedString(prepayId)).append("\n"); + sb.append(" packageVal: ").append(toIndentedString(packageVal)).append("\n"); + sb.append(" nonceStr: ").append(toIndentedString(nonceStr)).append("\n"); + sb.append(" timestamp: ").append(toIndentedString(timestamp)).append("\n"); + sb.append(" sign: ").append(toIndentedString(sign)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SceneInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SceneInfo.java new file mode 100644 index 00000000..d1073a51 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SceneInfo.java @@ -0,0 +1,66 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 支付场景描述 */ +public class SceneInfo { + /** 用户终端IP 说明:用户终端IP */ + @SerializedName("payer_client_ip") + private String payerClientIp; + + /** 商户端设备号 说明:商户端设备号 */ + @SerializedName("device_id") + private String deviceId; + + /** storeInfo */ + @SerializedName("store_info") + private StoreInfo storeInfo; + + public String getPayerClientIp() { + return payerClientIp; + } + + public void setPayerClientIp(String payerClientIp) { + this.payerClientIp = payerClientIp; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public StoreInfo getStoreInfo() { + return storeInfo; + } + + public void setStoreInfo(StoreInfo storeInfo) { + this.storeInfo = storeInfo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SceneInfo {\n"); + sb.append(" payerClientIp: ").append(toIndentedString(payerClientIp)).append("\n"); + sb.append(" deviceId: ").append(toIndentedString(deviceId)).append("\n"); + sb.append(" storeInfo: ").append(toIndentedString(storeInfo)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SettleInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SettleInfo.java new file mode 100644 index 00000000..df14c83e --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SettleInfo.java @@ -0,0 +1,60 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +import com.google.gson.annotations.SerializedName; + +/** SettleInfo */ +public class SettleInfo { + /** profitSharing 说明:是否指定分账 */ + @SerializedName("profit_sharing") + private Boolean profitSharing; + + /** + * 补差金额 + * SettleInfo.profit_sharing为true时,该金额才生效。 + 注意:单笔订单最高补差金额为5000元 + */ + @SerializedName("subsidy_amount") + private Integer subsidyAmount; + + + + public Boolean getProfitSharing() { + return profitSharing; + } + + public void setProfitSharing(Boolean profitSharing) { + this.profitSharing = profitSharing; + } + + public Integer getSubsidyAmount() { + return subsidyAmount; + } + + public void setSubsidyAmount(Integer subsidyAmount) { + this.subsidyAmount = subsidyAmount; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SettleInfo {\n"); + sb.append(" profitSharing: ").append(toIndentedString(profitSharing)).append("\n"); + sb.append(" subsidyAmount: ").append(toIndentedString(subsidyAmount)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/StoreInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/StoreInfo.java new file mode 100644 index 00000000..7c4dc0f2 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/StoreInfo.java @@ -0,0 +1,79 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 商户门店信息 */ +public class StoreInfo { + /** 门店编号 说明:商户侧门店编号 */ + @SerializedName("id") + private String id; + + /** 门店名称 说明:商户侧门店名称 */ + @SerializedName("name") + private String name; + + /** 地区编码 说明:地区编码,详细请见微信支付提供的文档 */ + @SerializedName("area_code") + private String areaCode; + + /** 详细地址 说明:详细的商户门店地址 */ + @SerializedName("address") + private String address; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class StoreInfo {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" areaCode: ").append(toIndentedString(areaCode)).append("\n"); + sb.append(" address: ").append(toIndentedString(address)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SubOrder.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SubOrder.java new file mode 100644 index 00000000..3f640bab --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/model/SubOrder.java @@ -0,0 +1,137 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.app.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class SubOrder { + + /** 子商户号 说明:子单发起方商户号,必须与发起方appid有绑定关系。服务商和电商模式下,传服务商商户号。 */ + @SerializedName("mchid") + private String mchid; + + /** 附加数据 说明:附加数据 */ + @SerializedName("attach") + private String attach; + + /** amount */ + @SerializedName("amount") + private Amount amount; + + /** 子单商户订单号 */ + @SerializedName("out_trade_no") + private String outTradeNo; + + /** 订单优惠标记 说明:商品标记,代金券或立减优惠功能的参数。 */ + @SerializedName("goods_tag") + private String goodsTag; + + /** + * 二级商户号 + * 说明:二级商户商户号,由微信支付生成并下发。 + * 服务商子商户的商户号,被合单方。直连商户不用传二级商户号。 + * 注意:仅适用于电商平台,服务商*/ + @SerializedName("sub_mchid") + private String subMchid; + + /** 商品描述 说明:商品描述 */ + @SerializedName("description") + private String description; + + /** settleInfo */ + @SerializedName("settle_info") + private SettleInfo settleInfo; + + /** 子商户应用ID 说明:子商户申请的公众号appid */ + @SerializedName("sub_appid") + private String subAppid; + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public Amount getAmount() { + return amount; + } + + public void setAmount(Amount amount) { + this.amount = amount; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getGoodsTag() { + return goodsTag; + } + + public void setGoodsTag(String goodsTag) { + this.goodsTag = goodsTag; + } + + public String getSubMchid() { + return subMchid; + } + + public void setSubMchid(String subMchid) { + this.subMchid = subMchid; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public SettleInfo getSettleInfo() { + return settleInfo; + } + + public void setSettleInfo(SettleInfo settleInfo) { + this.settleInfo = settleInfo; + } + + public String getSubAppid() { + return subAppid; + } + + public void setSubAppid(String subAppid) { + this.subAppid = subAppid; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SubOrder {\n"); + sb.append(" mchid: ").append(toIndentedString(mchid)).append("\n"); + sb.append(" attach: ").append(toIndentedString(attach)).append("\n"); + sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); + sb.append(" outTradeNo: ").append(toIndentedString(outTradeNo)).append("\n"); + sb.append(" goodsTag: ").append(toIndentedString(goodsTag)).append("\n"); + sb.append(" subMchid: ").append(toIndentedString(subMchid)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" settleInfo: ").append(toIndentedString(settleInfo)).append("\n"); + sb.append(" subAppid: ").append(toIndentedString(subAppid)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/package-info.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/package-info.java new file mode 100644 index 00000000..aa0620bc --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/app/package-info.java @@ -0,0 +1,2 @@ +/** 服务商-合单支付APP支付API */ +package com.wechat.pay.java.service.ecommercecombinepayments.app; diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5Service.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5Service.java new file mode 100644 index 00000000..19cca04e --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5Service.java @@ -0,0 +1,120 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// H5支付 +// +// H5支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.*; +import com.wechat.pay.java.service.ecommercecombinepayments.h5.model.*; + +import static com.wechat.pay.java.core.util.GsonUtil.toJson; +import static java.util.Objects.requireNonNull; + +/** H5Service服务 */ +public class H5Service { + + private final HttpClient httpClient; + private final HostName hostName; + + private H5Service(HttpClient httpClient, HostName hostName) { + this.httpClient = requireNonNull(httpClient); + this.hostName = hostName; + } + + /** H5Service构造器 */ + public static class Builder { + + private HttpClient httpClient; + private HostName hostName; + + /** + * 设置请求配置,以该配置构造默认的httpClient,若未调用httpClient()方法,则必须调用该方法 + * + * @param config 请求配置 + * @return Builder + */ + public Builder config(Config config) { + this.httpClient = new DefaultHttpClientBuilder().config(config).build(); + + return this; + } + + /** + * 设置微信支付域名,可选,默认为api.mch.weixin.qq.com + * + * @param hostName 微信支付域名 + * @return Builder + */ + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + /** + * 设置自定义httpClient,若未调用config(),则必须调用该方法 + * + * @param httpClient httpClient + * @return Builder + */ + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * 构造服务 + * + * @return H5Service + */ + public H5Service build() { + return new H5Service(httpClient, hostName); + } + } + + /** + * H5支付下单 + * @throws ServiceException 发送 + * + * @param request 请求参数 + * @return PrepayResponse + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public PrepayResponse prepay(PrepayRequest request) { + String requestPath = "https://api.mch.weixin.qq.com/v3/combine-transactions/h5"; + PrepayRequest realRequest = request; + if (this.hostName != null) { + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); + } + HttpHeaders headers = new HttpHeaders(); + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); + HttpRequest httpRequest = + new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url(requestPath) + .headers(headers) + .body(createRequestBody(realRequest)) + .build(); + HttpResponse httpResponse = + httpClient.execute(httpRequest, PrepayResponse.class); + return httpResponse.getServiceResponse(); + } + + private RequestBody createRequestBody(Object request) { + return new JsonRequestBody.Builder().body(toJson(request)).build(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/Amount.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/Amount.java new file mode 100644 index 00000000..9b8b7273 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/Amount.java @@ -0,0 +1,53 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// H5支付 +// +// H5支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** Amount */ +public class Amount { + /** 总金额 说明:订单总金额,单位为分 */ + @SerializedName("total") + private Integer total; + + /** 货币类型 说明:CNY:人民币,境内商户号仅支持人民币。 */ + @SerializedName("currency") + private String currency; + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Amount {\n"); + sb.append(" total: ").append(toIndentedString(total)).append("\n"); + sb.append(" currency: ").append(toIndentedString(currency)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/CombinePayerInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/CombinePayerInfo.java new file mode 100644 index 00000000..5185e642 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/CombinePayerInfo.java @@ -0,0 +1,24 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +public class CombinePayerInfo { + + @SerializedName("openid") + private String openid; + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Override + public String toString() { + return "CombinePayerInfo{" + + "openid='" + openid + '\'' + + '}'; + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/H5Info.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/H5Info.java new file mode 100644 index 00000000..2e566aa4 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/H5Info.java @@ -0,0 +1,92 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// H5支付 +// +// H5支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** H5Info */ +public class H5Info { + /** 场景类型 说明:场景类型 */ + @SerializedName("type") + private String type; + + /** 应用名称 说明:应用名称 */ + @SerializedName("app_name") + private String appName; + + /** 网站URL 说明:网站URL */ + @SerializedName("app_url") + private String appUrl; + + /** iOS平台BundleID 说明:iOS平台BundleID */ + @SerializedName("bundle_id") + private String bundleId; + + /** Android平台PackageName 说明:Android平台PackageName */ + @SerializedName("package_name") + private String packageName; + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getAppName() { + return appName; + } + + public void setAppName(String appName) { + this.appName = appName; + } + + public String getAppUrl() { + return appUrl; + } + + public void setAppUrl(String appUrl) { + this.appUrl = appUrl; + } + + public String getBundleId() { + return bundleId; + } + + public void setBundleId(String bundleId) { + this.bundleId = bundleId; + } + + public String getPackageName() { + return packageName; + } + + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class H5Info {\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" appName: ").append(toIndentedString(appName)).append("\n"); + sb.append(" appUrl: ").append(toIndentedString(appUrl)).append("\n"); + sb.append(" bundleId: ").append(toIndentedString(bundleId)).append("\n"); + sb.append(" packageName: ").append(toIndentedString(packageName)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/PrepayRequest.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/PrepayRequest.java new file mode 100644 index 00000000..beb4457c --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/PrepayRequest.java @@ -0,0 +1,135 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayRequest */ +public class PrepayRequest { + + + /** 合单商户appid 说明:合单发起方的appid */ + @SerializedName("combine_appid") + private String combineAppid; + + /** 合单商户号 说明:合单发起方商户号,服务商和电商模式下,传服务商商户号。*/ + @SerializedName("combine_mchid") + private String combineMchid; + + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + private String combineOutTradeNo; + + /** sceneInfo */ + @SerializedName("scene_info") + private SceneInfo sceneInfo; + + /** 子单信息 最多支持子单条数:50 */ + @SerializedName("sub_orders") + private List subOrders; + + /** 交易起始时间 说明:交易起始时间,格式为rfc3339格式 */ + @SerializedName("time_start") + private String timeStart; + + /** 交易结束时间 说明:订单失效时间,格式为rfc3339格式 */ + @SerializedName("time_expire") + private String timeExpire; + + /** 通知地址 说明:有效性:1. HTTPS;2. 不允许携带查询串。 */ + @SerializedName("notify_url") + private String notifyUrl; + + public String getCombineAppid() { + return combineAppid; + } + + public void setCombineAppid(String combineAppid) { + this.combineAppid = combineAppid; + } + + public String getCombineMchid() { + return combineMchid; + } + + public void setCombineMchid(String combineMchid) { + this.combineMchid = combineMchid; + } + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String combineOutTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + public SceneInfo getSceneInfo() { + return sceneInfo; + } + + public void setSceneInfo(SceneInfo sceneInfo) { + this.sceneInfo = sceneInfo; + } + + public List getSubOrders() { + return subOrders; + } + + public void setSubOrders(List subOrders) { + this.subOrders = subOrders; + } + + public String getTimeStart() { + return timeStart; + } + + public void setTimeStart(String timeStart) { + this.timeStart = timeStart; + } + + public String getTimeExpire() { + return timeExpire; + } + + public void setTimeExpire(String timeExpire) { + this.timeExpire = timeExpire; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public void setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayRequest {\n"); + sb.append(" combineAppid: ").append(toIndentedString(combineAppid)).append("\n"); + sb.append(" combineMchid: ").append(toIndentedString(combineMchid)).append("\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append(" sceneInfo: ").append(toIndentedString(sceneInfo)).append("\n"); + sb.append(" subOrders: ").append(toIndentedString(subOrders)).append("\n"); + sb.append(" timeStart: ").append(toIndentedString(timeStart)).append("\n"); + sb.append(" timeExpire: ").append(toIndentedString(timeExpire)).append("\n"); + sb.append(" notifyUrl: ").append(toIndentedString(notifyUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/PrepayResponse.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/PrepayResponse.java new file mode 100644 index 00000000..97564f03 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/PrepayResponse.java @@ -0,0 +1,40 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// H5支付 +// +// H5支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayResponse */ +public class PrepayResponse { + /** h5Url 说明:支付跳转链接 */ + @SerializedName("h5_url") + private String h5Url; + + public String getH5Url() { + return h5Url; + } + + public void setH5Url(String h5Url) { + this.h5Url = h5Url; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayResponse {\n"); + sb.append(" h5Url: ").append(toIndentedString(h5Url)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SceneInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SceneInfo.java new file mode 100644 index 00000000..6e1023de --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SceneInfo.java @@ -0,0 +1,79 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// H5支付 +// +// H5支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 支付场景描述 */ +public class SceneInfo { + /** 用户终端IP 说明:用户终端IP */ + @SerializedName("payer_client_ip") + private String payerClientIp; + + /** 商户端设备号 说明:商户端设备号 */ + @SerializedName("device_id") + private String deviceId; + + /** storeInfo */ + @SerializedName("store_info") + private StoreInfo storeInfo; + + /** h5Info */ + @SerializedName("h5_info") + private H5Info h5Info; + + public String getPayerClientIp() { + return payerClientIp; + } + + public void setPayerClientIp(String payerClientIp) { + this.payerClientIp = payerClientIp; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public StoreInfo getStoreInfo() { + return storeInfo; + } + + public void setStoreInfo(StoreInfo storeInfo) { + this.storeInfo = storeInfo; + } + + public H5Info getH5Info() { + return h5Info; + } + + public void setH5Info(H5Info h5Info) { + this.h5Info = h5Info; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SceneInfo {\n"); + sb.append(" payerClientIp: ").append(toIndentedString(payerClientIp)).append("\n"); + sb.append(" deviceId: ").append(toIndentedString(deviceId)).append("\n"); + sb.append(" storeInfo: ").append(toIndentedString(storeInfo)).append("\n"); + sb.append(" h5Info: ").append(toIndentedString(h5Info)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SettleInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SettleInfo.java new file mode 100644 index 00000000..6d130c2e --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SettleInfo.java @@ -0,0 +1,60 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** SettleInfo */ +public class SettleInfo { + /** profitSharing 说明:是否指定分账 */ + @SerializedName("profit_sharing") + private Boolean profitSharing; + + /** + * 补差金额 + * SettleInfo.profit_sharing为true时,该金额才生效。 + 注意:单笔订单最高补差金额为5000元 + */ + @SerializedName("subsidy_amount") + private Integer subsidyAmount; + + + + public Boolean getProfitSharing() { + return profitSharing; + } + + public void setProfitSharing(Boolean profitSharing) { + this.profitSharing = profitSharing; + } + + public Integer getSubsidyAmount() { + return subsidyAmount; + } + + public void setSubsidyAmount(Integer subsidyAmount) { + this.subsidyAmount = subsidyAmount; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SettleInfo {\n"); + sb.append(" profitSharing: ").append(toIndentedString(profitSharing)).append("\n"); + sb.append(" subsidyAmount: ").append(toIndentedString(subsidyAmount)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/StoreInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/StoreInfo.java new file mode 100644 index 00000000..d8010768 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/StoreInfo.java @@ -0,0 +1,79 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// H5支付 +// +// H5支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 商户门店信息 */ +public class StoreInfo { + /** 门店编号 说明:商户侧门店编号 */ + @SerializedName("id") + private String id; + + /** 门店名称 说明:商户侧门店名称 */ + @SerializedName("name") + private String name; + + /** 地区编码 说明:地区编码,详细请见微信支付提供的文档 */ + @SerializedName("area_code") + private String areaCode; + + /** 详细地址 说明:详细的商户门店地址 */ + @SerializedName("address") + private String address; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class StoreInfo {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" areaCode: ").append(toIndentedString(areaCode)).append("\n"); + sb.append(" address: ").append(toIndentedString(address)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SubOrder.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SubOrder.java new file mode 100644 index 00000000..05560d11 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/model/SubOrder.java @@ -0,0 +1,137 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.h5.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class SubOrder { + + /** 子商户号 说明:子单发起方商户号,必须与发起方appid有绑定关系。服务商和电商模式下,传服务商商户号。 */ + @SerializedName("mchid") + private String mchid; + + /** 附加数据 说明:附加数据 */ + @SerializedName("attach") + private String attach; + + /** amount */ + @SerializedName("amount") + private Amount amount; + + /** 子单商户订单号 */ + @SerializedName("out_trade_no") + private String outTradeNo; + + /** 订单优惠标记 说明:商品标记,代金券或立减优惠功能的参数。 */ + @SerializedName("goods_tag") + private String goodsTag; + + /** + * 二级商户号 + * 说明:二级商户商户号,由微信支付生成并下发。 + * 服务商子商户的商户号,被合单方。直连商户不用传二级商户号。 + * 注意:仅适用于电商平台,服务商*/ + @SerializedName("sub_mchid") + private String subMchid; + + /** 商品描述 说明:商品描述 */ + @SerializedName("description") + private String description; + + /** settleInfo */ + @SerializedName("settle_info") + private SettleInfo settleInfo; + + /** 子商户应用ID 说明:子商户申请的公众号appid */ + @SerializedName("sub_appid") + private String subAppid; + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public Amount getAmount() { + return amount; + } + + public void setAmount(Amount amount) { + this.amount = amount; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getGoodsTag() { + return goodsTag; + } + + public void setGoodsTag(String goodsTag) { + this.goodsTag = goodsTag; + } + + public String getSubMchid() { + return subMchid; + } + + public void setSubMchid(String subMchid) { + this.subMchid = subMchid; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public SettleInfo getSettleInfo() { + return settleInfo; + } + + public void setSettleInfo(SettleInfo settleInfo) { + this.settleInfo = settleInfo; + } + + public String getSubAppid() { + return subAppid; + } + + public void setSubAppid(String subAppid) { + this.subAppid = subAppid; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SubOrder {\n"); + sb.append(" mchid: ").append(toIndentedString(mchid)).append("\n"); + sb.append(" attach: ").append(toIndentedString(attach)).append("\n"); + sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); + sb.append(" outTradeNo: ").append(toIndentedString(outTradeNo)).append("\n"); + sb.append(" goodsTag: ").append(toIndentedString(goodsTag)).append("\n"); + sb.append(" subMchid: ").append(toIndentedString(subMchid)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" settleInfo: ").append(toIndentedString(settleInfo)).append("\n"); + sb.append(" subAppid: ").append(toIndentedString(subAppid)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/package-info.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/package-info.java new file mode 100644 index 00000000..33a40131 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/package-info.java @@ -0,0 +1,2 @@ +/** 服务商-合单支付H5支付API */ +package com.wechat.pay.java.service.ecommercecombinepayments.h5; diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiService.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiService.java new file mode 100644 index 00000000..a3cace51 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiService.java @@ -0,0 +1,120 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.*; +import com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model.*; + +import static com.wechat.pay.java.core.util.GsonUtil.toJson; +import static java.util.Objects.requireNonNull; + +/** JsapiService服务 */ +public class JsapiService { + + private final HttpClient httpClient; + private final HostName hostName; + + private JsapiService(HttpClient httpClient, HostName hostName) { + this.httpClient = requireNonNull(httpClient); + this.hostName = hostName; + } + + /** JsapiService构造器 */ + public static class Builder { + + private HttpClient httpClient; + private HostName hostName; + + /** + * 设置请求配置,以该配置构造默认的httpClient,若未调用httpClient()方法,则必须调用该方法 + * + * @param config 请求配置 + * @return Builder + */ + public Builder config(Config config) { + this.httpClient = new DefaultHttpClientBuilder().config(config).build(); + + return this; + } + + /** + * 设置微信支付域名,可选,默认为api.mch.weixin.qq.com + * + * @param hostName 微信支付域名 + * @return Builder + */ + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + /** + * 设置自定义httpClient,若未调用config(),则必须调用该方法 + * + * @param httpClient httpClient + * @return Builder + */ + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * 构造服务 + * + * @return JsapiService + */ + public JsapiService build() { + return new JsapiService(httpClient, hostName); + } + } + + /** + * JSAPI支付下单 + * + * @param request 请求参数 + * @return PrepayResponse + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public PrepayResponse prepay(PrepayRequest request) { + String requestPath = "https://api.mch.weixin.qq.com/v3/combine-transactions/jsapi"; + PrepayRequest realRequest = request; + if (this.hostName != null) { + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); + } + HttpHeaders headers = new HttpHeaders(); + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); + HttpRequest httpRequest = + new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url(requestPath) + .headers(headers) + .body(createRequestBody(realRequest)) + .build(); + HttpResponse httpResponse = + httpClient.execute(httpRequest, PrepayResponse.class); + return httpResponse.getServiceResponse(); + } + + private RequestBody createRequestBody(Object request) { + return new JsonRequestBody.Builder().body(toJson(request)).build(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExtension.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExtension.java new file mode 100644 index 00000000..5c357067 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExtension.java @@ -0,0 +1,108 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.cipher.Signer; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.HostName; +import com.wechat.pay.java.core.http.HttpClient; +import com.wechat.pay.java.core.util.NonceUtil; +import com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model.*; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.time.Instant; + +/** + * JSAPI 支付的扩展类。 + * + *

它封装了 JsapiService,并提供了一个增强的 JSAPI 下单方法 prepayWithRequestPayment。 + */ +public class JsapiServiceExtension { + private final Signer signer; + private final String signType; + private final JsapiService jsapiService; + private static final Logger logger = LoggerFactory.getLogger(JsapiServiceExtension.class); + + private JsapiServiceExtension( + Config config, HttpClient httpClient, HostName hostName, String signType) { + this.signer = config.createSigner(); + JsapiService.Builder builder = new JsapiService.Builder().config(config); + this.signType = signType; + if (httpClient != null) { + builder.httpClient(httpClient); + } + if (hostName != null) { + builder.hostName(hostName); + } + this.jsapiService = builder.build(); + } + + /** + * JSAPI 支付下单,并返回 JSAPI 调起支付数据。推荐使用! + * + *

请求成功后,该方法返回预支付交易会话标识 prepay_id 和客户端 JSAPI 调起支付所需参数。 它相比 JsapiService.prepay + * 更简单易用,因为无需开发者自行计算调起支付签名。 + * + * @param request 请求参数 商户申请的公众号对应的appid + * @param requestPaymentAppid 商户申请的公众号对应的appid + * @return PrepayWithRequestPaymentResponse + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public PrepayWithRequestPaymentResponse prepayWithRequestPayment( + PrepayRequest request, String requestPaymentAppid) { + String prepayId = jsapiService.prepay(request).getPrepayId(); + long timestamp = Instant.now().getEpochSecond(); + String nonceStr = NonceUtil.createNonce(32); + String packageVal = "prepay_id=" + prepayId; + String message = + requestPaymentAppid + "\n" + timestamp + "\n" + nonceStr + "\n" + packageVal + "\n"; + logger.debug("Message for RequestPayment signatures is[{}]", message); + String sign = signer.sign(message).getSign(); + PrepayWithRequestPaymentResponse response = new PrepayWithRequestPaymentResponse(); + response.setAppId(requestPaymentAppid); + response.setTimeStamp(String.valueOf(timestamp)); + response.setNonceStr(nonceStr); + response.setPackageVal(packageVal); + response.setSignType(signType); + response.setPaySign(sign); + return response; + } + + public static class Builder { + private Config config; + private HttpClient httpClient; + private HostName hostName; + private String signType; + + public Builder config(Config config) { + this.config = config; + return this; + } + + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + public Builder signType(String signType) { + this.signType = signType; + return this; + } + + public JsapiServiceExtension build() { + return new JsapiServiceExtension( + config, httpClient, hostName, signType == null ? "RSA" : signType); + } + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/Amount.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/Amount.java new file mode 100644 index 00000000..dba035d5 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/Amount.java @@ -0,0 +1,53 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** Amount */ +public class Amount { + /** 总金额 说明:订单总金额,单位为分 */ + @SerializedName("total") + private Integer total; + + /** 货币类型 说明:CNY:人民币,境内商户号仅支持人民币。 */ + @SerializedName("currency") + private String currency; + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Amount {\n"); + sb.append(" total: ").append(toIndentedString(total)).append("\n"); + sb.append(" currency: ").append(toIndentedString(currency)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/CombinePayerInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/CombinePayerInfo.java new file mode 100644 index 00000000..26d9214c --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/CombinePayerInfo.java @@ -0,0 +1,36 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +public class CombinePayerInfo { + + @SerializedName("openid") + private String openid; + + @SerializedName("sub_openid") + private String subOpenid; + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + public String getSubOpenid() { + return subOpenid; + } + + public void setSubOpenid(String subOpenid) { + this.subOpenid = subOpenid; + } + + @Override + public String toString() { + return "CombinePayerInfo{" + + "openid='" + openid + '\'' + + "subOpenid='" + subOpenid + '\'' + + '}'; + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayRequest.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayRequest.java new file mode 100644 index 00000000..ed368875 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayRequest.java @@ -0,0 +1,148 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayRequest */ +public class PrepayRequest { + + + /** 合单商户appid 说明:合单发起方的appid */ + @SerializedName("combine_appid") + private String combineAppid; + + /** 合单商户号 说明:合单发起方商户号,服务商和电商模式下,传服务商商户号。*/ + @SerializedName("combine_mchid") + private String combineMchid; + + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + private String combineOutTradeNo; + + /** sceneInfo */ + @SerializedName("scene_info") + private SceneInfo sceneInfo; + + /** 子单信息 最多支持子单条数:50 */ + @SerializedName("sub_orders") + private List subOrders; + + /** 支付者信息 */ + @SerializedName("combine_payer_info") + private CombinePayerInfo combinePayerInfo; + + /** 交易起始时间 说明:交易起始时间,格式为rfc3339格式 */ + @SerializedName("time_start") + private String timeStart; + + /** 交易结束时间 说明:订单失效时间,格式为rfc3339格式 */ + @SerializedName("time_expire") + private String timeExpire; + + /** 通知地址 说明:有效性:1. HTTPS;2. 不允许携带查询串。 */ + @SerializedName("notify_url") + private String notifyUrl; + + public String getCombineAppid() { + return combineAppid; + } + + public void setCombineAppid(String combineAppid) { + this.combineAppid = combineAppid; + } + + public String getCombineMchid() { + return combineMchid; + } + + public void setCombineMchid(String combineMchid) { + this.combineMchid = combineMchid; + } + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String combineOutTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + public SceneInfo getSceneInfo() { + return sceneInfo; + } + + public void setSceneInfo(SceneInfo sceneInfo) { + this.sceneInfo = sceneInfo; + } + + public List getSubOrders() { + return subOrders; + } + + public void setSubOrders(List subOrders) { + this.subOrders = subOrders; + } + + public CombinePayerInfo getCombinePayerInfo() { + return combinePayerInfo; + } + + public void setCombinePayerInfo(CombinePayerInfo combinePayerInfo) { + this.combinePayerInfo = combinePayerInfo; + } + + public String getTimeStart() { + return timeStart; + } + + public void setTimeStart(String timeStart) { + this.timeStart = timeStart; + } + + public String getTimeExpire() { + return timeExpire; + } + + public void setTimeExpire(String timeExpire) { + this.timeExpire = timeExpire; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public void setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayRequest {\n"); + sb.append(" combineAppid: ").append(toIndentedString(combineAppid)).append("\n"); + sb.append(" combineMchid: ").append(toIndentedString(combineMchid)).append("\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append(" sceneInfo: ").append(toIndentedString(sceneInfo)).append("\n"); + sb.append(" subOrders: ").append(toIndentedString(subOrders)).append("\n"); + sb.append(" combinePayerInfo: ").append(toIndentedString(combinePayerInfo)).append("\n"); + sb.append(" timeStart: ").append(toIndentedString(timeStart)).append("\n"); + sb.append(" timeExpire: ").append(toIndentedString(timeExpire)).append("\n"); + sb.append(" notifyUrl: ").append(toIndentedString(notifyUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayResponse.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayResponse.java new file mode 100644 index 00000000..78db6585 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayResponse.java @@ -0,0 +1,40 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayResponse */ +public class PrepayResponse { + /** prepayId 说明:预支付交易会话标识 */ + @SerializedName("prepay_id") + private String prepayId; + + public String getPrepayId() { + return prepayId; + } + + public void setPrepayId(String prepayId) { + this.prepayId = prepayId; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayResponse {\n"); + sb.append(" prepayId: ").append(toIndentedString(prepayId)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayWithRequestPaymentResponse.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayWithRequestPaymentResponse.java new file mode 100644 index 00000000..06f512a8 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/PrepayWithRequestPaymentResponse.java @@ -0,0 +1,88 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class PrepayWithRequestPaymentResponse { + + @SerializedName("appId") + private String appId; + + @SerializedName("timeStamp") + private String timestamp; + + @SerializedName("nonceStr") + private String nonceStr; + + @SerializedName("package") + private String packageVal; + + @SerializedName("signType") + private String signType; + + @SerializedName("paySign") + private String paySign; + + public String getAppId() { + return appId; + } + + public void setAppId(String appId) { + this.appId = appId; + } + + public String getTimeStamp() { + return timestamp; + } + + public void setTimeStamp(String timestamp) { + this.timestamp = timestamp; + } + + public String getNonceStr() { + return nonceStr; + } + + public void setNonceStr(String nonceStr) { + this.nonceStr = nonceStr; + } + + public String getPackageVal() { + return packageVal; + } + + public void setPackageVal(String packageVal) { + this.packageVal = packageVal; + } + + public String getSignType() { + return signType; + } + + public void setSignType(String signType) { + this.signType = signType; + } + + public String getPaySign() { + return paySign; + } + + public void setPaySign(String paySign) { + this.paySign = paySign; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayWithRequestPaymentRequest {\n"); + sb.append(" appId: ").append(toIndentedString(appId)).append("\n"); + sb.append(" timestamp: ").append(toIndentedString(timestamp)).append("\n"); + sb.append(" nonceStr: ").append(toIndentedString(nonceStr)).append("\n"); + sb.append(" packageVal: ").append(toIndentedString(packageVal)).append("\n"); + sb.append(" signType: ").append(toIndentedString(signType)).append("\n"); + sb.append(" paySign: ").append(toIndentedString(paySign)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SceneInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SceneInfo.java new file mode 100644 index 00000000..a4230f14 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SceneInfo.java @@ -0,0 +1,66 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 支付场景描述 */ +public class SceneInfo { + /** 用户终端IP 说明:用户终端IP */ + @SerializedName("payer_client_ip") + private String payerClientIp; + + /** 商户端设备号 说明:商户端设备号 */ + @SerializedName("device_id") + private String deviceId; + + /** storeInfo */ + @SerializedName("store_info") + private StoreInfo storeInfo; + + public String getPayerClientIp() { + return payerClientIp; + } + + public void setPayerClientIp(String payerClientIp) { + this.payerClientIp = payerClientIp; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public StoreInfo getStoreInfo() { + return storeInfo; + } + + public void setStoreInfo(StoreInfo storeInfo) { + this.storeInfo = storeInfo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SceneInfo {\n"); + sb.append(" payerClientIp: ").append(toIndentedString(payerClientIp)).append("\n"); + sb.append(" deviceId: ").append(toIndentedString(deviceId)).append("\n"); + sb.append(" storeInfo: ").append(toIndentedString(storeInfo)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SettleInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SettleInfo.java new file mode 100644 index 00000000..4ad4c785 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SettleInfo.java @@ -0,0 +1,60 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** SettleInfo */ +public class SettleInfo { + /** profitSharing 说明:是否指定分账 */ + @SerializedName("profit_sharing") + private Boolean profitSharing; + + /** + * 补差金额 + * SettleInfo.profit_sharing为true时,该金额才生效。 + 注意:单笔订单最高补差金额为5000元 + */ + @SerializedName("subsidy_amount") + private Integer subsidyAmount; + + + + public Boolean getProfitSharing() { + return profitSharing; + } + + public void setProfitSharing(Boolean profitSharing) { + this.profitSharing = profitSharing; + } + + public Integer getSubsidyAmount() { + return subsidyAmount; + } + + public void setSubsidyAmount(Integer subsidyAmount) { + this.subsidyAmount = subsidyAmount; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SettleInfo {\n"); + sb.append(" profitSharing: ").append(toIndentedString(profitSharing)).append("\n"); + sb.append(" subsidyAmount: ").append(toIndentedString(subsidyAmount)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/StoreInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/StoreInfo.java new file mode 100644 index 00000000..6ad59143 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/StoreInfo.java @@ -0,0 +1,79 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 商户门店信息 */ +public class StoreInfo { + /** 门店编号 说明:商户侧门店编号 */ + @SerializedName("id") + private String id; + + /** 门店名称 说明:商户侧门店名称 */ + @SerializedName("name") + private String name; + + /** 地区编码 说明:地区编码,详细请见微信支付提供的文档 */ + @SerializedName("area_code") + private String areaCode; + + /** 详细地址 说明:详细的商户门店地址 */ + @SerializedName("address") + private String address; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class StoreInfo {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" areaCode: ").append(toIndentedString(areaCode)).append("\n"); + sb.append(" address: ").append(toIndentedString(address)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SubOrder.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SubOrder.java new file mode 100644 index 00000000..04282d77 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/model/SubOrder.java @@ -0,0 +1,137 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class SubOrder { + + /** 子商户号 说明:子单发起方商户号,必须与发起方appid有绑定关系。服务商和电商模式下,传服务商商户号。 */ + @SerializedName("mchid") + private String mchid; + + /** 附加数据 说明:附加数据 */ + @SerializedName("attach") + private String attach; + + /** amount */ + @SerializedName("amount") + private Amount amount; + + /** 子单商户订单号 */ + @SerializedName("out_trade_no") + private String outTradeNo; + + /** 订单优惠标记 说明:商品标记,代金券或立减优惠功能的参数。 */ + @SerializedName("goods_tag") + private String goodsTag; + + /** + * 二级商户号 + * 说明:二级商户商户号,由微信支付生成并下发。 + * 服务商子商户的商户号,被合单方。直连商户不用传二级商户号。 + * 注意:仅适用于电商平台,服务商*/ + @SerializedName("sub_mchid") + private String subMchid; + + /** 商品描述 说明:商品描述 */ + @SerializedName("description") + private String description; + + /** settleInfo */ + @SerializedName("settle_info") + private SettleInfo settleInfo; + + /** 子商户应用ID 说明:子商户申请的公众号appid */ + @SerializedName("sub_appid") + private String subAppid; + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public Amount getAmount() { + return amount; + } + + public void setAmount(Amount amount) { + this.amount = amount; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getGoodsTag() { + return goodsTag; + } + + public void setGoodsTag(String goodsTag) { + this.goodsTag = goodsTag; + } + + public String getSubMchid() { + return subMchid; + } + + public void setSubMchid(String subMchid) { + this.subMchid = subMchid; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public SettleInfo getSettleInfo() { + return settleInfo; + } + + public void setSettleInfo(SettleInfo settleInfo) { + this.settleInfo = settleInfo; + } + + public String getSubAppid() { + return subAppid; + } + + public void setSubAppid(String subAppid) { + this.subAppid = subAppid; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SubOrder {\n"); + sb.append(" mchid: ").append(toIndentedString(mchid)).append("\n"); + sb.append(" attach: ").append(toIndentedString(attach)).append("\n"); + sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); + sb.append(" outTradeNo: ").append(toIndentedString(outTradeNo)).append("\n"); + sb.append(" goodsTag: ").append(toIndentedString(goodsTag)).append("\n"); + sb.append(" subMchid: ").append(toIndentedString(subMchid)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" settleInfo: ").append(toIndentedString(settleInfo)).append("\n"); + sb.append(" subAppid: ").append(toIndentedString(subAppid)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/package-info.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/package-info.java new file mode 100644 index 00000000..3d877687 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/package-info.java @@ -0,0 +1,2 @@ +/** 服务商-合单支付JSAPI支付API */ +package com.wechat.pay.java.service.ecommercecombinepayments.jsapi; diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/NativePayService.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/NativePayService.java new file mode 100644 index 00000000..9af82a4b --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/NativePayService.java @@ -0,0 +1,120 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// Native支付 +// +// Native支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.*; +import com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model.*; + +import static com.wechat.pay.java.core.util.GsonUtil.toJson; +import static java.util.Objects.requireNonNull; + +/** NativePayService服务 */ +public class NativePayService { + + private final HttpClient httpClient; + private final HostName hostName; + + private NativePayService(HttpClient httpClient, HostName hostName) { + this.httpClient = requireNonNull(httpClient); + this.hostName = hostName; + } + + /** NativePayService构造器 */ + public static class Builder { + + private HttpClient httpClient; + private HostName hostName; + + /** + * 设置请求配置,以该配置构造默认的httpClient,若未调用httpClient()方法,则必须调用该方法 + * + * @param config 请求配置 + * @return Builder + */ + public Builder config(Config config) { + this.httpClient = new DefaultHttpClientBuilder().config(config).build(); + + return this; + } + + /** + * 设置微信支付域名,可选,默认为api.mch.weixin.qq.com + * + * @param hostName 微信支付域名 + * @return Builder + */ + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + /** + * 设置自定义httpClient,若未调用config(),则必须调用该方法 + * + * @param httpClient httpClient + * @return Builder + */ + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * 构造服务 + * + * @return NativePayService + */ + public NativePayService build() { + return new NativePayService(httpClient, hostName); + } + } + + /** + * Native支付预下单 + * + * @param request 请求参数 + * @return PrepayResponse + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public PrepayResponse prepay(PrepayRequest request) { + String requestPath = "https://api.mch.weixin.qq.com/v3/combine-transactions/native"; + PrepayRequest realRequest = request; + if (this.hostName != null) { + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); + } + HttpHeaders headers = new HttpHeaders(); + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); + HttpRequest httpRequest = + new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url(requestPath) + .headers(headers) + .body(createRequestBody(realRequest)) + .build(); + HttpResponse httpResponse = + httpClient.execute(httpRequest, PrepayResponse.class); + return httpResponse.getServiceResponse(); + } + + private RequestBody createRequestBody(Object request) { + return new JsonRequestBody.Builder().body(toJson(request)).build(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/Amount.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/Amount.java new file mode 100644 index 00000000..d75e31f3 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/Amount.java @@ -0,0 +1,53 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// Native支付 +// +// Native支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** Amount */ +public class Amount { + /** 总金额 说明:订单总金额,单位为分 */ + @SerializedName("total") + private Integer total; + + /** 货币类型 说明:CNY:人民币,境内商户号仅支持人民币。 */ + @SerializedName("currency") + private String currency; + + public Integer getTotal() { + return total; + } + + public void setTotal(Integer total) { + this.total = total; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Amount {\n"); + sb.append(" total: ").append(toIndentedString(total)).append("\n"); + sb.append(" currency: ").append(toIndentedString(currency)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/PrepayRequest.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/PrepayRequest.java new file mode 100644 index 00000000..ee36b579 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/PrepayRequest.java @@ -0,0 +1,135 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayRequest */ +public class PrepayRequest { + + + /** 合单商户appid 说明:合单发起方的appid */ + @SerializedName("combine_appid") + private String combineAppid; + + /** 合单商户号 说明:合单发起方商户号,服务商和电商模式下,传服务商商户号。*/ + @SerializedName("combine_mchid") + private String combineMchid; + + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + private String combineOutTradeNo; + + /** sceneInfo */ + @SerializedName("scene_info") + private SceneInfo sceneInfo; + + /** 子单信息 最多支持子单条数:50 */ + @SerializedName("sub_orders") + private List subOrders; + + /** 交易起始时间 说明:交易起始时间,格式为rfc3339格式 */ + @SerializedName("time_start") + private String timeStart; + + /** 交易结束时间 说明:订单失效时间,格式为rfc3339格式 */ + @SerializedName("time_expire") + private String timeExpire; + + /** 通知地址 说明:有效性:1. HTTPS;2. 不允许携带查询串。 */ + @SerializedName("notify_url") + private String notifyUrl; + + public String getCombineAppid() { + return combineAppid; + } + + public void setCombineAppid(String combineAppid) { + this.combineAppid = combineAppid; + } + + public String getCombineMchid() { + return combineMchid; + } + + public void setCombineMchid(String combineMchid) { + this.combineMchid = combineMchid; + } + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String combineOutTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + public SceneInfo getSceneInfo() { + return sceneInfo; + } + + public void setSceneInfo(SceneInfo sceneInfo) { + this.sceneInfo = sceneInfo; + } + + public List getSubOrders() { + return subOrders; + } + + public void setSubOrders(List subOrders) { + this.subOrders = subOrders; + } + + public String getTimeStart() { + return timeStart; + } + + public void setTimeStart(String timeStart) { + this.timeStart = timeStart; + } + + public String getTimeExpire() { + return timeExpire; + } + + public void setTimeExpire(String timeExpire) { + this.timeExpire = timeExpire; + } + + public String getNotifyUrl() { + return notifyUrl; + } + + public void setNotifyUrl(String notifyUrl) { + this.notifyUrl = notifyUrl; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayRequest {\n"); + sb.append(" combineAppid: ").append(toIndentedString(combineAppid)).append("\n"); + sb.append(" combineMchid: ").append(toIndentedString(combineMchid)).append("\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append(" sceneInfo: ").append(toIndentedString(sceneInfo)).append("\n"); + sb.append(" subOrders: ").append(toIndentedString(subOrders)).append("\n"); + sb.append(" timeStart: ").append(toIndentedString(timeStart)).append("\n"); + sb.append(" timeExpire: ").append(toIndentedString(timeExpire)).append("\n"); + sb.append(" notifyUrl: ").append(toIndentedString(notifyUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/PrepayResponse.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/PrepayResponse.java new file mode 100644 index 00000000..3896a801 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/PrepayResponse.java @@ -0,0 +1,40 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// Native支付 +// +// Native支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PrepayResponse */ +public class PrepayResponse { + /** codeUrl 说明:二维码链接 */ + @SerializedName("code_url") + private String codeUrl; + + public String getCodeUrl() { + return codeUrl; + } + + public void setCodeUrl(String codeUrl) { + this.codeUrl = codeUrl; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PrepayResponse {\n"); + sb.append(" codeUrl: ").append(toIndentedString(codeUrl)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SceneInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SceneInfo.java new file mode 100644 index 00000000..d76e42f3 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SceneInfo.java @@ -0,0 +1,66 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// Native支付 +// +// Native支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 支付场景描述 */ +public class SceneInfo { + /** 用户终端IP 说明:用户终端IP */ + @SerializedName("payer_client_ip") + private String payerClientIp; + + /** 商户端设备号 说明:商户端设备号 */ + @SerializedName("device_id") + private String deviceId; + + /** storeInfo */ + @SerializedName("store_info") + private StoreInfo storeInfo; + + public String getPayerClientIp() { + return payerClientIp; + } + + public void setPayerClientIp(String payerClientIp) { + this.payerClientIp = payerClientIp; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public StoreInfo getStoreInfo() { + return storeInfo; + } + + public void setStoreInfo(StoreInfo storeInfo) { + this.storeInfo = storeInfo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SceneInfo {\n"); + sb.append(" payerClientIp: ").append(toIndentedString(payerClientIp)).append("\n"); + sb.append(" deviceId: ").append(toIndentedString(deviceId)).append("\n"); + sb.append(" storeInfo: ").append(toIndentedString(storeInfo)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SettleInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SettleInfo.java new file mode 100644 index 00000000..c9ca8a6e --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SettleInfo.java @@ -0,0 +1,60 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** SettleInfo */ +public class SettleInfo { + /** profitSharing 说明:是否指定分账 */ + @SerializedName("profit_sharing") + private Boolean profitSharing; + + /** + * 补差金额 + * SettleInfo.profit_sharing为true时,该金额才生效。 + 注意:单笔订单最高补差金额为5000元 + */ + @SerializedName("subsidy_amount") + private Integer subsidyAmount; + + + + public Boolean getProfitSharing() { + return profitSharing; + } + + public void setProfitSharing(Boolean profitSharing) { + this.profitSharing = profitSharing; + } + + public Integer getSubsidyAmount() { + return subsidyAmount; + } + + public void setSubsidyAmount(Integer subsidyAmount) { + this.subsidyAmount = subsidyAmount; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SettleInfo {\n"); + sb.append(" profitSharing: ").append(toIndentedString(profitSharing)).append("\n"); + sb.append(" subsidyAmount: ").append(toIndentedString(subsidyAmount)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/StoreInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/StoreInfo.java new file mode 100644 index 00000000..d63abbd2 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/StoreInfo.java @@ -0,0 +1,79 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// Native支付 +// +// Native支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 商户门店信息 */ +public class StoreInfo { + /** 门店编号 说明:商户侧门店编号 */ + @SerializedName("id") + private String id; + + /** 门店名称 说明:商户侧门店名称 */ + @SerializedName("name") + private String name; + + /** 地区编码 说明:地区编码,详细请见微信支付提供的文档 */ + @SerializedName("area_code") + private String areaCode; + + /** 详细地址 说明:详细的商户门店地址 */ + @SerializedName("address") + private String address; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class StoreInfo {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" areaCode: ").append(toIndentedString(areaCode)).append("\n"); + sb.append(" address: ").append(toIndentedString(address)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SubOrder.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SubOrder.java new file mode 100644 index 00000000..0aafd62c --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/model/SubOrder.java @@ -0,0 +1,137 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class SubOrder { + + /** 子商户号 说明:子单发起方商户号,必须与发起方appid有绑定关系。服务商和电商模式下,传服务商商户号。 */ + @SerializedName("mchid") + private String mchid; + + /** 附加数据 说明:附加数据 */ + @SerializedName("attach") + private String attach; + + /** amount */ + @SerializedName("amount") + private Amount amount; + + /** 子单商户订单号 */ + @SerializedName("out_trade_no") + private String outTradeNo; + + /** 订单优惠标记 说明:商品标记,代金券或立减优惠功能的参数。 */ + @SerializedName("goods_tag") + private String goodsTag; + + /** + * 二级商户号 + * 说明:二级商户商户号,由微信支付生成并下发。 + * 服务商子商户的商户号,被合单方。直连商户不用传二级商户号。 + * 注意:仅适用于电商平台,服务商*/ + @SerializedName("sub_mchid") + private String subMchid; + + /** 商品描述 说明:商品描述 */ + @SerializedName("description") + private String description; + + /** settleInfo */ + @SerializedName("settle_info") + private SettleInfo settleInfo; + + /** 子商户应用ID 说明:子商户申请的公众号appid */ + @SerializedName("sub_appid") + private String subAppid; + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public Amount getAmount() { + return amount; + } + + public void setAmount(Amount amount) { + this.amount = amount; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getGoodsTag() { + return goodsTag; + } + + public void setGoodsTag(String goodsTag) { + this.goodsTag = goodsTag; + } + + public String getSubMchid() { + return subMchid; + } + + public void setSubMchid(String subMchid) { + this.subMchid = subMchid; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public SettleInfo getSettleInfo() { + return settleInfo; + } + + public void setSettleInfo(SettleInfo settleInfo) { + this.settleInfo = settleInfo; + } + + public String getSubAppid() { + return subAppid; + } + + public void setSubAppid(String subAppid) { + this.subAppid = subAppid; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SubOrder {\n"); + sb.append(" mchid: ").append(toIndentedString(mchid)).append("\n"); + sb.append(" attach: ").append(toIndentedString(attach)).append("\n"); + sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); + sb.append(" outTradeNo: ").append(toIndentedString(outTradeNo)).append("\n"); + sb.append(" goodsTag: ").append(toIndentedString(goodsTag)).append("\n"); + sb.append(" subMchid: ").append(toIndentedString(subMchid)).append("\n"); + sb.append(" description: ").append(toIndentedString(description)).append("\n"); + sb.append(" settleInfo: ").append(toIndentedString(settleInfo)).append("\n"); + sb.append(" subAppid: ").append(toIndentedString(subAppid)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/package-info.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/package-info.java new file mode 100644 index 00000000..2899093a --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/nativepay/package-info.java @@ -0,0 +1,2 @@ +/** 服务商-合单支付Native支付API */ +package com.wechat.pay.java.service.ecommercecombinepayments.nativepay; diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/OrderService.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/OrderService.java new file mode 100644 index 00000000..e800c4fa --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/OrderService.java @@ -0,0 +1,150 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.order; + +import com.wechat.pay.java.core.Config; +import com.wechat.pay.java.core.exception.HttpException; +import com.wechat.pay.java.core.exception.MalformedMessageException; +import com.wechat.pay.java.core.exception.ServiceException; +import com.wechat.pay.java.core.exception.ValidationException; +import com.wechat.pay.java.core.http.*; +import com.wechat.pay.java.service.ecommercecombinepayments.order.model.CloseOrderRequest; +import com.wechat.pay.java.service.ecommercecombinepayments.order.model.QueryOrderByCombineOutTradeNoRequest; +import com.wechat.pay.java.service.ecommercecombinepayments.order.model.Transaction; + +import static com.wechat.pay.java.core.http.UrlEncoder.urlEncode; +import static com.wechat.pay.java.core.util.GsonUtil.toJson; +import static java.util.Objects.requireNonNull; + +public class OrderService { + + private final HttpClient httpClient; + private final HostName hostName; + + private OrderService(HttpClient httpClient, HostName hostName) { + this.httpClient = requireNonNull(httpClient); + this.hostName = hostName; + } + + /** NativePayService构造器 */ + public static class Builder { + + private HttpClient httpClient; + private HostName hostName; + + /** + * 设置请求配置,以该配置构造默认的httpClient,若未调用httpClient()方法,则必须调用该方法 + * + * @param config 请求配置 + * @return Builder + */ + public Builder config(Config config) { + this.httpClient = new DefaultHttpClientBuilder().config(config).build(); + + return this; + } + + /** + * 设置微信支付域名,可选,默认为api.mch.weixin.qq.com + * + * @param hostName 微信支付域名 + * @return Builder + */ + public Builder hostName(HostName hostName) { + this.hostName = hostName; + return this; + } + + /** + * 设置自定义httpClient,若未调用config(),则必须调用该方法 + * + * @param httpClient httpClient + * @return Builder + */ + public Builder httpClient(HttpClient httpClient) { + this.httpClient = httpClient; + return this; + } + + /** + * 构造服务 + * + * @return NativePayService + */ + public OrderService build() { + return new OrderService(httpClient, hostName); + } + } + + /** + * 关闭订单 + * + * @param request 请求参数 + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public void closeOrder(CloseOrderRequest request) { + String requestPath = + "https://api.mch.weixin.qq.com/v3/combine-transactions/out-trade-no/{combine_out_trade_no}/close"; + + CloseOrderRequest realRequest = request; + // 添加 path param + requestPath = + requestPath.replace("{" + "combine_out_trade_no" + "}", urlEncode(realRequest.getCombineOutTradeNo())); + + if (this.hostName != null) { + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); + } + HttpHeaders headers = new HttpHeaders(); + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); + HttpRequest httpRequest = + new HttpRequest.Builder() + .httpMethod(HttpMethod.POST) + .url(requestPath) + .headers(headers) + .body(createRequestBody(realRequest)) + .build(); + httpClient.execute(httpRequest, null); + } + + /** + * 商户合单订单号查询订单 + * + * @param request 请求参数 + * @return Transaction + * @throws HttpException 发送HTTP请求失败。例如构建请求参数失败、发送请求失败、I/O错误等。包含请求信息。 + * @throws ValidationException 发送HTTP请求成功,验证微信支付返回签名失败。 + * @throws ServiceException 发送HTTP请求成功,服务返回异常。例如返回状态码小于200或大于等于300。 + * @throws MalformedMessageException 服务返回成功,content-type不为application/json、解析返回体失败。 + */ + public Transaction queryOrderByCombineOutTradeNo(QueryOrderByCombineOutTradeNoRequest request) { + String requestPath = + "https://api.mch.weixin.qq.com/v3/combine-transactions/out-trade-no/{combine_out_trade_no}"; + + QueryOrderByCombineOutTradeNoRequest realRequest = request; + // 添加 path param + requestPath = + requestPath.replace("{" + "combine_out_trade_no" + "}", urlEncode(realRequest.getCombineOutTradeNo())); + + if (this.hostName != null) { + requestPath = requestPath.replaceFirst(HostName.API.getValue(), hostName.getValue()); + } + HttpHeaders headers = new HttpHeaders(); + headers.addHeader(Constant.ACCEPT, MediaType.APPLICATION_JSON.getValue()); + headers.addHeader(Constant.CONTENT_TYPE, MediaType.APPLICATION_JSON.getValue()); + HttpRequest httpRequest = + new HttpRequest.Builder() + .httpMethod(HttpMethod.GET) + .url(requestPath) + .headers(headers) + .build(); + HttpResponse httpResponse = httpClient.execute(httpRequest, Transaction.class); + return httpResponse.getServiceResponse(); + } + + private RequestBody createRequestBody(Object request) { + return new JsonRequestBody.Builder().body(toJson(request)).build(); + } + +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/CloseOrderRequest.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/CloseOrderRequest.java new file mode 100644 index 00000000..6005363b --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/CloseOrderRequest.java @@ -0,0 +1,70 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** CloseOrderRequest */ +public class CloseOrderRequest { + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + @Expose(serialize = false) + private String combineOutTradeNo; + + /** 子单信息 最多支持子单条数:50 */ + @SerializedName("sub_orders") + private List subOrders; + + /** 合单商户appid 说明:合单发起方的appid */ + @SerializedName("combine_appid") + private String combineAppid; + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String combineOutTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + public List getSubOrders() { + return subOrders; + } + + public void setSubOrders(List subOrders) { + this.subOrders = subOrders; + } + + public String getCombineAppid() { + return combineAppid; + } + + public void setCombineAppid(String combineAppid) { + this.combineAppid = combineAppid; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class CloseOrderRequest {\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append(" subOrders: ").append(toIndentedString(subOrders)).append("\n"); + sb.append(" subMchid: ").append(toIndentedString(combineAppid)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/CloseSubOrder.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/CloseSubOrder.java new file mode 100644 index 00000000..6beacb65 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/CloseSubOrder.java @@ -0,0 +1,62 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +public class CloseSubOrder { + + /** + * 子单商户号 + */ + @SerializedName("mchid") + private String mchid; + + /** + * 子单商户订单号 + */ + @SerializedName("out_trade_no") + private String outTradeNo; + + /** + * 二级商户号 + */ + @SerializedName("sub_mchid") + private String subMchid; + + /** + * 子商户应用ID + */ + @SerializedName("sub_appid") + private String subAppid; + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getSubMchid() { + return subMchid; + } + + public void setSubMchid(String subMchid) { + this.subMchid = subMchid; + } + + public String getSubAppid() { + return subAppid; + } + + public void setSubAppid(String subAppid) { + this.subAppid = subAppid; + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/PromotionDetail.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/PromotionDetail.java new file mode 100644 index 00000000..2d6b8ea1 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/PromotionDetail.java @@ -0,0 +1,190 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PromotionDetail */ +public class PromotionDetail { + /** 券ID 说明:券ID */ + @SerializedName("coupon_id") + private String couponId; + + /** 优惠名称 说明:优惠名称 */ + @SerializedName("name") + private String name; + + /** GLOBAL:全场代金券;SINGLE:单品优惠 */ + public enum ScopeEnum { + @SerializedName("GLOBAL") + GLOBAL, + + @SerializedName("SINGLE") + SINGLE + } + + @SerializedName("scope") + private ScopeEnum scope; + + /** CASH:充值;NOCASH:预充值。 */ + public enum TypeEnum { + @SerializedName("CASH") + CASH, + + @SerializedName("NOCASH") + NOCASH + } + + @SerializedName("type") + private TypeEnum type; + + /** 优惠券面额 说明:优惠券面额 */ + @SerializedName("amount") + private Integer amount; + + /** 活动ID 说明:活动ID,批次ID */ + @SerializedName("stock_id") + private String stockId; + + /** 微信出资 说明:单位为分 */ + @SerializedName("wechatpay_contribute") + private Integer wechatpayContribute; + + /** 商户出资 说明:单位为分 */ + @SerializedName("merchant_contribute") + private Integer merchantContribute; + + /** 其他出资 说明:单位为分 */ + @SerializedName("other_contribute") + private Integer otherContribute; + + /** 优惠币种 说明:CNY:人民币,境内商户号仅支持人民币。 */ + @SerializedName("currency") + private String currency; + + /** 单品列表 说明: */ + @SerializedName("goods_detail") + private List goodsDetail; + + public String getCouponId() { + return couponId; + } + + public void setCouponId(String couponId) { + this.couponId = couponId; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public ScopeEnum getScope() { + return scope; + } + + public void setScope(ScopeEnum scope) { + this.scope = scope; + } + + public TypeEnum getType() { + return type; + } + + public void setType(TypeEnum type) { + this.type = type; + } + + public Integer getAmount() { + return amount; + } + + public void setAmount(Integer amount) { + this.amount = amount; + } + + public String getStockId() { + return stockId; + } + + public void setStockId(String stockId) { + this.stockId = stockId; + } + + public Integer getWechatpayContribute() { + return wechatpayContribute; + } + + public void setWechatpayContribute(Integer wechatpayContribute) { + this.wechatpayContribute = wechatpayContribute; + } + + public Integer getMerchantContribute() { + return merchantContribute; + } + + public void setMerchantContribute(Integer merchantContribute) { + this.merchantContribute = merchantContribute; + } + + public Integer getOtherContribute() { + return otherContribute; + } + + public void setOtherContribute(Integer otherContribute) { + this.otherContribute = otherContribute; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public List getGoodsDetail() { + return goodsDetail; + } + + public void setGoodsDetail(List goodsDetail) { + this.goodsDetail = goodsDetail; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PromotionDetail {\n"); + sb.append(" couponId: ").append(toIndentedString(couponId)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" scope: ").append(toIndentedString(scope)).append("\n"); + sb.append(" type: ").append(toIndentedString(type)).append("\n"); + sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); + sb.append(" stockId: ").append(toIndentedString(stockId)).append("\n"); + sb.append(" wechatpayContribute: ") + .append(toIndentedString(wechatpayContribute)) + .append("\n"); + sb.append(" merchantContribute: ").append(toIndentedString(merchantContribute)).append("\n"); + sb.append(" otherContribute: ").append(toIndentedString(otherContribute)).append("\n"); + sb.append(" currency: ").append(toIndentedString(currency)).append("\n"); + sb.append(" goodsDetail: ").append(toIndentedString(goodsDetail)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/PromotionGoodsDetail.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/PromotionGoodsDetail.java new file mode 100644 index 00000000..07f86c0e --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/PromotionGoodsDetail.java @@ -0,0 +1,92 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** PromotionGoodsDetail */ +public class PromotionGoodsDetail { + /** 商品编码 说明:商品编码 */ + @SerializedName("goods_id") + private String goodsId; + + /** 商品数量 说明:商品数量 */ + @SerializedName("quantity") + private Integer quantity; + + /** 商品价格 说明:商品价格 */ + @SerializedName("unit_price") + private Integer unitPrice; + + /** 商品优惠金额 说明:商品优惠金额 */ + @SerializedName("discount_amount") + private Integer discountAmount; + + /** 商品备注 说明:商品备注 */ + @SerializedName("goods_remark") + private String goodsRemark; + + public String getGoodsId() { + return goodsId; + } + + public void setGoodsId(String goodsId) { + this.goodsId = goodsId; + } + + public Integer getQuantity() { + return quantity; + } + + public void setQuantity(Integer quantity) { + this.quantity = quantity; + } + + public Integer getUnitPrice() { + return unitPrice; + } + + public void setUnitPrice(Integer unitPrice) { + this.unitPrice = unitPrice; + } + + public Integer getDiscountAmount() { + return discountAmount; + } + + public void setDiscountAmount(Integer discountAmount) { + this.discountAmount = discountAmount; + } + + public String getGoodsRemark() { + return goodsRemark; + } + + public void setGoodsRemark(String goodsRemark) { + this.goodsRemark = goodsRemark; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class PromotionGoodsDetail {\n"); + sb.append(" goodsId: ").append(toIndentedString(goodsId)).append("\n"); + sb.append(" quantity: ").append(toIndentedString(quantity)).append("\n"); + sb.append(" unitPrice: ").append(toIndentedString(unitPrice)).append("\n"); + sb.append(" discountAmount: ").append(toIndentedString(discountAmount)).append("\n"); + sb.append(" goodsRemark: ").append(toIndentedString(goodsRemark)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/QueryOrderByCombineOutTradeNoRequest.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/QueryOrderByCombineOutTradeNoRequest.java new file mode 100644 index 00000000..59e29c1f --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/QueryOrderByCombineOutTradeNoRequest.java @@ -0,0 +1,42 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** QueryOrderByCombineOutTradeNoRequest */ +public class QueryOrderByCombineOutTradeNoRequest { + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + @Expose(serialize = false) + private String combineOutTradeNo; + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String outTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class QueryOrderByCombineOutTradeNoRequest {\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/SettleInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/SettleInfo.java new file mode 100644 index 00000000..7ed8442d --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/SettleInfo.java @@ -0,0 +1,60 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** SettleInfo */ +public class SettleInfo { + /** profitSharing 说明:是否指定分账 */ + @SerializedName("profit_sharing") + private Boolean profitSharing; + + /** + * 补差金额 + * SettleInfo.profit_sharing为true时,该金额才生效。 + 注意:单笔订单最高补差金额为5000元 + */ + @SerializedName("subsidy_amount") + private Integer subsidyAmount; + + + + public Boolean getProfitSharing() { + return profitSharing; + } + + public void setProfitSharing(Boolean profitSharing) { + this.profitSharing = profitSharing; + } + + public Integer getSubsidyAmount() { + return subsidyAmount; + } + + public void setSubsidyAmount(Integer subsidyAmount) { + this.subsidyAmount = subsidyAmount; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SettleInfo {\n"); + sb.append(" profitSharing: ").append(toIndentedString(profitSharing)).append("\n"); + sb.append(" subsidyAmount: ").append(toIndentedString(subsidyAmount)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/StoreInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/StoreInfo.java new file mode 100644 index 00000000..bbfcec01 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/StoreInfo.java @@ -0,0 +1,79 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 商户门店信息 */ +public class StoreInfo { + /** 门店编号 说明:商户侧门店编号 */ + @SerializedName("id") + private String id; + + /** 门店名称 说明:商户侧门店名称 */ + @SerializedName("name") + private String name; + + /** 地区编码 说明:地区编码,详细请见微信支付提供的文档 */ + @SerializedName("area_code") + private String areaCode; + + /** 详细地址 说明:详细的商户门店地址 */ + @SerializedName("address") + private String address; + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getAreaCode() { + return areaCode; + } + + public void setAreaCode(String areaCode) { + this.areaCode = areaCode; + } + + public String getAddress() { + return address; + } + + public void setAddress(String address) { + this.address = address; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class StoreInfo {\n"); + sb.append(" id: ").append(toIndentedString(id)).append("\n"); + sb.append(" name: ").append(toIndentedString(name)).append("\n"); + sb.append(" areaCode: ").append(toIndentedString(areaCode)).append("\n"); + sb.append(" address: ").append(toIndentedString(address)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/SubOrderDetail.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/SubOrderDetail.java new file mode 100644 index 00000000..2080e1c1 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/SubOrderDetail.java @@ -0,0 +1,234 @@ +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +public class SubOrderDetail { + + /** 子商户号 说明:子单发起方商户号,必须与发起方appid有绑定关系。服务商和电商模式下,传服务商商户号。 */ + @SerializedName("mchid") + private String mchid; + + /** tradeType */ + public enum TradeTypeEnum { + @SerializedName("JSAPI") + JSAPI, + + @SerializedName("NATIVE") + NATIVE, + + @SerializedName("APP") + APP, + + @SerializedName("MICROPAY") + MICROPAY, + + @SerializedName("MWEB") + MWEB, + + @SerializedName("FACEPAY") + FACEPAY + } + + @SerializedName("trade_type") + private TradeTypeEnum tradeType; + + /** tradeState */ + public enum TradeStateEnum { + @SerializedName("SUCCESS") + SUCCESS, + + @SerializedName("REFUND") + REFUND, + + @SerializedName("NOTPAY") + NOTPAY, + + @SerializedName("CLOSED") + CLOSED, + + @SerializedName("REVOKED") + REVOKED, + + @SerializedName("USERPAYING") + USERPAYING, + + @SerializedName("PAYERROR") + PAYERROR, + + @SerializedName("ACCEPT") + ACCEPT + } + + @SerializedName("trade_state") + private TradeStateEnum tradeState; + + /** bankType */ + @SerializedName("bank_type") + private String bankType; + + /** attach */ + @SerializedName("attach") + private String attach; + + /** successTime */ + @SerializedName("success_time") + private String successTime; + + /** transactionId */ + @SerializedName("transaction_id") + private String transactionId; + + /** outTradeNo */ + @SerializedName("out_trade_no") + private String outTradeNo; + + /** subMchid */ + @SerializedName("sub_mchid") + private String subMchid; + + /** subAppid */ + @SerializedName("sub_appid") + private String subAppid; + + /** subOpenid */ + @SerializedName("sub_openid") + private String subOpenid; + + /** amount */ + @SerializedName("amount") + private TransactionAmount amount; + + /** promotionDetail */ + @SerializedName("promotion_detail") + private List promotionDetail; + + public String getMchid() { + return mchid; + } + + public void setMchid(String mchid) { + this.mchid = mchid; + } + + public TradeTypeEnum getTradeType() { + return tradeType; + } + + public void setTradeType(TradeTypeEnum tradeType) { + this.tradeType = tradeType; + } + + public TradeStateEnum getTradeState() { + return tradeState; + } + + public void setTradeState(TradeStateEnum tradeState) { + this.tradeState = tradeState; + } + + public String getBankType() { + return bankType; + } + + public void setBankType(String bankType) { + this.bankType = bankType; + } + + public String getAttach() { + return attach; + } + + public void setAttach(String attach) { + this.attach = attach; + } + + public String getSuccessTime() { + return successTime; + } + + public void setSuccessTime(String successTime) { + this.successTime = successTime; + } + + public String getTransactionId() { + return transactionId; + } + + public void setTransactionId(String transactionId) { + this.transactionId = transactionId; + } + + public String getOutTradeNo() { + return outTradeNo; + } + + public void setOutTradeNo(String outTradeNo) { + this.outTradeNo = outTradeNo; + } + + public String getSubMchid() { + return subMchid; + } + + public void setSubMchid(String subMchid) { + this.subMchid = subMchid; + } + + public String getSubAppid() { + return subAppid; + } + + public void setSubAppid(String subAppid) { + this.subAppid = subAppid; + } + + public String getSubOpenid() { + return subOpenid; + } + + public void setSubOpenid(String subOpenid) { + this.subOpenid = subOpenid; + } + + public TransactionAmount getAmount() { + return amount; + } + + public void setAmount(TransactionAmount amount) { + this.amount = amount; + } + + public List getPromotionDetail() { + return promotionDetail; + } + + public void setPromotionDetail(List promotionDetail) { + this.promotionDetail = promotionDetail; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SubOrderDetail {\n"); + sb.append(" mchid: ").append(toIndentedString(mchid)).append("\n"); + sb.append(" tradeType: ").append(toIndentedString(tradeType)).append("\n"); + sb.append(" tradeState: ").append(toIndentedString(tradeState)).append("\n"); + sb.append(" bankType: ").append(toIndentedString(bankType)).append("\n"); + sb.append(" attach: ").append(toIndentedString(attach)).append("\n"); + sb.append(" successTime: ").append(toIndentedString(successTime)).append("\n"); + sb.append(" transactionId: ").append(toIndentedString(transactionId)).append("\n"); + sb.append(" outTradeNo: ").append(toIndentedString(outTradeNo)).append("\n"); + sb.append(" subMchid: ").append(toIndentedString(subMchid)).append("\n"); + sb.append(" subAppid: ").append(toIndentedString(subAppid)).append("\n"); + sb.append(" subOpenid: ").append(toIndentedString(subOpenid)).append("\n"); + sb.append(" amount: ").append(toIndentedString(amount)).append("\n"); + sb.append(" promotionDetail: ").append(toIndentedString(promotionDetail)).append("\n"); + sb.append("}"); + return sb.toString(); + } + +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/Transaction.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/Transaction.java new file mode 100644 index 00000000..2cc899db --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/Transaction.java @@ -0,0 +1,108 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import java.util.List; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** */ +public class Transaction { + + /** 合单商户appid 说明:合单发起方的appid */ + @SerializedName("combine_appid") + private String combineAppid; + + /** 合单商户号 说明:合单发起方商户号,服务商和电商模式下,传服务商商户号。*/ + @SerializedName("combine_mchid") + private String combineMchid; + + /** combineOutTradeNo 说明:合单商户订单号 */ + @SerializedName("combine_out_trade_no") + private String combineOutTradeNo; + + /** sceneInfo */ + @SerializedName("scene_info") + private TransactionSceneInfo sceneInfo; + + /** sceneInfo */ + @SerializedName("sub_orders") + private List subOrders; + + /** 支付者信息 */ + @SerializedName("combine_payer_info") + private TransactionPayer combinePayerInfo; + + public String getCombineAppid() { + return combineAppid; + } + + public void setCombineAppid(String combineAppid) { + this.combineAppid = combineAppid; + } + + public String getCombineMchid() { + return combineMchid; + } + + public void setCombineMchid(String combineMchid) { + this.combineMchid = combineMchid; + } + + public String getCombineOutTradeNo() { + return combineOutTradeNo; + } + + public void setCombineOutTradeNo(String combineOutTradeNo) { + this.combineOutTradeNo = combineOutTradeNo; + } + + public TransactionSceneInfo getSceneInfo() { + return sceneInfo; + } + + public void setSceneInfo(TransactionSceneInfo sceneInfo) { + this.sceneInfo = sceneInfo; + } + + public List getSubOrders() { + return subOrders; + } + + public void setSubOrders(List subOrders) { + this.subOrders = subOrders; + } + + public TransactionPayer getCombinePayerInfo() { + return combinePayerInfo; + } + + public void setCombinePayerInfo(TransactionPayer combinePayerInfo) { + this.combinePayerInfo = combinePayerInfo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class Transaction {\n"); + sb.append(" combineAppid: ").append(toIndentedString(combineAppid)).append("\n"); + sb.append(" combineMchid: ").append(toIndentedString(combineMchid)).append("\n"); + sb.append(" combineOutTradeNo: ").append(toIndentedString(combineOutTradeNo)).append("\n"); + sb.append(" sceneInfo: ").append(toIndentedString(sceneInfo)).append("\n"); + sb.append(" subOrders: ").append(toIndentedString(subOrders)).append("\n"); + sb.append(" combinePayerInfo: ").append(toIndentedString(combinePayerInfo)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionAmount.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionAmount.java new file mode 100644 index 00000000..9b145f86 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionAmount.java @@ -0,0 +1,80 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** TransactionAmount */ +public class TransactionAmount { + + /** 标价金额 */ + @SerializedName("total_amount") + private Integer totalAmount; + + /** 标价币种 */ + @SerializedName("currency") + private String currency; + + /** 现金支付金额 */ + @SerializedName("payer_amount") + private Integer payerAmount; + + /** 现金支付币种 */ + @SerializedName("payer_currency") + private String payerCurrency; + + public Integer getTotalAmount() { + return totalAmount; + } + + public void setTotalAmount(Integer totalAmount) { + this.totalAmount = totalAmount; + } + + public String getCurrency() { + return currency; + } + + public void setCurrency(String currency) { + this.currency = currency; + } + + public Integer getPayerAmount() { + return payerAmount; + } + + public void setPayerAmount(Integer payerAmount) { + this.payerAmount = payerAmount; + } + + public String getPayerCurrency() { + return payerCurrency; + } + + public void setPayerCurrency(String payerCurrency) { + this.payerCurrency = payerCurrency; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class TransactionAmount {\n"); + sb.append(" totalAmount: ").append(toIndentedString(totalAmount)).append("\n"); + sb.append(" currency: ").append(toIndentedString(currency)).append("\n"); + sb.append(" payerAmount: ").append(toIndentedString(payerAmount)).append("\n"); + sb.append(" payerCurrency: ").append(toIndentedString(payerCurrency)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionPayer.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionPayer.java new file mode 100644 index 00000000..c6ad4b7b --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionPayer.java @@ -0,0 +1,38 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// APP支付 +// +// APP支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + + +/** TransactionPayer */ +public class TransactionPayer { + + @SerializedName("openid") + private String openid; + + public String getOpenid() { + return openid; + } + + public void setOpenid(String openid) { + this.openid = openid; + } + + @Override + public String toString() { + return "CombinePayerInfo{" + + "openid='" + openid + '\'' + + '}'; + } + +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionSceneInfo.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionSceneInfo.java new file mode 100644 index 00000000..23e1c274 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/model/TransactionSceneInfo.java @@ -0,0 +1,66 @@ +// Copyright 2021 Tencent Inc. All rights reserved. +// +// JSAPI支付 +// +// JSAPI支付API +// +// API version: 1.2.3 + +// Code generated by WechatPay APIv3 Generator based on [OpenAPI +// Generator](https://openapi-generator.tech); DO NOT EDIT. + +package com.wechat.pay.java.service.ecommercecombinepayments.order.model; + +import com.google.gson.annotations.SerializedName; + +import static com.wechat.pay.java.core.util.StringUtil.toIndentedString; + +/** 支付场景描述 */ +public class TransactionSceneInfo { + /** 用户终端IP 说明:用户终端IP */ + @SerializedName("payer_client_ip") + private String payerClientIp; + + /** 商户端设备号 说明:商户端设备号 */ + @SerializedName("device_id") + private String deviceId; + + /** storeInfo */ + @SerializedName("store_info") + private StoreInfo storeInfo; + + public String getPayerClientIp() { + return payerClientIp; + } + + public void setPayerClientIp(String payerClientIp) { + this.payerClientIp = payerClientIp; + } + + public String getDeviceId() { + return deviceId; + } + + public void setDeviceId(String deviceId) { + this.deviceId = deviceId; + } + + public StoreInfo getStoreInfo() { + return storeInfo; + } + + public void setStoreInfo(StoreInfo storeInfo) { + this.storeInfo = storeInfo; + } + + @Override + public String toString() { + StringBuilder sb = new StringBuilder(); + sb.append("class SceneInfo {\n"); + sb.append(" payerClientIp: ").append(toIndentedString(payerClientIp)).append("\n"); + sb.append(" deviceId: ").append(toIndentedString(deviceId)).append("\n"); + sb.append(" storeInfo: ").append(toIndentedString(storeInfo)).append("\n"); + sb.append("}"); + return sb.toString(); + } +} diff --git a/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/package-info.java b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/package-info.java new file mode 100644 index 00000000..c9e66fa2 --- /dev/null +++ b/service/src/main/java/com/wechat/pay/java/service/ecommercecombinepayments/order/package-info.java @@ -0,0 +1,2 @@ +/** 服务商-合单支付公共接口 */ +package com.wechat.pay.java.service.ecommercecombinepayments.order;