@@ -474,18 +474,9 @@ private String post(String url, String xmlParam, boolean needTransferEncoding) {
474
474
}
475
475
476
476
HttpRequest request = HttpRequest .post (url ).body (requestString );
477
- HttpResponse response = request .send ();
478
- String responseString = response .bodyText ();
479
-
480
- if (needTransferEncoding ) {
481
- try {
482
- responseString = new String (response .bodyText ().getBytes (CharEncoding .ISO_8859_1 ), CharEncoding .UTF_8 );
483
- } catch (UnsupportedEncodingException e ) {
484
- e .printStackTrace ();
485
- }
486
- }
477
+ String responseString = this .getResponseString (request .send ());
487
478
488
- this .log .debug ("\n [URL] : {}\n [PARAMS]: {}\n [RESPONSE]: {}" , url , xmlParam , responseString );
479
+ this .log .info ("\n 【请求地址】 : {}\n 【请求参数】: {}\n 【响应数据】: {}" , url , xmlParam , responseString );
489
480
return responseString ;
490
481
}
491
482
@@ -499,16 +490,35 @@ private String postWithKey(String url, String requestStr) throws WxPayException
499
490
sslContext = this .getConfig ().initSSLContext ();
500
491
}
501
492
502
- HttpRequest request = HttpRequest .post (url ).withConnectionProvider (new SSLSocketHttpConnectionProvider (sslContext ));
503
- request .bodyText (requestStr );
504
- HttpResponse response = request .send ();
505
- String result = response .bodyText ();
506
- this .log .debug ("\n [URL]: {}\n [PARAMS]: {}\n [RESPONSE]: {}" , url , requestStr , result );
507
- return result ;
493
+ HttpRequest request = HttpRequest
494
+ .post (url )
495
+ .withConnectionProvider (new SSLSocketHttpConnectionProvider (sslContext ))
496
+ .bodyText (requestStr );
497
+
498
+ String responseString = this .getResponseString (request .send ());
499
+
500
+ this .log .debug ("\n 【请求地址】: {}\n 【请求参数】:{}\n 【响应数据】:{}" , url , requestStr , responseString );
501
+ return responseString ;
508
502
} catch (Exception e ) {
509
- this .log .error ("\n [URL]: {}\n [PARAMS]: {}\n [EXCEPTION]: {}" , url , requestStr , e .getMessage ());
503
+ this .log .error ("\n 【请求地址】: {}\n 【请求参数】: {}\n 【异常信息】: {}" , url , requestStr , e .getMessage ());
510
504
throw new WxPayException (e .getMessage ());
511
505
}
512
506
}
513
507
508
+ private String getResponseString (HttpResponse response ) {
509
+ this .log .debug ("【微信服务器响应头信息】:\n {}" , response .toString (false ));
510
+
511
+ String responseString = response .bodyText ();
512
+
513
+ if (StringUtils .isBlank (response .charset ())) {
514
+ try {
515
+ responseString = new String (response .bodyText ().getBytes (CharEncoding .ISO_8859_1 ), CharEncoding .UTF_8 );
516
+ } catch (UnsupportedEncodingException e ) {
517
+ e .printStackTrace ();
518
+ }
519
+ }
520
+ return responseString ;
521
+ }
522
+
523
+
514
524
}
0 commit comments