@@ -58,9 +58,36 @@ public String toString() {
5858 private String totalAppliedRefundFee ;
5959
6060 /**
61- * 从原始对账单字符串里构造出WxPayBillResult对象.
61+ * 根据账单类型,从原始对账单字符串里构造出WxPayBillResult对象
62+ *
63+ * @param responseContent 原始对账单字符串
64+ * @param billType 账单类型
65+ * @return WxPayBillResult对象
6266 */
63- public static WxPayBillResult fromRawBillResultString (String responseContent ) {
67+ public static WxPayBillResult fromRawBillResultString (String responseContent , String billType ) {
68+ switch (billType ) {
69+ case "ALL" :{
70+ return fromRawBillResultString (responseContent );
71+ }
72+ case "SUCCESS" :{
73+ return fromRawBillResultStringToSuccess (responseContent );
74+ }
75+ case "REFUND" :{
76+ return fromRawBillResultStringToRefund (responseContent );
77+ }
78+ case "RECHARGE_REFUND" :{
79+ return fromRawBillResultStringToRechargeRefund (responseContent );
80+ }
81+ default : {
82+ return null ;
83+ }
84+ }
85+ }
86+
87+ /**
88+ * 从原始对账单字符串里构造出WxPayBillResult对象,用于构建当日所有订单信息
89+ */
90+ private static WxPayBillResult fromRawBillResultString (String responseContent ) {
6491 String listStr = "" ;
6592 String objStr = "" ;
6693 if (responseContent .contains (TOTAL_DEAL_COUNT )) {
@@ -105,9 +132,6 @@ public static WxPayBillResult fromRawBillResultString(String responseContent) {
105132 result .setAttach (tempStr [k + 21 ].trim ());
106133 result .setPoundage (tempStr [k + 22 ].trim ());
107134 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 ());
111135 results .add (result );
112136 k += t .length ;
113137 }
@@ -125,9 +149,232 @@ public static WxPayBillResult fromRawBillResultString(String responseContent) {
125149 billResult .setTotalRefundFee (totalTempStr [3 ].trim ());
126150 billResult .setTotalCouponFee (totalTempStr [4 ].trim ());
127151 billResult .setTotalPoundageFee (totalTempStr [5 ].trim ());
128- billResult .setTotalAmount (totalTempStr [6 ].trim ());
129- billResult .setTotalAppliedRefundFee (totalTempStr [7 ].trim ());
152+ return billResult ;
153+ }
154+
155+ /**
156+ * 从原始对账单字符串里构造出WxPayBillResult对象,用于构建当日成功支付的订单
157+ */
158+ private static WxPayBillResult fromRawBillResultStringToSuccess (String responseContent ) {
159+ String listStr = "" ;
160+ String objStr = "" ;
161+ if (responseContent .contains (TOTAL_DEAL_COUNT )) {
162+ listStr = responseContent .substring (0 , responseContent .indexOf (TOTAL_DEAL_COUNT ));
163+ objStr = responseContent .substring (responseContent .indexOf (TOTAL_DEAL_COUNT ));
164+ }
165+
166+ List <WxPayBillInfo > results = new ArrayList <>();
167+ // 去空格
168+ String newStr = listStr .replaceAll ("," , " " );
169+ // 数据分组
170+ String [] tempStr = newStr .split ("`" );
171+ // 分组标题
172+ String [] t = tempStr [0 ].split (" " );
173+ // 计算循环次数
174+ int j = tempStr .length / t .length ;
175+ // 纪录数组下标
176+ int k = 1 ;
177+ // 交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,商品名称,商户数据包,手续费,费率
178+ for (int i = 0 ; i < j ; i ++) {
179+ WxPayBillInfo result = new WxPayBillInfo ();
180+ result .setTradeTime (tempStr [k ].trim ());
181+ result .setAppId (tempStr [k + 1 ].trim ());
182+ result .setMchId (tempStr [k + 2 ].trim ());
183+ result .setSubMchId (tempStr [k + 3 ].trim ());
184+ result .setDeviceInfo (tempStr [k + 4 ].trim ());
185+ result .setTransactionId (tempStr [k + 5 ].trim ());
186+ result .setOutTradeNo (tempStr [k + 6 ].trim ());
187+ result .setOpenId (tempStr [k + 7 ].trim ());
188+ result .setTradeType (tempStr [k + 8 ].trim ());
189+ result .setTradeState (tempStr [k + 9 ].trim ());
190+ result .setBankType (tempStr [k + 10 ].trim ());
191+ result .setFeeType (tempStr [k + 11 ].trim ());
192+ result .setTotalFee (tempStr [k + 12 ].trim ());
193+ result .setCouponFee (tempStr [k + 13 ].trim ());
194+ result .setBody (tempStr [k + 14 ].trim ());
195+ result .setAttach (tempStr [k + 15 ].trim ());
196+ result .setPoundage (tempStr [k + 16 ].trim ());
197+ result .setPoundageRate (tempStr [k + 17 ].trim ());
198+ results .add (result );
199+ k += t .length ;
200+ }
201+
202+ WxPayBillResult billResult = new WxPayBillResult ();
203+ billResult .setBillInfoList (results );
130204
205+ /*
206+ * 总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额 `2,`0.02,`0.0,`0.0,`0
207+ * 参考以上格式进行取值
208+ */
209+ String [] totalTempStr = objStr .replaceAll ("," , " " ).split ("`" );
210+ billResult .setTotalRecord (totalTempStr [1 ].trim ());
211+ billResult .setTotalFee (totalTempStr [2 ].trim ());
212+ billResult .setTotalRefundFee (totalTempStr [3 ].trim ());
213+ billResult .setTotalCouponFee (totalTempStr [4 ].trim ());
214+ billResult .setTotalPoundageFee (totalTempStr [5 ].trim ());
131215 return billResult ;
132216 }
217+
218+ /**
219+ * 从原始对账单字符串里构造出WxPayBillResult对象,用于构建当日退款的订单
220+ */
221+ private static WxPayBillResult fromRawBillResultStringToRefund (String responseContent ) {
222+ String listStr = "" ;
223+ String objStr = "" ;
224+ if (responseContent .contains (TOTAL_DEAL_COUNT )) {
225+ listStr = responseContent .substring (0 , responseContent .indexOf (TOTAL_DEAL_COUNT ));
226+ objStr = responseContent .substring (responseContent .indexOf (TOTAL_DEAL_COUNT ));
227+ }
228+
229+ List <WxPayBillInfo > results = new ArrayList <>();
230+ // 去空格
231+ String newStr = listStr .replaceAll ("," , " " );
232+ // 数据分组
233+ String [] tempStr = newStr .split ("`" );
234+ // 分组标题
235+ String [] t = tempStr [0 ].split (" " );
236+ // 计算循环次数
237+ int j = tempStr .length / t .length ;
238+ // 纪录数组下标
239+ int k = 1 ;
240+ // 交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,总金额,代金券或立减优惠金额,
241+ // 退款申请时间,退款成功时间,微信退款单号,商户退款单号,退款金额,代金券或立减优惠退款金额,退款类型,退款状态,商品名称,商户数据包,手续费,费率
242+ for (int i = 0 ; i < j ; i ++) {
243+ WxPayBillInfo result = new WxPayBillInfo ();
244+ result .setTradeTime (tempStr [k ].trim ());
245+ result .setAppId (tempStr [k + 1 ].trim ());
246+ result .setMchId (tempStr [k + 2 ].trim ());
247+ result .setSubMchId (tempStr [k + 3 ].trim ());
248+ result .setDeviceInfo (tempStr [k + 4 ].trim ());
249+ result .setTransactionId (tempStr [k + 5 ].trim ());
250+ result .setOutTradeNo (tempStr [k + 6 ].trim ());
251+ result .setOpenId (tempStr [k + 7 ].trim ());
252+ result .setTradeType (tempStr [k + 8 ].trim ());
253+ result .setTradeState (tempStr [k + 9 ].trim ());
254+ result .setBankType (tempStr [k + 10 ].trim ());
255+ result .setFeeType (tempStr [k + 11 ].trim ());
256+ result .setTotalFee (tempStr [k + 12 ].trim ());
257+ result .setCouponFee (tempStr [k + 13 ].trim ());
258+ result .setRefundTime (tempStr [k + 14 ].trim ());
259+ result .setRefundSuccessTime (tempStr [k + 15 ].trim ());
260+ result .setRefundId (tempStr [k + 16 ].trim ());
261+ result .setOutRefundNo (tempStr [k + 17 ].trim ());
262+ result .setSettlementRefundFee (tempStr [k + 18 ].trim ());
263+ result .setCouponRefundFee (tempStr [k + 19 ].trim ());
264+ result .setRefundChannel (tempStr [k + 20 ].trim ());
265+ result .setRefundState (tempStr [k + 21 ].trim ());
266+ result .setBody (tempStr [k + 22 ].trim ());
267+ result .setAttach (tempStr [k + 23 ].trim ());
268+ result .setPoundage (tempStr [k + 24 ].trim ());
269+ result .setPoundageRate (tempStr [k + 25 ].trim ());
270+ results .add (result );
271+ k += t .length ;
272+ }
273+
274+ WxPayBillResult billResult = new WxPayBillResult ();
275+ billResult .setBillInfoList (results );
276+
277+ /*
278+ * 总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额 `2,`0.02,`0.0,`0.0,`0
279+ * 参考以上格式进行取值
280+ */
281+ String [] totalTempStr = objStr .replaceAll ("," , " " ).split ("`" );
282+ billResult .setTotalRecord (totalTempStr [1 ].trim ());
283+ billResult .setTotalFee (totalTempStr [2 ].trim ());
284+ billResult .setTotalRefundFee (totalTempStr [3 ].trim ());
285+ billResult .setTotalCouponFee (totalTempStr [4 ].trim ());
286+ billResult .setTotalPoundageFee (totalTempStr [5 ].trim ());
287+ billResult .setTotalAmount (get (totalTempStr , 6 ));
288+ billResult .setTotalAppliedRefundFee (get (totalTempStr , 7 ));
289+
290+ return billResult ;
291+ }
292+
293+ /**
294+ * 从原始对账单字符串里构造出WxPayBillResult对象,用于构建当日充值退款订单
295+ */
296+ private static WxPayBillResult fromRawBillResultStringToRechargeRefund (String responseContent ) {
297+ String listStr = "" ;
298+ String objStr = "" ;
299+ if (responseContent .contains (TOTAL_DEAL_COUNT )) {
300+ listStr = responseContent .substring (0 , responseContent .indexOf (TOTAL_DEAL_COUNT ));
301+ objStr = responseContent .substring (responseContent .indexOf (TOTAL_DEAL_COUNT ));
302+ }
303+
304+ List <WxPayBillInfo > results = new ArrayList <>();
305+ // 去空格
306+ String newStr = listStr .replaceAll ("," , " " );
307+ // 数据分组
308+ String [] tempStr = newStr .split ("`" );
309+ // 分组标题
310+ String [] t = tempStr [0 ].split (" " );
311+ // 计算循环次数
312+ int j = tempStr .length / t .length ;
313+ // 纪录数组下标
314+ int k = 1 ;
315+ // 交易时间,公众账号ID,商户号,子商户号,设备号,微信订单号,商户订单号,用户标识,交易类型,交易状态,付款银行,货币种类,应结订单金额,代金券金额,
316+ // 退款申请时间,退款成功时间,微信退款单号,商户退款单号,退款金额,充值券退款金额,退款类型,退款状态,商品名称,商户数据包,返还手续费,费率,订单金额,申请退款金额
317+ for (int i = 0 ; i < j ; i ++) {
318+ WxPayBillInfo result = new WxPayBillInfo ();
319+ result .setTradeTime (tempStr [k ].trim ());
320+ result .setAppId (tempStr [k + 1 ].trim ());
321+ result .setMchId (tempStr [k + 2 ].trim ());
322+ result .setSubMchId (tempStr [k + 3 ].trim ());
323+ result .setDeviceInfo (tempStr [k + 4 ].trim ());
324+ result .setTransactionId (tempStr [k + 5 ].trim ());
325+ result .setOutTradeNo (tempStr [k + 6 ].trim ());
326+ result .setOpenId (tempStr [k + 7 ].trim ());
327+ result .setTradeType (tempStr [k + 8 ].trim ());
328+ result .setTradeState (tempStr [k + 9 ].trim ());
329+ result .setBankType (tempStr [k + 10 ].trim ());
330+ result .setFeeType (tempStr [k + 11 ].trim ());
331+ result .setTotalFee (tempStr [k + 12 ].trim ());
332+ result .setCouponFee (tempStr [k + 13 ].trim ());
333+ result .setRefundTime (tempStr [k + 14 ].trim ());
334+ result .setRefundSuccessTime (tempStr [k + 15 ].trim ());
335+ result .setRefundId (tempStr [k + 16 ].trim ());
336+ result .setOutRefundNo (tempStr [k + 17 ].trim ());
337+ result .setSettlementRefundFee (tempStr [k + 18 ].trim ());
338+ result .setCouponRefundFee (tempStr [k + 19 ].trim ());
339+ result .setRefundChannel (tempStr [k + 20 ].trim ());
340+ result .setRefundState (tempStr [k + 21 ].trim ());
341+ result .setBody (tempStr [k + 22 ].trim ());
342+ result .setAttach (tempStr [k + 23 ].trim ());
343+ result .setPoundage (tempStr [k + 24 ].trim ());
344+ result .setPoundageRate (tempStr [k + 25 ].trim ());
345+ result .setTotalAmount (get (tempStr , k + 26 , t .length ));
346+ result .setAppliedRefundAmount (get (tempStr , k + 27 , t .length ));
347+ results .add (result );
348+ k += t .length ;
349+ }
350+
351+ WxPayBillResult billResult = new WxPayBillResult ();
352+ billResult .setBillInfoList (results );
353+
354+ /*
355+ * 总交易单数,应结订单总金额,退款总金额,充值券退款总金额,手续费总金额,订单总金额,申请退款总金额 `2,`0.02,`0.0,`0.0,`0
356+ * 参考以上格式进行取值
357+ */
358+ String [] totalTempStr = objStr .replaceAll ("," , " " ).split ("`" );
359+ billResult .setTotalRecord (totalTempStr [1 ].trim ());
360+ billResult .setTotalFee (totalTempStr [2 ].trim ());
361+ billResult .setTotalRefundFee (totalTempStr [3 ].trim ());
362+ billResult .setTotalCouponFee (totalTempStr [4 ].trim ());
363+ billResult .setTotalPoundageFee (totalTempStr [5 ].trim ());
364+ billResult .setTotalAmount (get (totalTempStr , 6 ));
365+ billResult .setTotalAppliedRefundFee (get (totalTempStr , 7 ));
366+
367+ return billResult ;
368+ }
369+
370+ private static String get (String [] array , int idx ) {
371+ return get (array , idx , array .length );
372+ }
373+
374+ private static String get (String [] array , int idx , int length ) {
375+ if (length > idx ) {
376+ return array [idx ].trim ();
377+ }
378+ return null ;
379+ }
133380}
0 commit comments