您的应用程序正在使用hostnameverifier接口的不安全实现googleplay商店拒绝了这个应用

xqk2d5yq  于 2021-06-27  发布在  Java
关注(0)|答案(0)|浏览(336)

这是我的密码。我从google playstore收到此错误。“你的应用程序正在使用hostnameverifier接口的不安全实现。谷歌play商店拒绝应用程序“

public class APIClient {

private static OkHttpClient getHttpClient(Context context) {
    HttpLoggingInterceptor interceptor = new HttpLoggingInterceptor();
    interceptor.setLevel(HttpLoggingInterceptor.Level.BODY);
    CertificateFactory certificateFactory = CertificateFactory.getInstance("X.509");

    InputStream inputStream = context.getResources().openRawResource(R.raw.__6ixtaxi_com); //(.crt)
    Certificate certificate = certificateFactory.generateCertificate(inputStream);
    inputStream.close();

    // Create a KeyStore containing our trusted CAs
    String keyStoreType = KeyStore.getDefaultType();
    KeyStore keyStore = KeyStore.getInstance(keyStoreType);
    keyStore.load(null, null);
    keyStore.setCertificateEntry("ca", certificate);
    // Create a TrustManager that trusts the CAs in our KeyStore.
    String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
    TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(tmfAlgorithm);
    trustManagerFactory.init(keyStore);
    TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
    X509TrustManager x509TrustManager = (X509TrustManager) trustManagers[0];
    SSLContext sslContext = SSLContext.getInstance("SSL");
    sslContext.init(null, new TrustManager[]{x509TrustManager}, null);
    SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
    return new OkHttpClient().newBuilder()
            .connectTimeout(10, TimeUnit.SECONDS)
            .sslSocketFactory(sslSocketFactory,x509TrustManager )
            .addNetworkInterceptor(new AddHeaderInterceptor())
            .addInterceptor(new DecryptedPayloadInterceptor(new DecryptedPayloadInterceptor.DecryptionStrategy() {
                @Override
                public String decrypt(String stream) throws Exception {
                    if (!SharedHelper.apiState.equals("")) {
                        SharedHelper.apiState="";

                        return new String(Base64.decode(stream , Base64.DEFAULT), StandardCharsets.UTF_8);
                    }else {
                        return stream;
                    }
                }
                String getString(String str){
                    String replacement = "";
                    String toBeReplaced;
                    if (str.length()>60){
                        toBeReplaced = str.substring(5, 45);

                    }else {
                        toBeReplaced = str.substring(4, 44);
                    }
                    Log.e("sdsdsd",toBeReplaced);

                    Log.e("sdsdsd",str.replace(toBeReplaced, replacement));
                    return str.replace(toBeReplaced, replacement);
                }
            }))
            //.addNetworkInterceptor(new StethoInterceptor())
            .readTimeout(10, TimeUnit.SECONDS)
            .writeTimeout(10, TimeUnit.SECONDS)
            .retryOnConnectionFailure(true)
            .addInterceptor(interceptor)
            .build();
}

我用的是翻新图书馆。我怎样才能解决这个问题,请指导我。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题