🆕 #1772 电商收付通增加支付结果查询和提现的接口

This commit is contained in:
cloudX
2020-09-22 12:21:00 +08:00
committed by GitHub
parent 020cd0aed4
commit 5f0d1b320a
12 changed files with 1473 additions and 903 deletions

View File

@@ -97,6 +97,18 @@ public interface EcommerceService {
*/
CombineTransactionsNotifyResult parseCombineNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
/**
* <pre>
* 合单查询订单API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/combine/chapter3_3.shtml
* </pre>
*
* @param outTradeNo 合单商户订单号
* @return 支付订单信息
* @throws WxPayException the wx pay exception
*/
CombineTransactionsResult queryCombineTransactions(String outTradeNo) throws WxPayException;
/**
* <pre>
* 服务商模式普通支付API(APP支付、JSAPI支付、H5支付、NATIVE支付).
@@ -139,6 +151,18 @@ public interface EcommerceService {
*/
PartnerTransactionsNotifyResult parsePartnerNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
/**
* <pre>
* 普通查询订单API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/e_transactions/chapter3_5.shtml
* </pre>
*
* @param request 商户订单信息
* @return 支付订单信息
* @throws WxPayException the wx pay exception
*/
PartnerTransactionsResult queryPartnerTransactions(PartnerTransactionsQueryRequest request) throws WxPayException;
/**
* <pre>
* 服务商账户实时余额
@@ -237,4 +261,27 @@ public interface EcommerceService {
*/
RefundsResult refunds(RefundsRequest request) throws WxPayException;
/**
* <pre>
* 二级商户账户余额提现API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_2.shtml
* </pre>
*
* @param request 提现请求
* @return 返回数据 return withdraw result
* @throws WxPayException the wx pay exception
*/
SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException;
/**
* <pre>
* 电商平台提现API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/fund/chapter3_5.shtml
* </pre>
*
* @param request 提现请求
* @return 返回数据 return withdraw result
* @throws WxPayException the wx pay exception
*/
SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException;
}

View File

@@ -20,6 +20,7 @@ import java.util.Objects;
@RequiredArgsConstructor
public class EcommerceServiceImpl implements EcommerceService {
private static final Gson GSON = new GsonBuilder().create();
private final WxPayService payService;
@@ -73,14 +74,24 @@ public class EcommerceServiceImpl implements EcommerceService {
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key);
CombineTransactionsNotifyResult notifyResult = GSON.fromJson(result, CombineTransactionsNotifyResult.class);
CombineTransactionsResult transactionsResult = GSON.fromJson(result, CombineTransactionsResult.class);
CombineTransactionsNotifyResult notifyResult = new CombineTransactionsNotifyResult();
notifyResult.setRawData(response);
notifyResult.setResult(transactionsResult);
return notifyResult;
} catch (GeneralSecurityException | IOException e) {
throw new WxPayException("解析报文异常!", e);
}
}
@Override
public CombineTransactionsResult queryCombineTransactions(String outTradeNo) throws WxPayException {
String url = String.format("%s/v3/combine-transactions/out-trade-no/%s", this.payService.getPayBaseUrl(), outTradeNo);
String response = this.payService.getV3(URI.create(url));
return GSON.fromJson(response, CombineTransactionsResult.class);
}
@Override
public TransactionsResult partner(TradeTypeEnum tradeType, PartnerTransactionsRequest request) throws WxPayException {
String url = this.payService.getPayBaseUrl() + tradeType.getPartnerUrl();
@@ -108,14 +119,29 @@ public class EcommerceServiceImpl implements EcommerceService {
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key);
PartnerTransactionsNotifyResult notifyResult = GSON.fromJson(result, PartnerTransactionsNotifyResult.class);
PartnerTransactionsResult transactionsResult = GSON.fromJson(result, PartnerTransactionsResult.class);
PartnerTransactionsNotifyResult notifyResult = new PartnerTransactionsNotifyResult();
notifyResult.setRawData(response);
notifyResult.setResult(transactionsResult);
return notifyResult;
} catch (GeneralSecurityException | IOException e) {
throw new WxPayException("解析报文异常!", e);
}
}
@Override
public PartnerTransactionsResult queryPartnerTransactions(PartnerTransactionsQueryRequest request) throws WxPayException {
String url = String.format("%s/v3/pay/partner/transactions/out-trade-no/%s", this.payService.getPayBaseUrl(), request.getOutTradeNo());
if (Objects.isNull(request.getOutTradeNo())) {
url = String.format("%s/v3/pay/partner/transactions/id/%s", this.payService.getPayBaseUrl(), request.getTransactionId());
}
String query = String.format("?sp_mchid=%s&sub_mchid=%s", request.getSpMchid(), request.getSubMchid());
URI uri = URI.create(url + query);
String response = this.payService.getV3(uri);
return GSON.fromJson(response, PartnerTransactionsResult.class);
}
@Override
public FundBalanceResult spNowBalance(SpAccountTypeEnum accountType) throws WxPayException {
String url = String.format("%s/v3/merchant/fund/balance/%s", this.payService.getPayBaseUrl(), accountType);
@@ -176,6 +202,26 @@ public class EcommerceServiceImpl implements EcommerceService {
return GSON.fromJson(response, RefundsResult.class);
}
@Override
public SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException {
String url = String.format("%s/v3/ecommerce/fund/withdraw", this.payService.getPayBaseUrl());
String response = this.payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(response, SubWithdrawResult.class);
}
@Override
public SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException {
String url = String.format("%s/v3/merchant/fund/withdraw", this.payService.getPayBaseUrl());
String response = this.payService.postV3(url, GSON.toJson(request));
return GSON.fromJson(response, SpWithdrawResult.class);
}
/**
* 校验通知签名
* @param header 通知头信息
* @param data 通知数据
* @return true:校验通过 false:校验不通过
*/
private boolean verifyNotifySign(SignatureHeader header, String data) {
String beforeSign = String.format("%s\n%s\n%s\n",
header.getTimeStamp(),