11package com .github .binarywang .wxpay .service .impl ;
22
3- import java .io .File ;
4- import java .io .IOException ;
5- import java .nio .charset .StandardCharsets ;
6- import java .nio .file .Files ;
7- import java .nio .file .Path ;
8- import java .nio .file .Paths ;
9- import java .util .Date ;
10- import java .util .HashMap ;
11- import java .util .LinkedList ;
12- import java .util .List ;
13- import java .util .Map ;
14- import java .util .zip .ZipException ;
15-
16- import com .github .binarywang .wxpay .bean .order .WxPayMwebOrderResult ;
17- import org .apache .commons .lang3 .StringUtils ;
18- import org .slf4j .Logger ;
19- import org .slf4j .LoggerFactory ;
20-
213import com .github .binarywang .utils .qrcode .QrcodeUtils ;
224import com .github .binarywang .wxpay .bean .WxPayApiData ;
23- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponInfoQueryRequest ;
24- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponInfoQueryResult ;
25- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponSendRequest ;
26- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponSendResult ;
27- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponStockQueryRequest ;
28- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponStockQueryResult ;
5+ import com .github .binarywang .wxpay .bean .coupon .*;
296import com .github .binarywang .wxpay .bean .notify .WxPayOrderNotifyResult ;
307import com .github .binarywang .wxpay .bean .notify .WxPayRefundNotifyResult ;
318import com .github .binarywang .wxpay .bean .notify .WxScanPayNotifyResult ;
329import com .github .binarywang .wxpay .bean .order .WxPayAppOrderResult ;
3310import com .github .binarywang .wxpay .bean .order .WxPayMpOrderResult ;
11+ import com .github .binarywang .wxpay .bean .order .WxPayMwebOrderResult ;
3412import com .github .binarywang .wxpay .bean .order .WxPayNativeOrderResult ;
35- import com .github .binarywang .wxpay .bean .request .WxPayAuthcode2OpenidRequest ;
36- import com .github .binarywang .wxpay .bean .request .WxPayDefaultRequest ;
37- import com .github .binarywang .wxpay .bean .request .WxPayDownloadBillRequest ;
38- import com .github .binarywang .wxpay .bean .request .WxPayMicropayRequest ;
39- import com .github .binarywang .wxpay .bean .request .WxPayOrderCloseRequest ;
40- import com .github .binarywang .wxpay .bean .request .WxPayOrderQueryRequest ;
41- import com .github .binarywang .wxpay .bean .request .WxPayOrderReverseRequest ;
42- import com .github .binarywang .wxpay .bean .request .WxPayQueryCommentRequest ;
43- import com .github .binarywang .wxpay .bean .request .WxPayRedpackQueryRequest ;
44- import com .github .binarywang .wxpay .bean .request .WxPayRefundQueryRequest ;
45- import com .github .binarywang .wxpay .bean .request .WxPayRefundRequest ;
46- import com .github .binarywang .wxpay .bean .request .WxPayReportRequest ;
47- import com .github .binarywang .wxpay .bean .request .WxPaySendRedpackRequest ;
48- import com .github .binarywang .wxpay .bean .request .WxPayShorturlRequest ;
49- import com .github .binarywang .wxpay .bean .request .WxPayUnifiedOrderRequest ;
50- import com .github .binarywang .wxpay .bean .result .BaseWxPayResult ;
51- import com .github .binarywang .wxpay .bean .result .WxPayAuthcode2OpenidResult ;
52- import com .github .binarywang .wxpay .bean .result .WxPayBillBaseResult ;
53- import com .github .binarywang .wxpay .bean .result .WxPayBillResult ;
54- import com .github .binarywang .wxpay .bean .result .WxPayCommonResult ;
55- import com .github .binarywang .wxpay .bean .result .WxPayMicropayResult ;
56- import com .github .binarywang .wxpay .bean .result .WxPayOrderCloseResult ;
57- import com .github .binarywang .wxpay .bean .result .WxPayOrderQueryResult ;
58- import com .github .binarywang .wxpay .bean .result .WxPayOrderReverseResult ;
59- import com .github .binarywang .wxpay .bean .result .WxPayRedpackQueryResult ;
60- import com .github .binarywang .wxpay .bean .result .WxPayRefundQueryResult ;
61- import com .github .binarywang .wxpay .bean .result .WxPayRefundResult ;
62- import com .github .binarywang .wxpay .bean .result .WxPaySandboxSignKeyResult ;
63- import com .github .binarywang .wxpay .bean .result .WxPaySendRedpackResult ;
64- import com .github .binarywang .wxpay .bean .result .WxPayShorturlResult ;
65- import com .github .binarywang .wxpay .bean .result .WxPayUnifiedOrderResult ;
13+ import com .github .binarywang .wxpay .bean .request .*;
14+ import com .github .binarywang .wxpay .bean .result .*;
6615import com .github .binarywang .wxpay .config .WxPayConfig ;
16+ import com .github .binarywang .wxpay .constant .WxPayConstants ;
6717import com .github .binarywang .wxpay .constant .WxPayConstants .BillType ;
6818import com .github .binarywang .wxpay .constant .WxPayConstants .SignType ;
6919import com .github .binarywang .wxpay .constant .WxPayConstants .TradeType ;
7424import com .google .common .base .Joiner ;
7525import com .google .common .collect .Maps ;
7626import jodd .io .ZipUtil ;
27+ import org .apache .commons .lang3 .StringUtils ;
28+ import org .slf4j .Logger ;
29+ import org .slf4j .LoggerFactory ;
30+
31+ import java .io .File ;
32+ import java .io .IOException ;
33+ import java .nio .charset .StandardCharsets ;
34+ import java .nio .file .Files ;
35+ import java .nio .file .Path ;
36+ import java .nio .file .Paths ;
37+ import java .util .*;
38+ import java .util .zip .ZipException ;
7739
7840import static com .github .binarywang .wxpay .constant .WxPayConstants .QUERY_COMMENT_DATE_FORMAT ;
7941import static com .github .binarywang .wxpay .constant .WxPayConstants .TarType ;
@@ -145,6 +107,11 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN
145107 request .setOutRefundNo (StringUtils .trimToNull (outRefundNo ));
146108 request .setRefundId (StringUtils .trimToNull (refundId ));
147109
110+ return this .refundQuery (request );
111+ }
112+
113+ @ Override
114+ public WxPayRefundQueryResult refundQuery (WxPayRefundQueryRequest request ) throws WxPayException {
148115 request .checkAndSign (this .getConfig ());
149116
150117 String url = this .getPayBaseUrl () + "/pay/refundquery" ;
@@ -155,12 +122,6 @@ public WxPayRefundQueryResult refundQuery(String transactionId, String outTradeN
155122 return result ;
156123 }
157124
158- @ Override
159- @ Deprecated
160- public WxPayOrderNotifyResult getOrderNotifyResult (String xmlData ) throws WxPayException {
161- return this .parseOrderNotifyResult (xmlData );
162- }
163-
164125 @ Override
165126 public WxPayOrderNotifyResult parseOrderNotifyResult (String xmlData ) throws WxPayException {
166127 try {
@@ -195,7 +156,7 @@ public WxPayRefundNotifyResult parseRefundNotifyResult(String xmlData) throws Wx
195156 public WxScanPayNotifyResult parseScanPayNotifyResult (String xmlData ) throws WxPayException {
196157 try {
197158 log .debug ("扫码支付回调通知请求参数:{}" , xmlData );
198- WxScanPayNotifyResult result = BaseWxPayResult .fromXML (xmlData ,WxScanPayNotifyResult .class );
159+ WxScanPayNotifyResult result = BaseWxPayResult .fromXML (xmlData , WxScanPayNotifyResult .class );
199160 log .debug ("扫码支付回调通知解析后的对象:{}" , result );
200161 result .checkResult (this , this .getConfig ().getSignType (), false );
201162 return result ;
@@ -243,6 +204,12 @@ public WxPayOrderQueryResult queryOrder(String transactionId, String outTradeNo)
243204 WxPayOrderQueryRequest request = new WxPayOrderQueryRequest ();
244205 request .setOutTradeNo (StringUtils .trimToNull (outTradeNo ));
245206 request .setTransactionId (StringUtils .trimToNull (transactionId ));
207+
208+ return this .queryOrder (request );
209+ }
210+
211+ @ Override
212+ public WxPayOrderQueryResult queryOrder (WxPayOrderQueryRequest request ) throws WxPayException {
246213 request .checkAndSign (this .getConfig ());
247214
248215 String url = this .getPayBaseUrl () + "/pay/orderquery" ;
@@ -265,6 +232,12 @@ public WxPayOrderCloseResult closeOrder(String outTradeNo) throws WxPayException
265232
266233 WxPayOrderCloseRequest request = new WxPayOrderCloseRequest ();
267234 request .setOutTradeNo (StringUtils .trimToNull (outTradeNo ));
235+
236+ return this .closeOrder (request );
237+ }
238+
239+ @ Override
240+ public WxPayOrderCloseResult closeOrder (WxPayOrderCloseRequest request ) throws WxPayException {
268241 request .checkAndSign (this .getConfig ());
269242
270243 String url = this .getPayBaseUrl () + "/pay/closeorder" ;
@@ -425,14 +398,15 @@ public String createScanPayQrcodeMode1(String productId) {
425398 params .put ("appid" , this .getConfig ().getAppId ());
426399 params .put ("mch_id" , this .getConfig ().getMchId ());
427400 params .put ("product_id" , productId );
428- params .put ("time_stamp" , String .valueOf (System .currentTimeMillis () / 1000 ));//这里需要秒,10位数字
401+ //这里需要秒,10位数字
402+ params .put ("time_stamp" , String .valueOf (System .currentTimeMillis () / 1000 ));
429403 params .put ("nonce_str" , String .valueOf (System .currentTimeMillis ()));
430404
431405 String sign = SignUtils .createSign (params , null , this .getConfig ().getMchKey (), false );
432406 params .put ("sign" , sign );
433407
434408 for (String key : params .keySet ()) {
435- codeUrl .append (key + "=" + params .get (key ) + "&" );
409+ codeUrl .append (key ). append ( "=" ). append ( params .get (key )). append ( "&" );
436410 }
437411
438412 String content = codeUrl .toString ().substring (0 , codeUrl .length () - 1 );
@@ -475,12 +449,17 @@ public WxPayBillResult downloadBill(String billDate, String billType, String tar
475449 request .setTarType (tarType );
476450 request .setDeviceInfo (deviceInfo );
477451
452+ return this .downloadBill (request );
453+ }
454+
455+ @ Override
456+ public WxPayBillResult downloadBill (WxPayDownloadBillRequest request ) throws WxPayException {
478457 request .checkAndSign (this .getConfig ());
479458
480459 String url = this .getPayBaseUrl () + "/pay/downloadbill" ;
481460
482461 String responseContent ;
483- if (TarType .GZIP .equals (tarType )) {
462+ if (TarType .GZIP .equals (request . getTarType () )) {
484463 responseContent = this .handleGzipBill (url , request .toXML ());
485464 } else {
486465 responseContent = this .post (url , request .toXML (), false );
@@ -489,7 +468,7 @@ public WxPayBillResult downloadBill(String billDate, String billType, String tar
489468 }
490469 }
491470
492- return this .handleBill (billType , responseContent );
471+ return this .handleBill (request . getBillType () , responseContent );
493472 }
494473
495474 private WxPayBillResult handleBill (String billType , String responseContent ) {
@@ -517,9 +496,10 @@ private String handleGzipBill(String url, String requestStr) throws WxPayExcepti
517496 this .log .error ("解压zip文件出错" , e );
518497 }
519498 }
520- } catch (IOException e ) {
521- e . printStackTrace ( );
499+ } catch (Exception e ) {
500+ this . log . error ( "解析对账单文件时出错" , e );
522501 }
502+
523503 return null ;
524504 }
525505
0 commit comments