https://blog.csdn.net/divaid/article/details/121154062 用cz.msebera.android:httpclient:4.5.8 替换Apache的包就可以正常跑了。 Android 上应该有人碰到同样的问题,可能继续使用Apache的原因是为了兼容除 Andorid 以外的java开发。 建议增加个备注。
Android 10.0, WechatPayHttpClientBuilder 创建失败.出问题的log. java.lang.NoSuchFieldError: No static field INSTANCE of type Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; in class Lorg/apache/http/conn/ssl/AllowAllHostnameVerifier; or its superclasses (declaration of 'org.apache.http.conn.ssl.AllowAllHostnameVerifier' appears in /system/framework/framework.jar!classes3.dex) at org.apache.http.conn.ssl.SSLConnectionSocketFactory.<clinit>(SSLConnectionSocketFactory.java:151) at org.apache.http.impl.client.HttpClientBuilder.build(HttpClientBuilder.java:977) at com.wechat.pay.contrib.apache.httpclient.WechatPayHttpClientBuilder.build(WechatPayHttpClientBuilder.java:88) at com.example.myapplication.MainActivity.sendHttpRequest2(MainActivity.java:250) at com.example.myapplication.MainActivity.access$000(MainActivity.java:64) at com.example.myapplication.MainActivity$2.run(MainActivity.java:186) at java.lang.Thread.run(Thread.java:919) 使用wechatpay-apache-httpclient 0.4.8 SDK, 出错时的代码片段如下,创建WechatPayHttpClientBuilder的时候出现上述异常. X509Certificate certificate = getCertificate(CERT_PATH + "wechatpay.pem"); List<X509Certificate> x509CertificateList = new ArrayList<>(); x509CertificateList.add(certificate); PrivateKey privateKey = getPrivateKey(CERT_PATH + "apiclient_key.pem"); WechatPayHttpClientBuilder builder = WechatPayHttpClientBuilder.create() .withMerchant(mch_id, mchSerialNo, privateKey) .withWechatPay(x509CertificateList); CloseableHttpClient httpClient = null; try { httpClient = builder.build(); } catch (IllegalArgumentException e) { Log.e("ERROR", "IllegalArgumentException =" + e.getMessage()); }
2022-08-30