11package com .github .binarywang .wxpay .service .impl ;
22
3- import java .io .File ;
4- import java .nio .charset .StandardCharsets ;
5- import java .nio .file .Files ;
6- import java .nio .file .Path ;
7- import java .nio .file .Paths ;
8- import java .util .Date ;
9- import java .util .HashMap ;
10- import java .util .LinkedList ;
11- import java .util .List ;
12- import java .util .Map ;
13- import java .util .zip .ZipException ;
14-
15- import org .apache .commons .lang3 .StringUtils ;
16- import org .slf4j .Logger ;
17- import org .slf4j .LoggerFactory ;
18-
193import com .github .binarywang .utils .qrcode .QrcodeUtils ;
204import com .github .binarywang .wxpay .bean .WxPayApiData ;
21- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponInfoQueryRequest ;
22- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponInfoQueryResult ;
23- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponSendRequest ;
24- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponSendResult ;
25- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponStockQueryRequest ;
26- import com .github .binarywang .wxpay .bean .coupon .WxPayCouponStockQueryResult ;
5+ import com .github .binarywang .wxpay .bean .coupon .*;
276import com .github .binarywang .wxpay .bean .notify .WxPayOrderNotifyResult ;
287import com .github .binarywang .wxpay .bean .notify .WxPayRefundNotifyResult ;
298import com .github .binarywang .wxpay .bean .notify .WxScanPayNotifyResult ;
309import com .github .binarywang .wxpay .bean .order .WxPayAppOrderResult ;
3110import com .github .binarywang .wxpay .bean .order .WxPayMpOrderResult ;
3211import com .github .binarywang .wxpay .bean .order .WxPayMwebOrderResult ;
3312import com .github .binarywang .wxpay .bean .order .WxPayNativeOrderResult ;
34- import com .github .binarywang .wxpay .bean .request .WxPayAuthcode2OpenidRequest ;
35- import com .github .binarywang .wxpay .bean .request .WxPayDefaultRequest ;
36- import com .github .binarywang .wxpay .bean .request .WxPayDownloadBillRequest ;
37- import com .github .binarywang .wxpay .bean .request .WxPayMicropayRequest ;
38- import com .github .binarywang .wxpay .bean .request .WxPayOrderCloseRequest ;
39- import com .github .binarywang .wxpay .bean .request .WxPayOrderQueryRequest ;
40- import com .github .binarywang .wxpay .bean .request .WxPayOrderReverseRequest ;
41- import com .github .binarywang .wxpay .bean .request .WxPayQueryCommentRequest ;
42- import com .github .binarywang .wxpay .bean .request .WxPayRedpackQueryRequest ;
43- import com .github .binarywang .wxpay .bean .request .WxPayRefundQueryRequest ;
44- import com .github .binarywang .wxpay .bean .request .WxPayRefundRequest ;
45- import com .github .binarywang .wxpay .bean .request .WxPayReportRequest ;
46- import com .github .binarywang .wxpay .bean .request .WxPaySendRedpackRequest ;
47- import com .github .binarywang .wxpay .bean .request .WxPayShorturlRequest ;
48- import com .github .binarywang .wxpay .bean .request .WxPayUnifiedOrderRequest ;
49- import com .github .binarywang .wxpay .bean .result .BaseWxPayResult ;
50- import com .github .binarywang .wxpay .bean .result .WxPayAuthcode2OpenidResult ;
51- import com .github .binarywang .wxpay .bean .result .WxPayBillBaseResult ;
52- import com .github .binarywang .wxpay .bean .result .WxPayBillResult ;
53- import com .github .binarywang .wxpay .bean .result .WxPayCommonResult ;
54- import com .github .binarywang .wxpay .bean .result .WxPayMicropayResult ;
55- import com .github .binarywang .wxpay .bean .result .WxPayOrderCloseResult ;
56- import com .github .binarywang .wxpay .bean .result .WxPayOrderQueryResult ;
57- import com .github .binarywang .wxpay .bean .result .WxPayOrderReverseResult ;
58- import com .github .binarywang .wxpay .bean .result .WxPayRedpackQueryResult ;
59- import com .github .binarywang .wxpay .bean .result .WxPayRefundQueryResult ;
60- import com .github .binarywang .wxpay .bean .result .WxPayRefundResult ;
61- import com .github .binarywang .wxpay .bean .result .WxPaySandboxSignKeyResult ;
62- import com .github .binarywang .wxpay .bean .result .WxPaySendRedpackResult ;
63- import com .github .binarywang .wxpay .bean .result .WxPayShorturlResult ;
64- import com .github .binarywang .wxpay .bean .result .WxPayUnifiedOrderResult ;
13+ import com .github .binarywang .wxpay .bean .request .*;
14+ import com .github .binarywang .wxpay .bean .result .*;
6515import com .github .binarywang .wxpay .config .WxPayConfig ;
6616import com .github .binarywang .wxpay .constant .WxPayConstants .BillType ;
6717import com .github .binarywang .wxpay .constant .WxPayConstants .SignType ;
7323import com .google .common .base .Joiner ;
7424import com .google .common .collect .Maps ;
7525import jodd .io .ZipUtil ;
26+ import org .apache .commons .lang3 .StringUtils ;
27+ import org .slf4j .Logger ;
28+ import org .slf4j .LoggerFactory ;
29+
30+ import java .io .File ;
31+ import java .nio .charset .StandardCharsets ;
32+ import java .nio .file .Files ;
33+ import java .nio .file .Path ;
34+ import java .nio .file .Paths ;
35+ import java .util .*;
36+ import java .util .zip .ZipException ;
7637
7738import static com .github .binarywang .wxpay .constant .WxPayConstants .QUERY_COMMENT_DATE_FORMAT ;
7839import static com .github .binarywang .wxpay .constant .WxPayConstants .TarType ;
@@ -290,23 +251,19 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
290251 WxPayUnifiedOrderResult unifiedOrderResult = this .unifiedOrder (request );
291252 String prepayId = unifiedOrderResult .getPrepayId ();
292253 if (StringUtils .isBlank (prepayId )) {
293- throw new RuntimeException (String .format ("无法获取prepay id,错误代码: '%s',信息:%s。" ,
254+ throw new WxPayException (String .format ("无法获取prepay id,错误代码: '%s',信息:%s。" ,
294255 unifiedOrderResult .getErrCode (), unifiedOrderResult .getErrCodeDes ()));
295256 }
296257
297258 String timestamp = String .valueOf (System .currentTimeMillis () / 1000 );
298259 String nonceStr = String .valueOf (System .currentTimeMillis ());
299260 switch (request .getTradeType ()) {
300261 case TradeType .MWEB : {
301- return (T ) WxPayMwebOrderResult .builder ()
302- .mwebUrl (unifiedOrderResult .getMwebUrl ())
303- .build ();
262+ return (T ) new WxPayMwebOrderResult (unifiedOrderResult .getMwebUrl ());
304263 }
305264
306265 case TradeType .NATIVE : {
307- return (T ) WxPayNativeOrderResult .builder ()
308- .codeUrl (unifiedOrderResult .getCodeURL ())
309- .build ();
266+ return (T ) new WxPayNativeOrderResult (unifiedOrderResult .getCodeURL ());
310267 }
311268
312269 case TradeType .APP : {
@@ -318,7 +275,13 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
318275
319276 Map <String , String > configMap = new HashMap <>(8 );
320277 // 此map用于参与调起sdk支付的二次签名,格式全小写,timestamp只能是10位,格式固定,切勿修改
321- String partnerId = getConfig ().getMchId ();
278+ String partnerId ;
279+ if (StringUtils .isEmpty (request .getMchId ())) {
280+ partnerId = this .getConfig ().getMchId ();
281+ } else {
282+ partnerId = request .getMchId ();
283+ }
284+
322285 configMap .put ("prepayid" , prepayId );
323286 configMap .put ("partnerid" , partnerId );
324287 String packageValue = "Sign=WXPay" ;
@@ -327,7 +290,7 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
327290 configMap .put ("noncestr" , nonceStr );
328291 configMap .put ("appid" , appId );
329292
330- return ( T ) WxPayAppOrderResult .builder ()
293+ final WxPayAppOrderResult result = WxPayAppOrderResult .builder ()
331294 .sign (SignUtils .createSign (configMap , null , this .getConfig ().getMchKey (), false ))
332295 .prepayId (prepayId )
333296 .partnerId (partnerId )
@@ -336,13 +299,14 @@ public <T> T createOrder(WxPayUnifiedOrderRequest request) throws WxPayException
336299 .timeStamp (timestamp )
337300 .nonceStr (nonceStr )
338301 .build ();
302+ return (T ) result ;
339303 }
340304
341305 case TradeType .JSAPI : {
342306 String signType = SignType .MD5 ;
343307 String appid = unifiedOrderResult .getAppid ();
344- if (StringUtils .isNotEmpty (this . getConfig () .getSubAppId ())) {
345- appid = this . getConfig () .getSubAppId ();
308+ if (StringUtils .isNotEmpty (unifiedOrderResult .getSubAppId ())) {
309+ appid = unifiedOrderResult .getSubAppId ();
346310 }
347311
348312 WxPayMpOrderResult payResult = WxPayMpOrderResult .builder ()
0 commit comments