Skip to content

Commit 1d35399

Browse files
committed
#801 根据微信支付最新通知调整对账单下载接口的部分字段
1 parent 0d7ea29 commit 1d35399

File tree

3 files changed

+109
-90
lines changed

3 files changed

+109
-90
lines changed
Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
*/
1616
@Data
1717
@NoArgsConstructor
18-
public class WxPayBillBaseResult implements Serializable {
18+
public class WxPayBillInfo implements Serializable {
1919
private static final long serialVersionUID = 2226245109137435453L;
2020

2121
@Override
@@ -36,7 +36,7 @@ public String toString() {
3636
*/
3737
private String mchId;
3838
/**
39-
* 子商户号.
39+
* 特约商户号.
4040
*/
4141
private String subMchId;
4242
/**
@@ -72,11 +72,11 @@ public String toString() {
7272
*/
7373
private String feeType;
7474
/**
75-
* 总金额.
75+
* 应结订单金额.
7676
*/
7777
private String totalFee;
7878
/**
79-
* 企业红包金额.
79+
* 代金券金额.
8080
*/
8181
private String couponFee;
8282
/**
@@ -92,7 +92,7 @@ public String toString() {
9292
*/
9393
private String settlementRefundFee;
9494
/**
95-
* 企业红包退款金额.
95+
* 充值券退款金额.
9696
*/
9797
private String couponRefundFee;
9898
/**
@@ -119,5 +119,17 @@ public String toString() {
119119
* 费率.
120120
*/
121121
private String poundageRate;
122+
/**
123+
* 订单金额.
124+
*/
125+
private String totalAmount;
126+
/**
127+
* 申请退款金额.
128+
*/
129+
private String appliedRefundAmount;
130+
/**
131+
* 费率备注.
132+
*/
133+
private String feeRemark;
122134

123135
}
Lines changed: 90 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
11
package com.github.binarywang.wxpay.bean.result;
22

33
import java.io.Serializable;
4+
import java.util.ArrayList;
45
import java.util.List;
56

67
import lombok.Data;
78
import lombok.NoArgsConstructor;
89
import me.chanjar.weixin.common.util.json.WxGsonBuilder;
910

1011
/**
11-
* The type Wx pay bill result.
12+
* 微信对账单结果类.
1213
*
13-
* @author BinaryWang
14+
* @author DDLeEHi
1415
*/
1516
@Data
1617
@NoArgsConstructor
1718
public class WxPayBillResult implements Serializable {
19+
private static final String TOTAL_DEAL_COUNT = "总交易单数";
1820
private static final long serialVersionUID = -7687458652694204070L;
1921

2022
@Override
@@ -23,28 +25,109 @@ public String toString() {
2325
}
2426

2527
/**
26-
* 对账返回对象.
28+
* 对账明细列表.
2729
*/
28-
private List<WxPayBillBaseResult> wxPayBillBaseResultLst;
30+
private List<WxPayBillInfo> billInfoList;
2931
/**
3032
* 总交易单数.
3133
*/
3234
private String totalRecord;
3335
/**
34-
* 总交易额.
36+
* 应结订单总金额.
3537
*/
3638
private String totalFee;
3739
/**
38-
* 总退款金额.
40+
* 退款总金额.
3941
*/
4042
private String totalRefundFee;
4143
/**
42-
* 总代金券或立减优惠退款金额.
44+
* 充值券退款总金额.
4345
*/
4446
private String totalCouponFee;
4547
/**
4648
* 手续费总金额.
4749
*/
4850
private String totalPoundageFee;
51+
/**
52+
* 订单总金额.
53+
*/
54+
private String totalAmount;
55+
/**
56+
* 申请退款总金额.
57+
*/
58+
private String totalAppliedRefundFee;
4959

60+
/**
61+
* 从原始对账单字符串里构造出WxPayBillResult对象.
62+
*/
63+
public static WxPayBillResult fromRawBillResultString(String responseContent) {
64+
String listStr = "";
65+
String objStr = "";
66+
if (responseContent.contains(TOTAL_DEAL_COUNT)) {
67+
listStr = responseContent.substring(0, responseContent.indexOf(TOTAL_DEAL_COUNT));
68+
objStr = responseContent.substring(responseContent.indexOf(TOTAL_DEAL_COUNT));
69+
}
70+
71+
List<WxPayBillInfo> results = new ArrayList<>();
72+
// 去空格
73+
String newStr = listStr.replaceAll(",", " ");
74+
// 数据分组
75+
String[] tempStr = newStr.split("`");
76+
// 分组标题
77+
String[] t = tempStr[0].split(" ");
78+
// 计算循环次数
79+
int j = tempStr.length / t.length;
80+
// 纪录数组下标
81+
int k = 1;
82+
for (int i = 0; i < j; i++) {
83+
WxPayBillInfo result = new WxPayBillInfo();
84+
result.setTradeTime(tempStr[k].trim());
85+
result.setAppId(tempStr[k + 1].trim());
86+
result.setMchId(tempStr[k + 2].trim());
87+
result.setSubMchId(tempStr[k + 3].trim());
88+
result.setDeviceInfo(tempStr[k + 4].trim());
89+
result.setTransactionId(tempStr[k + 5].trim());
90+
result.setOutTradeNo(tempStr[k + 6].trim());
91+
result.setOpenId(tempStr[k + 7].trim());
92+
result.setTradeType(tempStr[k + 8].trim());
93+
result.setTradeState(tempStr[k + 9].trim());
94+
result.setBankType(tempStr[k + 10].trim());
95+
result.setFeeType(tempStr[k + 11].trim());
96+
result.setTotalFee(tempStr[k + 12].trim());
97+
result.setCouponFee(tempStr[k + 13].trim());
98+
result.setRefundId(tempStr[k + 14].trim());
99+
result.setOutRefundNo(tempStr[k + 15].trim());
100+
result.setSettlementRefundFee(tempStr[k + 16].trim());
101+
result.setCouponRefundFee(tempStr[k + 17].trim());
102+
result.setRefundChannel(tempStr[k + 18].trim());
103+
result.setRefundState(tempStr[k + 19].trim());
104+
result.setBody(tempStr[k + 20].trim());
105+
result.setAttach(tempStr[k + 21].trim());
106+
result.setPoundage(tempStr[k + 22].trim());
107+
result.setPoundageRate(tempStr[k + 23].trim());
108+
result.setTotalAmount(tempStr[k + 24].trim());
109+
result.setAppliedRefundAmount(tempStr[k + 25].trim());
110+
result.setFeeRemark(tempStr[k + 26].trim());
111+
results.add(result);
112+
k += t.length;
113+
}
114+
115+
WxPayBillResult billResult = new WxPayBillResult();
116+
billResult.setBillInfoList(results);
117+
118+
/*
119+
* 总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额 `2,`0.02,`0.0,`0.0,`0
120+
* 参考以上格式进行取值
121+
*/
122+
String[] totalTempStr = objStr.replaceAll(",", " ").split("`");
123+
billResult.setTotalRecord(totalTempStr[1]);
124+
billResult.setTotalFee(totalTempStr[2]);
125+
billResult.setTotalRefundFee(totalTempStr[3]);
126+
billResult.setTotalCouponFee(totalTempStr[4]);
127+
billResult.setTotalPoundageFee(totalTempStr[5]);
128+
billResult.setTotalAmount(totalTempStr[6]);
129+
billResult.setTotalAppliedRefundFee(totalTempStr[7]);
130+
131+
return billResult;
132+
}
50133
}

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

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
5050
import com.github.binarywang.wxpay.bean.result.BaseWxPayResult;
5151
import com.github.binarywang.wxpay.bean.result.WxPayAuthcode2OpenidResult;
52-
import com.github.binarywang.wxpay.bean.result.WxPayBillBaseResult;
5352
import com.github.binarywang.wxpay.bean.result.WxPayBillResult;
5453
import com.github.binarywang.wxpay.bean.result.WxPayCommonResult;
5554
import com.github.binarywang.wxpay.bean.result.WxPayFundFlowBaseResult;
@@ -91,7 +90,6 @@
9190
public abstract class BaseWxPayServiceImpl implements WxPayService {
9291
private static final String PAY_BASE_URL = "https://api.mch.weixin.qq.com";
9392
private static final String TOTAL_FUND_COUNT = "资金流水总笔数";
94-
private static final String TOTAL_DEAL_COUNT = "总交易单数";
9593

9694
/**
9795
* The Log.
@@ -554,10 +552,10 @@ private WxPayBillResult handleBill(String billType, String responseContent) {
554552
return null;
555553
}
556554

557-
return this.handleAllBill(responseContent);
555+
return WxPayBillResult.fromRawBillResultString(responseContent);
558556
}
559557

560-
private String handleGzipBill(String url, String requestStr) throws WxPayException {
558+
private String handleGzipBill(String url, String requestStr) {
561559
try {
562560
byte[] responseBytes = this.postForBytes(url, requestStr, false);
563561
Path tempDirectory = Files.createTempDirectory("bill");
@@ -581,80 +579,6 @@ private String handleGzipBill(String url, String requestStr) throws WxPayExcepti
581579
return null;
582580
}
583581

584-
private WxPayBillResult handleAllBill(String responseContent) {
585-
WxPayBillResult wxPayBillResult = new WxPayBillResult();
586-
587-
String listStr = "";
588-
String objStr = "";
589-
if (responseContent.contains(TOTAL_DEAL_COUNT)) {
590-
listStr = responseContent.substring(0, responseContent.indexOf(TOTAL_DEAL_COUNT));
591-
objStr = responseContent.substring(responseContent.indexOf(TOTAL_DEAL_COUNT));
592-
}
593-
594-
/*
595-
* 交易时间:2017-04-06 01:00:02 公众账号ID: 商户号: 子商户号:0 设备号:WEB 微信订单号: 商户订单号:2017040519091071873216 用户标识: 交易类型:NATIVE
596-
* 交易状态:REFUND 付款银行:CFT 货币种类:CNY 总金额:0.00 企业红包金额:0.00 微信退款单号: 商户退款单号:20170406010000933 退款金额:0.01 企业红包退款金额:0.00
597-
* 退款类型:ORIGINAL 退款状态:SUCCESS 商品名称: 商户数据包: 手续费:0.00000 费率 :0.60%
598-
* 参考以上格式进行取值
599-
*/
600-
List<WxPayBillBaseResult> wxPayBillBaseResultLst = new LinkedList<>();
601-
// 去空格
602-
String newStr = listStr.replaceAll(",", " ");
603-
// 数据分组
604-
String[] tempStr = newStr.split("`");
605-
// 分组标题
606-
String[] t = tempStr[0].split(" ");
607-
// 计算循环次数
608-
int j = tempStr.length / t.length;
609-
// 纪录数组下标
610-
int k = 1;
611-
for (int i = 0; i < j; i++) {
612-
WxPayBillBaseResult wxPayBillBaseResult = new WxPayBillBaseResult();
613-
614-
wxPayBillBaseResult.setTradeTime(tempStr[k].trim());
615-
wxPayBillBaseResult.setAppId(tempStr[k + 1].trim());
616-
wxPayBillBaseResult.setMchId(tempStr[k + 2].trim());
617-
wxPayBillBaseResult.setSubMchId(tempStr[k + 3].trim());
618-
wxPayBillBaseResult.setDeviceInfo(tempStr[k + 4].trim());
619-
wxPayBillBaseResult.setTransactionId(tempStr[k + 5].trim());
620-
wxPayBillBaseResult.setOutTradeNo(tempStr[k + 6].trim());
621-
wxPayBillBaseResult.setOpenId(tempStr[k + 7].trim());
622-
wxPayBillBaseResult.setTradeType(tempStr[k + 8].trim());
623-
wxPayBillBaseResult.setTradeState(tempStr[k + 9].trim());
624-
wxPayBillBaseResult.setBankType(tempStr[k + 10].trim());
625-
wxPayBillBaseResult.setFeeType(tempStr[k + 11].trim());
626-
wxPayBillBaseResult.setTotalFee(tempStr[k + 12].trim());
627-
wxPayBillBaseResult.setCouponFee(tempStr[k + 13].trim());
628-
wxPayBillBaseResult.setRefundId(tempStr[k + 14].trim());
629-
wxPayBillBaseResult.setOutRefundNo(tempStr[k + 15].trim());
630-
wxPayBillBaseResult.setSettlementRefundFee(tempStr[k + 16].trim());
631-
wxPayBillBaseResult.setCouponRefundFee(tempStr[k + 17].trim());
632-
wxPayBillBaseResult.setRefundChannel(tempStr[k + 18].trim());
633-
wxPayBillBaseResult.setRefundState(tempStr[k + 19].trim());
634-
wxPayBillBaseResult.setBody(tempStr[k + 20].trim());
635-
wxPayBillBaseResult.setAttach(tempStr[k + 21].trim());
636-
wxPayBillBaseResult.setPoundage(tempStr[k + 22].trim());
637-
wxPayBillBaseResult.setPoundageRate(tempStr[k + 23].trim());
638-
wxPayBillBaseResultLst.add(wxPayBillBaseResult);
639-
k += t.length;
640-
}
641-
wxPayBillResult.setWxPayBillBaseResultLst(wxPayBillBaseResultLst);
642-
643-
/*
644-
* 总交易单数,总交易额,总退款金额,总代金券或立减优惠退款金额,手续费总金额 `2,`0.02,`0.0,`0.0,`0
645-
* 参考以上格式进行取值
646-
*/
647-
String totalStr = objStr.replaceAll(",", " ");
648-
String[] totalTempStr = totalStr.split("`");
649-
wxPayBillResult.setTotalRecord(totalTempStr[1]);
650-
wxPayBillResult.setTotalFee(totalTempStr[2]);
651-
wxPayBillResult.setTotalRefundFee(totalTempStr[3]);
652-
wxPayBillResult.setTotalCouponFee(totalTempStr[4]);
653-
wxPayBillResult.setTotalPoundageFee(totalTempStr[5]);
654-
655-
return wxPayBillResult;
656-
}
657-
658582
@Override
659583
public WxPayFundFlowResult downloadFundFlow(String billDate, String accountType, String tarType) throws WxPayException {
660584

0 commit comments

Comments
 (0)