diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java index 7e2dff7b..e8bb1079 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/WxPayService.java @@ -388,6 +388,47 @@ public interface WxPayService { */ void report(WxPayReportRequest request) throws WxPayException; + /** + *
+ * 下载对账单. + * 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。 + * 注意: + * 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致,bill_type为REVOKED; + * 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取; + * 3、对账单中涉及金额的字段单位为“元”。 + * 4、对账单接口只能下载三个月以内的账单。 + * 接口链接:https://api.mch.weixin.qq.com/pay/downloadbill + * 详情请见: 下载对账单 + *+ * + * @param billDate 对账单日期 bill_date 下载对账单的日期,格式:20140603 + * @param billType 账单类型 bill_type ALL,返回当日所有订单信息,默认值,SUCCESS,返回当日成功支付的订单,REFUND,返回当日退款订单 + * @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。 + * @param deviceInfo 设备号 device_info 非必传参数,终端设备号 + * @return 对账内容原始字符串 + * @throws WxPayException the wx pay exception + */ + String downloadRawBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException; + + /** + *
+ * 下载对账单(适合于需要自定义子商户号和子商户appid的情形). + * 商户可以通过该接口下载历史交易清单。比如掉单、系统错误等导致商户侧和微信侧数据不一致,通过对账单核对后可校正支付状态。 + * 注意: + * 1、微信侧未成功下单的交易不会出现在对账单中。支付成功后撤销的交易会出现在对账单中,跟原支付单订单号一致,bill_type为REVOKED; + * 2、微信在次日9点启动生成前一天的对账单,建议商户10点后再获取; + * 3、对账单中涉及金额的字段单位为“元”。 + * 4、对账单接口只能下载三个月以内的账单。 + * 接口链接:https://api.mch.weixin.qq.com/pay/downloadbill + * 详情请见: 下载对账单 + *+ * + * @param request 下载对账单请求 + * @return 对账内容原始字符串 + * @throws WxPayException the wx pay exception + */ + String downloadRawBill(WxPayDownloadBillRequest request) throws WxPayException; + /** *
* 下载对账单. diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java index 291a646a..7578093a 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/service/impl/BaseWxPayServiceImpl.java @@ -496,7 +496,19 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { } @Override - public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) throws WxPayException { + public String downloadRawBill(String billDate, String billType, String tarType, String deviceInfo) + throws WxPayException { + return this.downloadRawBill(this.buildDownloadBillRequest(billDate, billType, tarType, deviceInfo)); + } + + @Override + public WxPayBillResult downloadBill(String billDate, String billType, String tarType, String deviceInfo) + throws WxPayException { + return this.downloadBill(this.buildDownloadBillRequest(billDate, billType, tarType, deviceInfo)); + } + + private WxPayDownloadBillRequest buildDownloadBillRequest(String billDate, String billType, String tarType, + String deviceInfo) throws WxPayException { if (!BillType.ALL.equals(billType)) { throw new WxPayException("目前仅支持ALL类型的对账单下载"); } @@ -506,12 +518,22 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { request.setBillDate(billDate); request.setTarType(tarType); request.setDeviceInfo(deviceInfo); - - return this.downloadBill(request); + return request; } @Override public WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException { + String responseContent = this.downloadRawBill(request); + + if (StringUtils.isEmpty(responseContent)) { + return null; + } + + return this.handleBill(request.getBillType(), responseContent); + } + + @Override + public String downloadRawBill(WxPayDownloadBillRequest request) throws WxPayException { request.checkAndSign(this.getConfig()); String url = this.getPayBaseUrl() + "/pay/downloadbill"; @@ -525,12 +547,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService { throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class)); } } - - if (StringUtils.isEmpty(responseContent)) { - return null; - } - - return this.handleBill(request.getBillType(), responseContent); + return responseContent; } private WxPayBillResult handleBill(String billType, String responseContent) {