1
0
mirror of synced 2025-12-19 06:37:59 +08:00

🎨 新增okhttp实现接口请求的单例模式代码

This commit is contained in:
WuLang
2023-02-18 22:52:02 +08:00
committed by GitHub
parent a47bc221f5
commit b83435281d
8 changed files with 733 additions and 23 deletions

View File

@@ -6,6 +6,7 @@ import me.chanjar.weixin.common.enums.WxType;
import me.chanjar.weixin.common.error.WxError;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.util.http.HttpType;
import me.chanjar.weixin.common.util.http.okhttp.DefaultOkHttpClientBuilder;
import me.chanjar.weixin.common.util.http.okhttp.OkHttpProxyInfo;
import me.chanjar.weixin.cp.config.WxCpConfigStorage;
import okhttp3.*;
@@ -82,12 +83,8 @@ public class WxCpServiceOkHttpImpl extends BaseWxCpServiceImpl<OkHttpClient, OkH
configStorage.getHttpProxyPort(),
configStorage.getHttpProxyUsername(),
configStorage.getHttpProxyPassword());
}
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
if (httpProxy != null) {
OkHttpClient.Builder clientBuilder = new OkHttpClient.Builder();
clientBuilder.proxy(getRequestHttpProxy().getProxy());
//设置授权
clientBuilder.authenticator(new Authenticator() {
@Override
@@ -98,8 +95,10 @@ public class WxCpServiceOkHttpImpl extends BaseWxCpServiceImpl<OkHttpClient, OkH
.build();
}
});
httpClient = clientBuilder.build();
} else {
httpClient = DefaultOkHttpClientBuilder.get().build();
}
httpClient = clientBuilder.build();
}
@Override