Commit 4d4606c8 by pye52

删除冗余工具类及方法

parent b5200563
package com.bgycc.smartcanteen.api; package com.bgycc.smartcanteen.api;
import com.bgycc.smartcanteen.BuildConfig; import com.bgycc.smartcanteen.BuildConfig;
import com.bgycc.smartcanteen.utils.TrustAllCerts;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -35,12 +34,6 @@ public class SCRetrofit { ...@@ -35,12 +34,6 @@ public class SCRetrofit {
return builder; return builder;
} }
public static OkHttpClient.Builder createUnsafeOkHttpClientBuilder() {
return createOkHttpClientBuilder()
.hostnameVerifier(new TrustAllCerts.TrustAllHostnameVerifier())
.sslSocketFactory(TrustAllCerts.createSSLSocketFactory(), new TrustAllCerts());
}
private static Retrofit createRetrofit(OkHttpClient client) { private static Retrofit createRetrofit(OkHttpClient client) {
return new Retrofit.Builder() return new Retrofit.Builder()
.client(client) .client(client)
......
package com.bgycc.smartcanteen.utils;
import android.annotation.SuppressLint;
import java.security.SecureRandom;
import java.security.cert.X509Certificate;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocketFactory;
import javax.net.ssl.TrustManager;
import javax.net.ssl.X509TrustManager;
@SuppressLint("TrustAllX509TrustManager")
public class TrustAllCerts implements X509TrustManager {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) {}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) {}
@Override
public X509Certificate[] getAcceptedIssuers() {return new X509Certificate[0];}
public static SSLSocketFactory createSSLSocketFactory() {
SSLSocketFactory ssfFactory = null;
try {
SSLContext sc = SSLContext.getInstance("SSL");
sc.init(null, new TrustManager[] { new TrustAllCerts() }, new SecureRandom());
ssfFactory = sc.getSocketFactory();
} catch (Exception ignored) {
}
return ssfFactory;
}
public static class TrustAllHostnameVerifier implements HostnameVerifier {
@SuppressLint("BadHostnameVerifier")
@Override
public boolean verify(String hostname, SSLSession session) {
return true;
}
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment