mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 18:46:10 +08:00 
			
		
		
		
	微信支付增加对账单下载返回原始字符串数据的downloadRawBill方法
This commit is contained in:
		| @ -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> | ||||||
|    * 下载对账单. |    * 下载对账单. | ||||||
|  | |||||||
| @ -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) { | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang