Skip to content

Commit b4da5c9

Browse files
authored
🆕 #1885 【微信支付】电商收付通增加资金账单下载的接口
1 parent 57ab245 commit b4da5c9

File tree

9 files changed

+283
-22
lines changed

9 files changed

+283
-22
lines changed
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
6+
/**
7+
* 资金账单请求
8+
* @author: f00lish
9+
* @date: 2020/09/28
10+
*/
11+
@Data
12+
@Builder
13+
@ToString
14+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
15+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
16+
public class FundBillRequest {
17+
18+
/**
19+
* <pre>
20+
* 字段名:账单日期
21+
* 变量名:bill_date
22+
* 是否必填:是
23+
* 类型:string(10)
24+
* 描述:
25+
* 格式YYYY-MM-DD
26+
* 仅支持三个月内的账单下载申请。
27+
* 示例值:2019-06-11
28+
* </pre>
29+
*/
30+
@SerializedName(value = "bill_date")
31+
private String billDate;
32+
33+
34+
/**
35+
* <pre>
36+
* 字段名:资金账户类型
37+
* 变量名:account_type
38+
* 是否必填:是
39+
* 类型:string(32)
40+
* 描述:
41+
* 枚举值:
42+
* ALL:所有账户
43+
* 示例值:ALL
44+
* </pre>
45+
*/
46+
@SerializedName(value = "account_type")
47+
private String accountType;
48+
49+
/**
50+
* <pre>
51+
* 字段名:压缩类型
52+
* 变量名:tar_type
53+
* 是否必填:否
54+
* 类型:string(32)
55+
* 描述:
56+
* 不填则以不压缩的方式返回数据流
57+
* 枚举值:
58+
* GZIP:返回格式为.gzip的压缩包账单
59+
* 示例值:GZIP
60+
* </pre>
61+
*/
62+
@SerializedName(value = "tar_type")
63+
private String tarType;
64+
65+
/**
66+
* <pre>
67+
* 字段名:加密算法
68+
* 变量名:algorithm
69+
* 是否必填:是
70+
* 类型:string(32)
71+
* 描述:
72+
* 枚举值:
73+
* AEAD_AES_256_GCM:AEAD_AES_256_GCM加密算法
74+
* 示例值:AEAD_AES_256_GCM
75+
* </pre>
76+
*/
77+
@SerializedName(value = "algorithm")
78+
private String algorithm;
79+
}
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
package com.github.binarywang.wxpay.bean.ecommerce;
2+
3+
import com.google.gson.annotations.SerializedName;
4+
import lombok.*;
5+
6+
/**
7+
* 资金账单结果
8+
* @author: f00lish
9+
* @date: 2020/09/28
10+
*/
11+
@Data
12+
@Builder
13+
@ToString
14+
@NoArgsConstructor(access = AccessLevel.PRIVATE)
15+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
16+
public class FundBillResult {
17+
18+
/**
19+
* <pre>
20+
* 字段名:下载信息总数
21+
* 变量名:download_bill_count
22+
* 是否必填:是
23+
* 类型:int
24+
* 描述:
25+
* 下载信息总数
26+
* 示例值:1
27+
* </pre>
28+
*/
29+
@SerializedName(value = "download_bill_count")
30+
private int downloadBillCount;
31+
32+
33+
34+
/**
35+
* <pre>
36+
* 字段名:下载信息明细
37+
* 变量名:download_bill_list
38+
* 是否必填:否
39+
* 类型:array
40+
* 描述:
41+
* 下载信息明细
42+
* </pre>
43+
*/
44+
@SerializedName(value = "download_bill_list")
45+
private FundBill[] downloadBillList;
46+
47+
@Data
48+
public static class FundBill {
49+
50+
/**
51+
* <pre>
52+
* 字段名:账单文件序号
53+
* 变量名:bill_sequence
54+
* 是否必填:是
55+
* 类型:int
56+
* 描述:
57+
* 商户将多个文件按账单文件序号的顺序合并为完整的资金账单文件,起始值为1
58+
* 示例值:1
59+
* </pre>
60+
*/
61+
@SerializedName(value = "bill_sequence")
62+
private String billSequence;
63+
64+
/**
65+
* <pre>
66+
* 字段名:哈希类型
67+
* 变量名:hash_type
68+
* 是否必填:是
69+
* 类型:string(32)
70+
* 描述:
71+
* 枚举值:
72+
* SHA1:SHA1值
73+
* 示例值:SHA1
74+
* </pre>
75+
*/
76+
@SerializedName(value = "hash_type")
77+
private String hashType;
78+
79+
/**
80+
* <pre>
81+
* 字段名:哈希值
82+
* 变量名:hash_value
83+
* 是否必填:是
84+
* 类型:string(1024)
85+
* 描述:
86+
* 原始账单(gzip需要解压缩)的摘要值,用于校验文件的完整性。
87+
* 示例值:79bb0f45fc4c42234a918000b2668d689e2bde04
88+
* </pre>
89+
*/
90+
@SerializedName(value = "hash_value")
91+
private String hashValue;
92+
93+
/**
94+
* <pre>
95+
* 字段名:账单下载地址
96+
* 变量名:download_url
97+
* 是否必填:是
98+
* 类型:string(2048)
99+
* 描述:
100+
* 供下一步请求账单文件的下载地址,该地址30s内有效。
101+
* 示例值:https://api.mch.weixin.qq.com/v3/billdownload/file?token=xxx
102+
* </pre>
103+
*/
104+
@SerializedName(value = "download_url")
105+
private String downloadUrl;
106+
107+
108+
/**
109+
* <pre>
110+
* 字段名:加密密钥
111+
* 变量名:encrypt_key
112+
* 是否必填:是
113+
* 类型:string(512)
114+
* 描述:
115+
* 加密账单文件使用的加密密钥。密钥用商户证书的公钥进行加密,然后进行Base64编码
116+
* 示例值:YpkbxSne+mDwyXq//xYPmtr9eQ5LsH7zLMZSs+GSEcY4wjhlsfioS4n9X6q1ZBL0wM1v5qd7KhWuj0rFJ4N1FidP7Q8KDy25QDTt46wiKnsPKSCAXWRFNw1D2JmJBqZsc9y5g0DupONWKYB2GfRigRDEBVszj67uOIILPdxOKX1w3N4jvu0U9IFanJa7ldm70KVvYrMWVgQFDPbgjh1gVDbuTAjmPN88AobLdkiegnBUS2woDZW+PfhPo13kweOiR3h1gXIKRlnKnN3Jkkwpna/AFFijXrFphO3voSuiV0CfptfzTtcae4X3DYG3RSroKqmpa+5tuy2aU2VJUSIuFQ==
117+
* </pre>
118+
*/
119+
@SerializedName(value = "encrypt_key")
120+
private String encryptKey;
121+
122+
/**
123+
* <pre>
124+
* 字段名:随机字符串
125+
* 变量名:nonce
126+
* 是否必填:是
127+
* 类型:string(16)
128+
* 描述:
129+
* 加密账单文件使用的随机字符串
130+
* 示例值:a8607ef79034c49c
131+
* </pre>
132+
*/
133+
@SerializedName(value = "nonce")
134+
private String nonce;
135+
136+
137+
}
138+
139+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/BillRequest.java renamed to weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TradeBillRequest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import lombok.*;
55

66
/**
7-
* 账单请求
7+
* 交易账单请求
88
* @author: f00lish
99
* @date: 2020/09/28
1010
*/
@@ -13,7 +13,7 @@
1313
@ToString
1414
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1515
@AllArgsConstructor(access = AccessLevel.PRIVATE)
16-
public class BillRequest {
16+
public class TradeBillRequest {
1717

1818
/**
1919
* <pre>

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/BillResult.java renamed to weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/TradeBillResult.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import lombok.*;
55

66
/**
7-
* 账单结果
7+
* 交易账单结果
88
* @author: f00lish
99
* @date: 2020/09/28
1010
*/
@@ -13,7 +13,7 @@
1313
@ToString
1414
@NoArgsConstructor(access = AccessLevel.PRIVATE)
1515
@AllArgsConstructor(access = AccessLevel.PRIVATE)
16-
public class BillResult {
16+
public class TradeBillResult {
1717

1818
/**
1919
* <pre>

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/BillTypeEnum.java renamed to weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/ecommerce/enums/FundBillTypeEnum.java

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,16 @@
1010
*/
1111
@Getter
1212
@AllArgsConstructor
13-
public enum BillTypeEnum {
13+
public enum FundBillTypeEnum {
1414

1515
/**
16-
* 交易账单
16+
* 资金账单
1717
*/
18-
TRADE_BILL("%s/v3/bill/tradebill?%s"),
18+
FUND_FLOW_BILL("%s/v3/bill/fundflowbill?%s"),
1919
/**
20-
* 资金账单
20+
* 二级商户资金账单
2121
*/
22-
FUND_FLOW_BILL("%s/v3/bill/fundflowbill?%s");
23-
22+
SUB_FUND_FLOW_BILL("%s/v3/ecommerce/bill/fundflowbill?%s");
2423

2524
/**
2625
* url

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

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.binarywang.wxpay.service;
22

33
import com.github.binarywang.wxpay.bean.ecommerce.*;
4-
import com.github.binarywang.wxpay.bean.ecommerce.enums.BillTypeEnum;
4+
import com.github.binarywang.wxpay.bean.ecommerce.enums.FundBillTypeEnum;
55
import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum;
66
import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
77
import com.github.binarywang.wxpay.exception.WxPayException;
@@ -394,12 +394,24 @@ public interface EcommerceService {
394394
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pages/bill.shtml
395395
* </pre>
396396
*
397+
* @param request 请求信息。
398+
* @return 返回数据 return trade bill result
399+
* @throws WxPayException the wx pay exception
400+
*/
401+
TradeBillResult applyBill(TradeBillRequest request) throws WxPayException;
402+
403+
/**
404+
* <pre>
405+
* 申请资金账单API
406+
* 文档地址: https://pay.weixin.qq.com/wiki/doc/apiv3/wxpay/pay/bill/chapter3_2.shtml
407+
* </pre>
408+
*
397409
* @param billType 账单类型。
398-
* @param request 二级商户号
399-
* @return 返回数据 return bill result
410+
* @param request 请求信息
411+
* @return 返回数据 return fund bill result
400412
* @throws WxPayException the wx pay exception
401413
*/
402-
BillResult applyBill(BillTypeEnum billType, BillRequest request) throws WxPayException;
414+
FundBillResult applyFundBill(FundBillTypeEnum billType, FundBillRequest request) throws WxPayException;
403415

404416
/**
405417
* <pre>

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.github.binarywang.wxpay.service.impl;
22

33
import com.github.binarywang.wxpay.bean.ecommerce.*;
4-
import com.github.binarywang.wxpay.bean.ecommerce.enums.BillTypeEnum;
4+
import com.github.binarywang.wxpay.bean.ecommerce.enums.FundBillTypeEnum;
55
import com.github.binarywang.wxpay.bean.ecommerce.enums.SpAccountTypeEnum;
66
import com.github.binarywang.wxpay.bean.ecommerce.enums.TradeTypeEnum;
77
import com.github.binarywang.wxpay.exception.WxPayException;
@@ -295,10 +295,17 @@ public SettlementResult querySettlement(String subMchid) throws WxPayException {
295295
}
296296

297297
@Override
298-
public BillResult applyBill(BillTypeEnum billType, BillRequest request) throws WxPayException {
298+
public TradeBillResult applyBill(TradeBillRequest request) throws WxPayException {
299+
String url = String.format("%s/v3/bill/tradebill?%s", this.payService.getPayBaseUrl(), this.parseURLPair(request));
300+
String response = this.payService.getV3(URI.create(url));
301+
return GSON.fromJson(response, TradeBillResult.class);
302+
}
303+
304+
@Override
305+
public FundBillResult applyFundBill(FundBillTypeEnum billType, FundBillRequest request) throws WxPayException {
299306
String url = String.format(billType.getUrl(), this.payService.getPayBaseUrl(), this.parseURLPair(request));
300307
String response = this.payService.getV3(URI.create(url));
301-
return GSON.fromJson(response, BillResult.class);
308+
return GSON.fromJson(response, FundBillResult.class);
302309
}
303310

304311
@Override

0 commit comments

Comments
 (0)