微信支付增加对账单下载返回原始字符串数据的downloadRawBill方法

This commit is contained in:
Binary Wang 2018-11-11 21:25:01 +08:00
parent 6720960d54
commit e1a233c07b
2 changed files with 67 additions and 9 deletions

View File

@ -388,6 +388,47 @@ public interface WxPayService {
*/ */
void report(WxPayReportRequest request) throws WxPayException; void report(WxPayReportRequest request) throws WxPayException;
/**
* <pre>
* 下载对账单.
* 商户可以通过该接口下载历史交易清单比如掉单系统错误等导致商户侧和微信侧数据不一致通过对账单核对后可校正支付状态
* 注意
* 1微信侧未成功下单的交易不会出现在对账单中支付成功后撤销的交易会出现在对账单中跟原支付单订单号一致bill_type为REVOKED
* 2微信在次日9点启动生成前一天的对账单建议商户10点后再获取
* 3对账单中涉及金额的字段单位为
* 4对账单接口只能下载三个月以内的账单
* 接口链接https://api.mch.weixin.qq.com/pay/downloadbill
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">下载对账单</a>
* </pre>
*
* @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;
/**
* <pre>
* 下载对账单适合于需要自定义子商户号和子商户appid的情形.
* 商户可以通过该接口下载历史交易清单比如掉单系统错误等导致商户侧和微信侧数据不一致通过对账单核对后可校正支付状态
* 注意
* 1微信侧未成功下单的交易不会出现在对账单中支付成功后撤销的交易会出现在对账单中跟原支付单订单号一致bill_type为REVOKED
* 2微信在次日9点启动生成前一天的对账单建议商户10点后再获取
* 3对账单中涉及金额的字段单位为
* 4对账单接口只能下载三个月以内的账单
* 接口链接https://api.mch.weixin.qq.com/pay/downloadbill
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_6">下载对账单</a>
* </pre>
*
* @param request 下载对账单请求
* @return 对账内容原始字符串
* @throws WxPayException the wx pay exception
*/
String downloadRawBill(WxPayDownloadBillRequest request) throws WxPayException;
/** /**
* <pre> * <pre>
* 下载对账单. * 下载对账单.

View File

@ -496,7 +496,19 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
} }
@Override @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)) { if (!BillType.ALL.equals(billType)) {
throw new WxPayException("目前仅支持ALL类型的对账单下载"); throw new WxPayException("目前仅支持ALL类型的对账单下载");
} }
@ -506,12 +518,22 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
request.setBillDate(billDate); request.setBillDate(billDate);
request.setTarType(tarType); request.setTarType(tarType);
request.setDeviceInfo(deviceInfo); request.setDeviceInfo(deviceInfo);
return request;
return this.downloadBill(request);
} }
@Override @Override
public WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException { 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()); request.checkAndSign(this.getConfig());
String url = this.getPayBaseUrl() + "/pay/downloadbill"; String url = this.getPayBaseUrl() + "/pay/downloadbill";
@ -525,12 +547,7 @@ public abstract class BaseWxPayServiceImpl implements WxPayService {
throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class)); throw WxPayException.from(BaseWxPayResult.fromXML(responseContent, WxPayCommonResult.class));
} }
} }
return responseContent;
if (StringUtils.isEmpty(responseContent)) {
return null;
}
return this.handleBill(request.getBillType(), responseContent);
} }
private WxPayBillResult handleBill(String billType, String responseContent) { private WxPayBillResult handleBill(String billType, String responseContent) {