获取accesstoken时,提示证书解析有问题,导致无法正常获取token

错误:
https://qyapi.weixin.qq.com/cgi-bin/gettoken": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

原因,企业微信正在更新 SSL 证书,导致https 访问不可用。
https://developers.weixin.qq.com/community/develop/article/doc/0002025ca6c3a8c4d7d1afbaf6b013

java 项目解决办法

1. 将 jdk 更新到最新

(我使用的版本是)

java version "1.8.0_451"
Java(TM) SE Runtime Environment (build 1.8.0_451-b10)
Java HotSpot(TM) 64-Bit Server VM (build 25.451-b10, mixed mode

jdk8 官方下载页面
https://www.oracle.com/java/technologies/downloads/?er=221886#java8

2. 下载最新的根证书

https://cacerts.digicert.com/DigiCertGlobalRootG2.crt


(我使用的版本是)
https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/en-US/20230725/lrkl/Digicert%20G2%20ROOT.cer

3. 将下载的证书文件上传到服务器,并执行下方命令

keytool -importcert -keystore cacerts -storepass changeit -noprompt -file ./DigiCertGlobalRootG2.crt -alias digicertglobalrootg2

其中 ./DigiCertGlobalRootG2.crt 是证书文件地址。与你上传路径,上传的文件名保持一致即可

4. 重启 java 应用(必要步骤)

使用带 java 全路径的方式启动应用
/app/java/jdk1.8.0_451/bin/java -jar app.jar

你可能感兴趣的:(ssl,wechat,企业微信)