Closed kbc2019 closed 2 years ago
一样遇见了,这里有这个问题的描述:https://blog.csdn.net/divaid/article/details/121154062 等版本更新。
// 获取证书管理器实例
certificatesManager = CertificatesManager.getInstance();
// 向证书管理器增加需要自动更新平台证书的商户信息
certificatesManager.putMerchant(merchantId, new WechatPay2Credentials(merchantId,
new PrivateKeySigner(merchantSerialNumber, merchantPrivateKey)),
apiV3Key.getBytes(StandardCharsets.UTF_8));
// 从证书管理器中获取verifier
verifier = certificatesManager.getVerifier(merchantId);
感谢!用cz.msebera.android:httpclient:4.5.8 替换apache的包就可以正常跑了。 可能是为了兼容除Android以外的其他Java开发而继续使用apache的包。
出现问题的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.(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)
代码片段如下: X509Certificate certificate = getCertificate(CERT_PATH + "wechatpay.pem"); List x509CertificateList = new ArrayList<>();
x509CertificateList.add(certificate);
系统默认找framework里的AllowAllHostnameVerifier , 但里面没有静态的INSTANCE;而第三方包org.apache.httpcomponents:httpclient里是有的。有人碰到同样的问题吗?请问如何解决。