Skip to content

Commit e1a233c

Browse files
committed
微信支付增加对账单下载返回原始字符串数据的downloadRawBill方法
1 parent 6720960 commit e1a233c

File tree

2 files changed

+67
-9
lines changed

2 files changed

+67
-9
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,47 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
388388
*/
389389
void report(WxPayReportRequest request) throws WxPayException;
390390

391+
/**
392+
* <pre>
393+
* 下载对账单.
394+
* 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。
395+
* 注意:
396+
* 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致,bill_type为REVOKED;
397+
* 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取;
398+
* 3、对账单中涉及金额的字段单位为“元”。
399+
* 4、对账单接口只能下载三个月以内的账单。
400+
* 接口链接:https://api.mch.weixin.qq.com/pay/downloadbill
401+
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">下载对账单</a>
402+
* </pre>
403+
*
404+
* @param billDate 对账单日期 bill_date 下载对账单的日期,格式:20140603
405+
* @param billType 账单类型 bill_type ALL,返回当日所有订单信息,默认值,SUCCESS,返回当日成功支付的订单,REFUND,返回当日退款订单
406+
* @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
407+
* @param deviceInfo 设备号 device_info 非必传参数,终端设备号
408+
* @return 对账内容原始字符串
409+
* @throws WxPayException the wx pay exception
410+
*/
411+
String downloadRawBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException;
412+
413+
/**
414+
* <pre>
415+
* 下载对账单(适合于需要自定义子商户号和子商户appid的情形).
416+
* 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。
417+
* 注意:
418+
* 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致,bill_type为REVOKED;
419+
* 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取;
420+
* 3、对账单中涉及金额的字段单位为“元”。
421+
* 4、对账单接口只能下载三个月以内的账单。
422+
* 接口链接:https://api.mch.weixin.qq.com/pay/downloadbill
423+
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">下载对账单</a>
424+
* </pre>
425+
*
426+
* @param request 下载对账单请求
427+
* @return 对账内容原始字符串
428+
* @throws WxPayException the wx pay exception
429+
*/
430+
String downloadRawBill(WxPayDownloadBillRequest request) throws WxPayException;
431+
391432
/**
392433
* <pre>
393434
* 下载对账单.

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,19 @@ public void report(WxPayReportRequest request) throws WxPayException {
496496
}
497497

498498
@Override
499-
public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException {
499+
public String downloadRawBill(String billDate, String billType, String tarType, String deviceInfo)
500+
throws WxPayException {
501+
return this.downloadRawBill(this.buildDownloadBillRequest(billDate, billType, tarType, deviceInfo));
502+
}
503+
504+
@Override
505+
public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo)
506+
throws WxPayException {
507+
return this.downloadBill(this.buildDownloadBillRequest(billDate, billType, tarType, deviceInfo));
508+
}
509+
510+
private WxPayDownloadBillRequest buildDownloadBillRequest(String billDate, String billType, String tarType,
511+
String deviceInfo) throws WxPayException {
500512
if (!BillType.ALL.equals(billType)) {
501513
throw new WxPayException("目前仅支持ALL类型的对账单下载");
502514
}
@@ -506,12 +518,22 @@ public WxPayBillResult downloadBill(String billDate, String billType, String tar
506518
request.setBillDate(billDate);
507519
request.setTarType(tarType);
508520
request.setDeviceInfo(deviceInfo);
509-
510-
return this.downloadBill(request);
521+
return request;
511522
}
512523

513524
@Override
514525
public WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException {
526+
String responseContent = this.downloadRawBill(request);
527+
528+
if (StringUtils.isEmpty(responseContent)) {
529+
return null;
530+
}
531+
532+
return this.handleBill(request.getBillType(), responseContent);
533+
}
534+
535+
@Override
536+
public String downloadRawBill(WxPayDownloadBillRequest request) throws WxPayException {
515537
request.checkAndSign(this.getConfig());
516538

517539
String url = this.getPayBaseUrl() + "/pay/downloadbill";
@@ -525,12 +547,7 @@ public WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxP
525547
throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));
526548
}
527549
}
528-
529-
if (StringUtils.isEmpty(responseContent)) {
530-
return null;
531-
}
532-
533-
return this.handleBill(request.getBillType(), responseContent);
550+
return responseContent;
534551
}
535552

536553
private WxPayBillResult handleBill(String billType, String responseContent) {

0 commit comments

Comments
 (0)