使用官方UniMPsdk集成到原生app中,wgt包内的https请求报错证书问题 请问有解决方案吗,安卓原生请求是忽略了ssl验证可行,但wgt包的uniapp应该是没有适配到。尝试了各种方案,包括原生适配:
1.
android:networkSecurityConfig="@xml/network_security_config"
android:usesCleartextTraffic="true"
network_security_config中忽略配置或者使用证书。
2.获取信任指定证书的OkHttpClient,但是发现OkHttpClient没有地方设置,因为SDK的源码是arr包无法修改。
3.也设置过源码中的:DCWXHttpAdapter类插入这个【OkHttpClient】,也还是如此。
这个问题已经困扰两天了,找不到解决方案。你们的官方群也没有任何人回复一下消息,请问下这个还有其他解决方案吗?
日志信息如下:
javax.net.ssl.SSLHandshakeException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
2025-12-26 11:14:26.476 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:229)
2025-12-26 11:14:26.476 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.RealConnection.connectTls(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:22)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.RealConnection.establishProtocol(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:15)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.RealConnection.connect(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:41)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.StreamAllocation.findConnection(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:92)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.StreamAllocation.findHealthyConnection(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:1)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.StreamAllocation.newStream(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:8)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.connection.ConnectInterceptor.intercept(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:7)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:23)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:1)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.cache.CacheInterceptor.intercept(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:41)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:23)
2025-12-26 11:14:26.477 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:1)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.BridgeInterceptor.intercept(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:65)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:23)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:21)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:23)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.internal.http.RealInterceptorChain.proceed(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:1)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.RealCall.getResponseWithInterceptorChain(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:16)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at dc.squareup.okhttp3.RealCall.execute(r8-map-id-168a8911c198db382adea05f30dd44b2772442721951d00a5256bbbecfe3838d:10)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at io.dcloud.feature.weex.adapter.DCWXHttpAdapter$1.run(r8-map-id-b4716a25f9920722ba6f2d7f7c6f40e43a654927e8ebe1c489894a7bc6a88ab4:19)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)
2025-12-26 11:14:26.478 28563-28792 System.err com.example.unimpdemo W at java.lang.Thread.run(Thread.java:764)
2025-12-26 11:14:26.479 28563-28792 System.err com.example.unimpdemo W Caused by: java.security.cert.CertificateException: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
2025-12-26 11:14:26.479 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.TrustManagerImpl.checkTrustedRecursive(TrustManagerImpl.java:646)
2025-12-26 11:14:26.479 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:495)
2025-12-26 11:14:26.479 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.TrustManagerImpl.checkTrusted(TrustManagerImpl.java:418)
2025-12-26 11:14:26.479 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.TrustManagerImpl.getTrustedChainForServer(TrustManagerImpl.java:339)
2025-12-26 11:14:26.479 28563-28792 System.err com.example.unimpdemo W at android.security.net.config.NetworkSecurityTrustManager.checkServerTrusted(NetworkSecurityTrustManager.java:94)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W at android.security.net.config.RootTrustManager.checkServerTrusted(RootTrustManager.java:88)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.Platform.checkServerTrusted(Platform.java:208)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.ConscryptFileDescriptorSocket.verifyCertificateChain(ConscryptFileDescriptorSocket.java:404)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.NativeCrypto.SSL_do_handshake(Native Method)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.NativeSsl.doHandshake(NativeSsl.java:375)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W at com.android.org.conscrypt.ConscryptFileDescriptorSocket.startHandshake(ConscryptFileDescriptorSocket.java:224)
2025-12-26 11:14:26.480 28563-28792 System.err com.example.unimpdemo W ... 23 more
2025-12-26 11:14:26.481 28563-28792 System.err com.example.unimpdemo W Caused by: java.security.cert.CertPathValidatorException: Trust anchor for certification path not found.
2025-12-26 11:14:26.481 28563-28792 System.err com.example.unimpdemo W ... 34 more
3 个回复
Ask小助手
根据您描述的问题和日志信息,这是典型的SSL证书验证失败问题。结合知识库内容,提供以下解决方案:
在wgt包内设置sslVerify参数
在uni.request()调用中添加
sslVerify: false参数(虽然不推荐,但可临时解决问题):注意:知识库明确说明小众CA签发的证书在安卓设备会失败,且"离线打包不支持sslVerify配置",但wgt热更新包应支持此参数。
检查wgt manifest配置
在wgt包的manifest.json中添加网络安全配置:
UniMPsdk特殊处理
由于您使用UniMPsdk集成,需确认:
setSSLVerifyEnabled(false)类似API根本解决方案
建议更换为Let's Encrypt等系统内置信任的证书机构,避免使用CFCA等小众CA证书。知识库明确指出:"可以更换其他常见机构签发的证书(如:Let's Encrypt)"。
5***@qq.com (作者) - 没啥说的
你说的这些方法都试过,还是没有任何效果。还是报一样的错误。
爱豆豆 - 办法总比困难多
在manifest.json中配置ssl 的 untrustedca为accept试试呢
参考文档:https://uniapp.dcloud.net.cn/collocation/manifest-app.html#full-manifest
要回复问题请先登录或注册
公告
更多>相关问题