77import me .chanjar .weixin .common .util .http .okhttp .OkHttpProxyInfo ;
88import me .chanjar .weixin .cp .config .WxCpConfigStorage ;
99import okhttp3 .*;
10- import org .slf4j .Logger ;
11- import org .slf4j .LoggerFactory ;
1210
1311import java .io .IOException ;
1412
1513public class WxCpServiceOkHttpImpl extends WxCpServiceAbstractImpl <OkHttpClient , OkHttpProxyInfo > {
16- private final Logger logger = LoggerFactory .getLogger (this .getClass ());
17-
1814 protected OkHttpClient httpClient ;
1915 protected OkHttpProxyInfo httpProxy ;
2016
@@ -36,7 +32,7 @@ public HttpType getRequestType() {
3632
3733 @ Override
3834 public String getAccessToken (boolean forceRefresh ) throws WxErrorException {
39- logger .debug ("WxCpServiceOkHttpImpl is running" );
35+ this . log .debug ("WxCpServiceOkHttpImpl is running" );
4036 if (this .configStorage .isAccessTokenExpired () || forceRefresh ) {
4137 synchronized (this .globalAccessTokenRefreshLock ) {
4238 if (this .configStorage .isAccessTokenExpired ()) {
@@ -47,18 +43,14 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
4743 OkHttpClient client = getRequestHttpClient ();
4844 //请求的request
4945 Request request = new Request .Builder ().url (url ).get ().build ();
50- Response response = null ;
51- try {
52- response = client .newCall (request ).execute ();
53- } catch (IOException e ) {
54- e .printStackTrace ();
55- }
5646 String resultContent = null ;
5747 try {
48+ Response response = client .newCall (request ).execute ();
5849 resultContent = response .body ().string ();
5950 } catch (IOException e ) {
60- e . printStackTrace ( );
51+ this . log . error ( e . getMessage (), e );
6152 }
53+
6254 WxError error = WxError .fromJson (resultContent );
6355 if (error .getErrorCode () != 0 ) {
6456 throw new WxErrorException (error );
@@ -74,7 +66,7 @@ public String getAccessToken(boolean forceRefresh) throws WxErrorException {
7466
7567 @ Override
7668 public void initHttp () {
77- logger .debug ("WxCpServiceOkHttpImpl initHttp" );
69+ this . log .debug ("WxCpServiceOkHttpImpl initHttp" );
7870 OkHttpClient .Builder clientBuilder = new OkHttpClient .Builder ();
7971 //设置代理
8072 if (httpProxy != null ) {
0 commit comments