Skip to content

Commit 79f8517

Browse files
committed
🐛 #1275 微信支付优化对账单下载解析接口,兼容普通结算对账单
1 parent fa1f085 commit 79f8517

File tree

2 files changed

+61
-33
lines changed

2 files changed

+61
-33
lines changed

weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/result/WxPayBillResult.java

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,16 +66,16 @@ public String toString() {
6666
*/
6767
public static WxPayBillResult fromRawBillResultString(String responseContent, String billType) {
6868
switch (billType) {
69-
case "ALL":{
69+
case "ALL": {
7070
return fromRawBillResultString(responseContent);
7171
}
72-
case "SUCCESS":{
72+
case "SUCCESS": {
7373
return fromRawBillResultStringToSuccess(responseContent);
7474
}
75-
case "REFUND" :{
75+
case "REFUND": {
7676
return fromRawBillResultStringToRefund(responseContent);
7777
}
78-
case "RECHARGE_REFUND" :{
78+
case "RECHARGE_REFUND": {
7979
return fromRawBillResultStringToRechargeRefund(responseContent);
8080
}
8181
default: {
@@ -106,7 +106,9 @@ private static WxPayBillResult fromRawBillResultString(String responseContent) {
106106
int j = tempStr.length / t.length;
107107
// 纪录数组下标
108108
int k = 1;
109-
// 交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注
109+
// 交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,
110+
// 应结订单金额,代金券金额,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,
111+
// 订单金额,申请退款金额,费率备注 (开通免充值券后的结算对账单专有的三个字段)
110112
for (int i = 0; i < j; i++) {
111113
WxPayBillInfo result = new WxPayBillInfo();
112114
result.setTradeTime(tempStr[k].trim());
@@ -133,9 +135,14 @@ private static WxPayBillResult fromRawBillResultString(String responseContent) {
133135
result.setAttach(tempStr[k + 21].trim());
134136
result.setPoundage(tempStr[k + 22].trim());
135137
result.setPoundageRate(tempStr[k + 23].trim());
136-
result.setTotalAmount(tempStr[k + 24].trim());
137-
result.setAppliedRefundAmount(tempStr[k + 25].trim());
138-
result.setFeeRemark(tempStr[k + 26].trim());
138+
139+
if (t.length > 24) {
140+
// 开通免充值券后的结算对账单
141+
result.setTotalAmount(tempStr[k + 24].trim());
142+
result.setAppliedRefundAmount(tempStr[k + 25].trim());
143+
result.setFeeRemark(tempStr[k + 26].trim());
144+
}
145+
139146
results.add(result);
140147
k += t.length;
141148
}
@@ -181,7 +188,8 @@ private static WxPayBillResult fromRawBillResultStringToSuccess(String responseC
181188
int j = tempStr.length / t.length;
182189
// 纪录数组下标
183190
int k = 1;
184-
// 交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,商品名称,商户数据包,手续费,费率,订单金额,费率备注
191+
// 交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,
192+
// 应结订单金额,代金券金额,商品名称,商户数据包,手续费,费率,订单金额,费率备注
185193
for (int i = 0; i < j; i++) {
186194
WxPayBillInfo result = new WxPayBillInfo();
187195
result.setTradeTime(tempStr[k].trim());
Lines changed: 44 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,65 @@
11
package com.github.binarywang.wxpay.bean.result;
22

33
import com.github.binarywang.wxpay.constant.WxPayConstants;
4-
import org.testng.Assert;
54
import org.testng.annotations.Test;
65

6+
import static org.testng.Assert.assertEquals;
7+
import static org.testng.Assert.assertNull;
8+
79
/**
810
* @author m8cool
911
*/
1012
public class WxPayBillResultTest {
11-
12-
public static final String PAY_BILL_RESULT_ALL_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注\n" +
13+
private static final String PAY_BILL_RESULT_ALL_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注\n" +
1314
"`2019-07-25 08:35:41,`WWWW,`XXXXXXXX,`0,`,`XXXXXXXXXXXXX,`XXXXXXXXXX,`XXXXXXXXXXX,`JSAPI,`SUCCESS,`PSBC_DEBIT,`CNY,`6.00,`0.00,`0,`0,`0.00,`0.00,`,`,`XXXXXX,`XXXXXXX,`0.04000,`0.60%,`6.00,`0.00,`\n" +
1415
"总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额\n" +
1516
"`48,`5.76,`1.42,`0.00,`0.01000,`5.76,`1.42\n";
16-
public static final String PAY_BILL_RESULT_SUCCESS_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,商品名称,商户数据包,手续费,费率,订单金额,费率备注\n" +
17+
private static final String PAY_BILL_RESULT_ALL_CONTENT_1 = "交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,微信退款单号,商户退款单号,退款金额,代金券或立减优惠退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率\n" +
18+
"`2014-11-10 16:33:45,`wx2421b1c4370ec43b,`10000100,`0,`1000,`1001690740201411100005734289,`1415640626,`085e9858e3ba5186aafcbaed1,`MICROPAY,`SUCCESS,`OTHERS,`CNY,`0.01,`0.0,`0,`0,`0,`0,`,`,`被扫支付测试,`订单额外描述,`0,`0.60%\n" +
19+
"`2014-11-10 16:46:14,`wx2421b1c4370ec43b,`10000100,`0,`1000,`1002780740201411100005729794,`1415635270,`085e9858e90ca40c0b5aee463,`MICROPAY,`SUCCESS,`OTHERS,`CNY,`0.01,`0.0,`0,`0,`0,`0,`,`,`被扫支付测试,`订单额外描述,`0,`0.60%\n" +
20+
"总交易单数,总交易额,总退款金额,总代金券或立减优惠退款金额,手续费总金额\n" +
21+
"`2,`0.02,`0.0,`0.0,`0";
22+
23+
private static final String PAY_BILL_RESULT_SUCCESS_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,商品名称,商户数据包,手续费,费率,订单金额,费率备注\n" +
1724
"`2019-07-23 18:46:41,`XXXX,`XXX,`XXX,`,`XXX,`XXX,`XXX,`JSAPI,`SUCCESS,`CFT,`CNY,`0.01,`0.00,`XXX,`XXXX,`0.00000,`0.60%,`0.01,`\n" +
1825
"总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额\n" +
1926
"`31,`3.05,`0.00,`0.00,`0.02000,`3.05,`0.00";
20-
public static final String PAY_BILL_RESULT_REFUND_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,退款申请时间,退款成功时间,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注\n" +
27+
private static final String PAY_BILL_RESULT_REFUND_CONTENT = "交易时间,公众账号ID,商户号,特约商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,退款申请时间,退款成功时间,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率,订单金额,申请退款金额,费率备注\n" +
2128
"`2019-07-23 20:53:36,`xxx,`xxx,`xxx,`,`xxx,`xxxx,`xxxxx,`JSAPI,`REFUND,`CFT,`CNY,`0.00,`0.00,`2019-07-23 20:53:36,`2019-07-23 20:53:40,`xxxx,`xxx,`0.01,`0.00,`ORIGINAL,`SUCCESS,`xxxx,`xxxx,`0.00000,`0.60%,`0.00,`0.01,`\n" +
2229
"总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额\n" +
2330
"`4,`0.00,`2.02,`0.00,`-0.02000,`0.00,`2.02";
2431

32+
2533
/**
2634
* 测试微信返回类型为ALL时,解析结果是否正确
2735
*/
2836
@Test
2937
public void testFromRawBillResultStringAll() {
3038
WxPayBillResult result = WxPayBillResult.fromRawBillResultString(PAY_BILL_RESULT_ALL_CONTENT, WxPayConstants.BillType.ALL);
3139

32-
Assert.assertEquals(result.getTotalRecord(), "48");
33-
Assert.assertEquals(result.getTotalFee(), "5.76");
34-
Assert.assertEquals(result.getTotalRefundFee(), "1.42");
35-
Assert.assertEquals(result.getTotalCouponFee(), "0.00");
36-
Assert.assertEquals(result.getTotalPoundageFee(), "0.01000");
37-
Assert.assertEquals(result.getTotalAmount(), "5.76");
38-
Assert.assertEquals(result.getTotalAppliedRefundFee(), "1.42");
39-
Assert.assertEquals(result.getBillInfoList().get(0).getTotalAmount(), "6.00");
40-
Assert.assertEquals(result.getBillInfoList().get(0).getAppliedRefundAmount(), "0.00");
41-
Assert.assertEquals(result.getBillInfoList().get(0).getFeeRemark(), "");
40+
assertEquals(result.getTotalRecord(), "48");
41+
assertEquals(result.getTotalFee(), "5.76");
42+
assertEquals(result.getTotalRefundFee(), "1.42");
43+
assertEquals(result.getTotalCouponFee(), "0.00");
44+
assertEquals(result.getTotalPoundageFee(), "0.01000");
45+
assertEquals(result.getTotalAmount(), "5.76");
46+
assertEquals(result.getTotalAppliedRefundFee(), "1.42");
47+
assertEquals(result.getBillInfoList().get(0).getTotalAmount(), "6.00");
48+
assertEquals(result.getBillInfoList().get(0).getAppliedRefundAmount(), "0.00");
49+
assertEquals(result.getBillInfoList().get(0).getFeeRemark(), "");
50+
51+
result = WxPayBillResult.fromRawBillResultString(PAY_BILL_RESULT_ALL_CONTENT_1, WxPayConstants.BillType.ALL);
4252

53+
assertEquals(result.getTotalRecord(), "2");
54+
assertEquals(result.getTotalFee(), "0.02");
55+
assertEquals(result.getTotalRefundFee(), "0.0");
56+
assertEquals(result.getTotalCouponFee(), "0.0");
57+
assertEquals(result.getTotalPoundageFee(), "0");
58+
assertNull(result.getTotalAmount());
59+
assertNull(result.getTotalAppliedRefundFee());
60+
assertNull(result.getBillInfoList().get(0).getTotalAmount());
61+
assertNull(result.getBillInfoList().get(0).getAppliedRefundAmount());
62+
assertNull(result.getBillInfoList().get(0).getFeeRemark());
4363

4464
}
4565

@@ -50,15 +70,15 @@ public void testFromRawBillResultStringAll() {
5070
public void testFromRawBillResultStringSuccess() {
5171
WxPayBillResult result = WxPayBillResult.fromRawBillResultString(PAY_BILL_RESULT_SUCCESS_CONTENT, WxPayConstants.BillType.SUCCESS);
5272

53-
Assert.assertEquals(result.getTotalRecord(), "31");
54-
Assert.assertEquals(result.getTotalFee(), "3.05");
55-
Assert.assertEquals(result.getTotalRefundFee(), "0.00");
56-
Assert.assertEquals(result.getTotalCouponFee(), "0.00");
57-
Assert.assertEquals(result.getTotalPoundageFee(), "0.02000");
58-
Assert.assertEquals(result.getTotalAmount(), "3.05");
59-
Assert.assertEquals(result.getTotalAppliedRefundFee(), "0.00");
60-
Assert.assertEquals(result.getBillInfoList().get(0).getTotalAmount(), "0.01");
61-
Assert.assertEquals(result.getBillInfoList().get(0).getFeeRemark(), "");
73+
assertEquals(result.getTotalRecord(), "31");
74+
assertEquals(result.getTotalFee(), "3.05");
75+
assertEquals(result.getTotalRefundFee(), "0.00");
76+
assertEquals(result.getTotalCouponFee(), "0.00");
77+
assertEquals(result.getTotalPoundageFee(), "0.02000");
78+
assertEquals(result.getTotalAmount(), "3.05");
79+
assertEquals(result.getTotalAppliedRefundFee(), "0.00");
80+
assertEquals(result.getBillInfoList().get(0).getTotalAmount(), "0.01");
81+
assertEquals(result.getBillInfoList().get(0).getFeeRemark(), "");
6282

6383
}
6484
}

0 commit comments

Comments
 (0)