Skip to content

Commit

Permalink
收付通合并支付相关接口对接实现(wechatpay-apiv3#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
liulipeng committed Jun 27, 2024
1 parent 36e70ff commit f9e71b4
Show file tree
Hide file tree
Showing 70 changed files with 6,350 additions and 0 deletions.
4 changes: 4 additions & 0 deletions service/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,7 @@
| billdownload | 账单下载 |✔️|✔️|
| ecommercesubsidy | 电商收付通补差 | |✔️|
| ecommercerefund | 电商收付通退款 | |✔️|
| ecommercecombinepayments/app | 电商收付通 APP 支付 | | ✔️ |
| ecommercecombinepayments/jsapi | 电商收付通 JSAPI 支付 | | ✔️ |
| ecommercecombinepayments/nativepay | 电商收付通 Native 支付 | | ✔️ |
| ecommercecombinepayments/h5 | 电商收付通 H5 支付 | | ✔️ |
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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();
// ... 调用接口
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);
}

/** APP支付下单 */
public static PrepayResponse prepay() {
PrepayRequest request = new PrepayRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.prepay(request);
}

/** 商户订单号查询订单 */
public static Transaction queryOrderByCombineOutTradeNo() {

QueryOrderByCombineOutTradeNoRequest request = new QueryOrderByCombineOutTradeNoRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.queryOrderByCombineOutTradeNo(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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定义
}
}

/** 关闭订单 */
public static void closeOrder() {

CloseOrderRequest request = new CloseOrderRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
service.closeOrder(request);
}

/** APP支付下单,并返回APP调起支付数据 */
public static PrepayWithRequestPaymentResponse prepayWithRequestPayment() {
// 微信开放平台审核通过的移动应用appid
String requestPaymentAppid = "test-appid";
PrepayRequest request = new PrepayRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.prepayWithRequestPayment(request, requestPaymentAppid);
}

/** 商户订单号查询订单 */
public static Transaction queryOrderByCombineOutTradeNo() {

QueryOrderByCombineOutTradeNoRequest request = new QueryOrderByCombineOutTradeNoRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.queryOrderByCombineOutTradeNo(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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();
// ... 调用接口
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);
}

/** H5支付下单 */
public static PrepayResponse prepay() {
PrepayRequest request = new PrepayRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.prepay(request);
}

/** 商户订单号查询订单 */
public static Transaction queryOrderByCombineOutTradeNo() {

QueryOrderByCombineOutTradeNoRequest request = new QueryOrderByCombineOutTradeNoRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.queryOrderByCombineOutTradeNo(request);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
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();
// ... 调用接口
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);
}

/** JSAPI支付下单 */
public static PrepayResponse prepay() {
PrepayRequest request = new PrepayRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.prepay(request);
}

/** 商户订单号查询订单 */
public static Transaction queryOrderByCombineOutTradeNo() {

QueryOrderByCombineOutTradeNoRequest request = new QueryOrderByCombineOutTradeNoRequest();
// 调用request.setXxx(val)设置所需参数,具体参数可见Request定义
// 调用接口
return service.queryOrderByCombineOutTradeNo(request);
}
}
Loading

0 comments on commit f9e71b4

Please sign in to comment.