Skip to content

Commit cc6dd65

Browse files
cwivanbinarywang
authored andcommitted
#503 微信支付增加资金账单下载接口
1 parent 95e398d commit cc6dd65

File tree

7 files changed

+430
-36
lines changed

7 files changed

+430
-36
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package com.github.binarywang.wxpay.bean.request;
2+
3+
import com.github.binarywang.wxpay.constant.WxPayConstants.AccountType;
4+
import com.github.binarywang.wxpay.exception.WxPayException;
5+
import com.thoughtworks.xstream.annotations.XStreamAlias;
6+
import lombok.*;
7+
import me.chanjar.weixin.common.annotation.Required;
8+
import org.apache.commons.lang3.ArrayUtils;
9+
import org.apache.commons.lang3.StringUtils;
10+
11+
import java.util.Arrays;
12+
13+
/**
14+
* <pre>
15+
* 微信支付下载资金账单请求参数类
16+
* Created by cwivan on 2018-08-02.
17+
* </pre>
18+
*
19+
* @author <a href="https://github.com/cwivan">cwivan</a>
20+
*/
21+
@Data
22+
@EqualsAndHashCode(callSuper = true)
23+
@Builder(builderMethodName = "newBuilder")
24+
@NoArgsConstructor
25+
@AllArgsConstructor
26+
@XStreamAlias("xml")
27+
public class WxPayDownloadFundFlowRequest extends BaseWxPayRequest {
28+
private static final String[] ACCOUNT_TYPES = new String[]{AccountType.BASIC, AccountType.OPERATION, AccountType.FEES};
29+
private static final String SIGN_TYPE_HMAC_SHA256 = "HMAC-SHA256";
30+
private static final String TAR_TYPE_GZIP = "GZIP";
31+
32+
/**
33+
* <pre>
34+
* 对账单日期
35+
* bill_date
36+
* 是
37+
* String(8)
38+
* 20140603
39+
* 下载对账单的日期,格式:20140603
40+
* </pre>
41+
*/
42+
@Required
43+
@XStreamAlias("bill_date")
44+
private String billDate;
45+
46+
/**
47+
* <pre>
48+
* 资金账户类型
49+
* account_type
50+
* 是
51+
* Basic
52+
* String(8)
53+
* --Basic,基本账户
54+
* --Operation,运营账户
55+
* --Fees,手续费账户
56+
* </pre>
57+
*/
58+
@Required
59+
@XStreamAlias("account_type")
60+
private String accountType;
61+
62+
/**
63+
* <pre>
64+
* 压缩账单
65+
* tar_type
66+
* 否
67+
* String(8)
68+
* GZIP
69+
* 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
70+
* </pre>
71+
*/
72+
@XStreamAlias("tar_type")
73+
private String tarType;
74+
75+
@Override
76+
protected void checkConstraints() throws WxPayException {
77+
if (StringUtils.isNotBlank(this.getTarType()) && !TAR_TYPE_GZIP.equals(this.getTarType())) {
78+
throw new WxPayException("tar_type值如果存在,只能为GZIP");
79+
}
80+
81+
if (!ArrayUtils.contains(ACCOUNT_TYPES, this.getAccountType())) {
82+
throw new WxPayException(String.format("account_type必须为%s其中之一,实际值:%s",
83+
Arrays.toString(ACCOUNT_TYPES), this.getAccountType()));
84+
}
85+
/**
86+
* 目前仅支持HMAC-SHA256
87+
*/
88+
this.setSignType(SIGN_TYPE_HMAC_SHA256);
89+
}
90+
}
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.github.binarywang.wxpay.bean.result;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
import org.apache.commons.lang3.builder.ToStringStyle;
7+
8+
import java.io.Serializable;
9+
10+
/**
11+
* 记账时间:2018-02-01 04:21:23 微信支付业务单号:50000305742018020103387128253 资金流水单号:1900009231201802015884652186 业务名称:退款
12+
* 业务类型:退款 收支类型:支出 收支金额(元):0.02 账户结余(元):0.17 资金变更提交申请人:system 备注:缺货 业务凭证号:REF4200000068201801293084726067
13+
*
14+
* @author cwivan
15+
*/
16+
@Data
17+
@NoArgsConstructor
18+
public class WxPayFundFlowBaseResult implements Serializable {
19+
private static final long serialVersionUID = 4474557532904682718L;
20+
21+
@Override
22+
public String toString() {
23+
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
24+
}
25+
26+
/**
27+
* 记账时间
28+
*/
29+
private String BillingTime;
30+
/**
31+
* 微信支付业务单号
32+
*/
33+
private String bizTransactionId;
34+
/**
35+
* 资金流水单号
36+
*/
37+
private String fundFlowId;
38+
/**
39+
* 业务名称
40+
*/
41+
private String bizName;
42+
/**
43+
* 业务类型
44+
*/
45+
private String bizType;
46+
/**
47+
* 收支类型
48+
*/
49+
private String financialType;
50+
/**
51+
* 收支金额(元)
52+
*/
53+
private String financialFee;
54+
/**
55+
* 账户结余(元)
56+
*/
57+
private String AccountBalance;
58+
/**
59+
* 资金变更提交申请人
60+
*/
61+
private String fundApplicant;
62+
/**
63+
* 备注
64+
*/
65+
private String memo;
66+
/**
67+
* 业务凭证号
68+
*/
69+
private String bizVoucherId;
70+
71+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package com.github.binarywang.wxpay.bean.result;
2+
3+
import lombok.Data;
4+
import lombok.NoArgsConstructor;
5+
import org.apache.commons.lang3.builder.ToStringBuilder;
6+
import org.apache.commons.lang3.builder.ToStringStyle;
7+
8+
import java.io.Serializable;
9+
import java.util.List;
10+
11+
/**
12+
* <pre>
13+
* 下载资金账单接口响应结果对象类
14+
* Created by cwivan on 2018-08-02.
15+
* </pre>
16+
*
17+
* @author cwivan
18+
* @date 2018-08-02
19+
*/
20+
@Data
21+
@NoArgsConstructor
22+
public class WxPayFundFlowResult implements Serializable{
23+
private static final long serialVersionUID = 8371500036495349207L;
24+
25+
@Override
26+
public String toString() {
27+
return ToStringBuilder.reflectionToString(this, ToStringStyle.JSON_STYLE);
28+
}
29+
30+
/**
31+
* 资金流水返回对象
32+
*/
33+
private List<WxPayFundFlowBaseResult> wxPayFundFlowBaseResultList;
34+
35+
/**
36+
* 资金流水总笔数
37+
*/
38+
private String totalRecord;
39+
40+
/**
41+
* 收入笔数
42+
*/
43+
private String incomeRecord;
44+
45+
/**
46+
* 收入金额
47+
*/
48+
private String incomeAmount;
49+
50+
/**
51+
* 支出笔数
52+
*/
53+
private String expenditureRecord;
54+
55+
/**
56+
* 支出金额
57+
*/
58+
private String expenditureAmount;
59+
60+
}

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/constant/WxPayConstants.java

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

3-
import java.text.Format;
4-
import java.util.List;
5-
3+
import com.google.common.collect.Lists;
64
import org.apache.commons.lang3.time.FastDateFormat;
75

8-
import com.google.common.collect.Lists;
6+
import java.text.Format;
7+
import java.util.List;
98

109
/**
1110
* <pre>
@@ -106,6 +105,24 @@ public static class TradeType {
106105
public static final String MICROPAY = "MICROPAY";
107106
}
108107

108+
/**
109+
* 账户类型
110+
*/
111+
public static class AccountType{
112+
/**
113+
* 基本账户
114+
*/
115+
public static final String BASIC = "Basic";
116+
/**
117+
* 运营账户
118+
*/
119+
public static final String OPERATION = "Operation";
120+
/**
121+
* Fees
122+
*/
123+
public static final String FEES = "Fees";
124+
}
125+
109126
/**
110127
* 签名类型.
111128
*/

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

Lines changed: 43 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,19 @@
11
package com.github.binarywang.wxpay.service;
22

3-
import java.io.File;
4-
import java.util.Date;
5-
import java.util.Map;
6-
73
import com.github.binarywang.wxpay.bean.WxPayApiData;
8-
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryRequest;
9-
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponInfoQueryResult;
10-
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendRequest;
11-
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponSendResult;
12-
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryRequest;
13-
import com.github.binarywang.wxpay.bean.coupon.WxPayCouponStockQueryResult;
4+
import com.github.binarywang.wxpay.bean.coupon.*;
145
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
156
import com.github.binarywang.wxpay.bean.notify.WxPayRefundNotifyResult;
167
import com.github.binarywang.wxpay.bean.notify.WxScanPayNotifyResult;
17-
import com.github.binarywang.wxpay.bean.request.WxPayAuthcode2OpenidRequest;
18-
import com.github.binarywang.wxpay.bean.request.WxPayDownloadBillRequest;
19-
import com.github.binarywang.wxpay.bean.request.WxPayMicropayRequest;
20-
import com.github.binarywang.wxpay.bean.request.WxPayOrderCloseRequest;
21-
import com.github.binarywang.wxpay.bean.request.WxPayOrderQueryRequest;
22-
import com.github.binarywang.wxpay.bean.request.WxPayOrderReverseRequest;
23-
import com.github.binarywang.wxpay.bean.request.WxPayRefundQueryRequest;
24-
import com.github.binarywang.wxpay.bean.request.WxPayRefundRequest;
25-
import com.github.binarywang.wxpay.bean.request.WxPayReportRequest;
26-
import com.github.binarywang.wxpay.bean.request.WxPaySendRedpackRequest;
27-
import com.github.binarywang.wxpay.bean.request.WxPayShorturlRequest;
28-
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
29-
import com.github.binarywang.wxpay.bean.result.WxPayBillResult;
30-
import com.github.binarywang.wxpay.bean.result.WxPayMicropayResult;
31-
import com.github.binarywang.wxpay.bean.result.WxPayOrderCloseResult;
32-
import com.github.binarywang.wxpay.bean.result.WxPayOrderQueryResult;
33-
import com.github.binarywang.wxpay.bean.result.WxPayOrderReverseResult;
34-
import com.github.binarywang.wxpay.bean.result.WxPayRedpackQueryResult;
35-
import com.github.binarywang.wxpay.bean.result.WxPayRefundQueryResult;
36-
import com.github.binarywang.wxpay.bean.result.WxPayRefundResult;
37-
import com.github.binarywang.wxpay.bean.result.WxPaySendRedpackResult;
38-
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
8+
import com.github.binarywang.wxpay.bean.request.*;
9+
import com.github.binarywang.wxpay.bean.result.*;
3910
import com.github.binarywang.wxpay.config.WxPayConfig;
4011
import com.github.binarywang.wxpay.exception.WxPayException;
4112

13+
import java.io.File;
14+
import java.util.Date;
15+
import java.util.Map;
16+
4217
/**
4318
* <pre>
4419
* 微信支付相关接口.
@@ -378,6 +353,42 @@ WxPayRefundQueryResult refundQuery(String transactionId, String outTradeNo, Stri
378353
*/
379354
WxPayBillResult downloadBill(WxPayDownloadBillRequest request) throws WxPayException;
380355

356+
/**
357+
* <pre>
358+
* 下载资金账单.
359+
* 商户可以通过该接口下载自2017年6月1日起 的历史资金流水账单。
360+
* 注意:
361+
* 1、资金账单中的数据反映的是商户微信账户资金变动情况;
362+
* 2、当日账单在次日上午9点开始生成,建议商户在上午10点以后获取;
363+
* 3、资金账单中涉及金额的字段单位为“元”。
364+
* 接口链接:https://api.mch.weixin.qq.com/pay/downloadfundflow
365+
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18">下载对账单</a>
366+
* </pre>
367+
*
368+
* @param billDate 资金账单日期 bill_date 下载对账单的日期,格式:20140603
369+
* @param accountType 资金账户类型 account_type Basic,基本账户,Operation,运营账户,Fees,手续费账户
370+
* @param tarType 压缩账单 tar_type 非必传参数,固定值:GZIP,返回格式为.gzip的压缩包账单。不传则默认为数据流形式。
371+
* @return WxPayFundFlowResult对象
372+
*/
373+
WxPayFundFlowResult downloadFundFlow(String billDate, String accountType, String tarType) throws WxPayException;
374+
375+
/**
376+
* <pre>
377+
* 下载资金账单.
378+
* 商户可以通过该接口下载自2017年6月1日起 的历史资金流水账单。
379+
* 注意:
380+
* 1、资金账单中的数据反映的是商户微信账户资金变动情况;
381+
* 2、当日账单在次日上午9点开始生成,建议商户在上午10点以后获取;
382+
* 3、资金账单中涉及金额的字段单位为“元”。
383+
* 接口链接:https://api.mch.weixin.qq.com/pay/downloadfundflow
384+
* 详情请见: <a href="https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=9_18">下载对账单</a>
385+
* </pre>
386+
*
387+
* @param request 下载资金流水请求
388+
* @return WxPayFundFlowResult对象
389+
*/
390+
WxPayFundFlowResult downloadFundFlow(WxPayDownloadFundFlowRequest request) throws WxPayException;
391+
381392
/**
382393
* <pre>
383394
* 提交刷卡支付.

0 commit comments

Comments
 (0)