forked from wechatpay-apiv3/wechatpay-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
收付通合并支付相关接口对接实现(wechatpay-apiv3#282)
- Loading branch information
Showing
70 changed files
with
6,350 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...mple/java/com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../com/wechat/pay/java/service/ecommercecombinepayments/app/AppServiceExtensionExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...xample/java/com/wechat/pay/java/service/ecommercecombinepayments/h5/H5ServiceExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
.../java/com/wechat/pay/java/service/ecommercecombinepayments/jsapi/JsapiServiceExample.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} |
Oops, something went wrong.