🆕 #1775 微信支付电商收付通增加修改二级商户结算账户和退款查询的接口

This commit is contained in:
cloudX
2020-09-23 12:27:45 +08:00
committed by GitHub
parent 5f0d1b320a
commit 807ed7d0b5
11 changed files with 1181 additions and 10 deletions

View File

@@ -225,6 +225,18 @@ public interface EcommerceService {
*/
ProfitSharingResult profitSharing(ProfitSharingRequest request) throws WxPayException;
/**
* <pre>
* 查询分账结果API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/profitsharing/chapter3_2.shtml
* </pre>
*
* @param request 查询分账请求
* @return 返回数据 profit sharing result
* @throws WxPayException the wx pay exception
*/
ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException;
/**
* <pre>
* 请求分账回退API
@@ -261,6 +273,45 @@ public interface EcommerceService {
*/
RefundsResult refunds(RefundsRequest request) throws WxPayException;
/**
* <pre>
* 查询退款API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml
* </pre>
*
* @param subMchid 二级商户号
* @param refundId 微信退款单号
* @return 返回数据 return refunds result
* @throws WxPayException the wx pay exception
*/
RefundQueryResult queryRefundByRefundId(String subMchid, String refundId) throws WxPayException;
/**
* <pre>
* 查询退款API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_2.shtml
* </pre>
*
* @param subMchid 二级商户号
* @param outRefundNo 商户退款单号
* @return 返回数据 return refunds result
* @throws WxPayException the wx pay exception
*/
RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRefundNo) throws WxPayException;
/**
* <pre>
* 退款通知回调数据处理
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/refunds/chapter3_3.shtml
* </pre>
*
* @param notifyData 通知数据
* @param header 通知头部数据,不传则表示不校验头
* @return 解密后通知数据 partner refund notify result
* @throws WxPayException the wx pay exception
*/
RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException;
/**
* <pre>
* 二级商户账户余额提现API
@@ -284,4 +335,29 @@ public interface EcommerceService {
* @throws WxPayException the wx pay exception
*/
SpWithdrawResult spWithdraw(SpWithdrawRequest request) throws WxPayException;
/**
* <pre>
* 修改结算帐号API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_4.shtml
* </pre>
*
* @param subMchid 二级商户号。
* @param request 结算帐号
* @throws WxPayException the wx pay exception
*/
void modifySettlement(String subMchid, SettlementRequest request) throws WxPayException;
/**
* <pre>
* 查询结算账户API
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/ecommerce/applyments/chapter3_5.shtml
* </pre>
*
* @param subMchid 二级商户号。
* @return 返回数据 return settlement result
* @throws WxPayException the wx pay exception
*/
SettlementResult querySettlement(String subMchid) throws WxPayException;
}

View File

@@ -181,6 +181,14 @@ public class EcommerceServiceImpl implements EcommerceService {
return GSON.fromJson(response, ProfitSharingResult.class);
}
@Override
public ProfitSharingResult queryProfitSharing(ProfitSharingQueryRequest request) throws WxPayException {
String url = String.format("%s/v3/ecommerce/profitsharing/orders?sub_mchid=%s&transaction_id=%s&out_order_no=%s",
this.payService.getPayBaseUrl(), request.getSubMchid(), request.getTransactionId(), request.getOutOrderNo());
String response = this.payService.getV3(URI.create(url));
return GSON.fromJson(response, ProfitSharingResult.class);
}
@Override
public ReturnOrdersResult returnOrders(ReturnOrdersRequest request) throws WxPayException {
String url = String.format("%s/v3/ecommerce/profitsharing/returnorders", this.payService.getPayBaseUrl());
@@ -202,6 +210,41 @@ public class EcommerceServiceImpl implements EcommerceService {
return GSON.fromJson(response, RefundsResult.class);
}
@Override
public RefundQueryResult queryRefundByRefundId(String subMchid, String refundId) throws WxPayException {
String url = String.format("%s/v3/ecommerce/refunds/id/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), refundId, subMchid);
String response = this.payService.getV3(URI.create(url));
return GSON.fromJson(response, RefundQueryResult.class);
}
@Override
public RefundQueryResult queryRefundByOutRefundNo(String subMchid, String outRefundNo) throws WxPayException {
String url = String.format("%s/v3/ecommerce/applyments/out-request-no/%s?sub_mchid=%s", this.payService.getPayBaseUrl(), outRefundNo, subMchid);
String response = this.payService.getV3(URI.create(url));
return GSON.fromJson(response, RefundQueryResult.class);
}
@Override
public RefundNotifyResult parseRefundNotifyResult(String notifyData, SignatureHeader header) throws WxPayException {
if(Objects.nonNull(header) && !this.verifyNotifySign(header, notifyData)){
throw new WxPayException("非法请求,头部信息验证失败");
}
NotifyResponse response = GSON.fromJson(notifyData, NotifyResponse.class);
NotifyResponse.Resource resource = response.getResource();
String cipherText = resource.getCiphertext();
String associatedData = resource.getAssociatedData();
String nonce = resource.getNonce();
String apiV3Key = this.payService.getConfig().getApiV3Key();
try {
String result = AesUtils.decryptToString(associatedData, nonce,cipherText, apiV3Key);
RefundNotifyResult notifyResult = GSON.fromJson(result, RefundNotifyResult.class);
notifyResult.setRawData(response);
return notifyResult;
} catch (GeneralSecurityException | IOException e) {
throw new WxPayException("解析报文异常!", e);
}
}
@Override
public SubWithdrawResult subWithdraw(SubWithdrawRequest request) throws WxPayException {
String url = String.format("%s/v3/ecommerce/fund/withdraw", this.payService.getPayBaseUrl());
@@ -216,6 +259,20 @@ public class EcommerceServiceImpl implements EcommerceService {
return GSON.fromJson(response, SpWithdrawResult.class);
}
@Override
public void modifySettlement(String subMchid, SettlementRequest request) throws WxPayException {
String url = String.format("%s/v3/apply4sub/sub_merchants/%s/modify-settlement", this.payService.getPayBaseUrl(), subMchid);
RsaCryptoUtil.encryptFields(request, this.payService.getConfig().getVerifier().getValidCertificate());
this.payService.postV3WithWechatpaySerial(url, GSON.toJson(request));
}
@Override
public SettlementResult querySettlement(String subMchid) throws WxPayException {
String url = String.format("%s/v3/apply4sub/sub_merchants/%s/settlement", this.payService.getPayBaseUrl(), subMchid);
String response = this.payService.getV3(URI.create(url));
return GSON.fromJson(response, SettlementResult.class);
}
/**
* 校验通知签名
* @param header 通知头信息