In Yii2, file_get_contents(“https://api.weixin.qq.com”); Error: yii\base\ErrorException: file_get_contents(): SSL operation failed with code 1. OpenSSL error messages:
1. In Yii2, file_get_contents(“https://api.weixin.qq.com”); Error: yii\base\ErrorException: file_get_contents(): SSL operation failed with code 1. OpenSSL error messages:. as shown in Figure 1
2025-03-11 17:56:30 [101.204.100.38][1826027541133144][-][error][yii\base\ErrorException:2] yii\base\ErrorException: file_get_contents(): SSL operation failed with code 1. OpenSSL Error messages:
error:0A000126:SSL routines::unexpected eof while reading in /home/wwwroot/object/src/api/controllers/UserController.php:189
Stack trace:
#0 [internal function]: yii\base\ErrorHandler->handleError()
#1 /home/wwwroot/object/src/api/controllers/UserController.php(189): file_get_contents()
2. PHP needs the correct CA certificate to verify the SSL certificate of the remote server. If the CA certificate is missing or expired, it will cause SSL authentication to fail.
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# cp -f cacert.pem /etc/ssl/certs/cacert.pem
[root@iZ2zeaj7tnbv8d3gsoy1w5Z ~]# cd /etc/ssl/certs/
[root@iZ2zeaj7tnbv8d3gsoy1w5Z certs]# ls -l
total 228
lrwxrwxrwx 1 root root 49 Aug 19 2024 ca-bundle.crt -> /etc/pki/ca-trust/extracted/pem/tls-ca-bundle.pem
lrwxrwxrwx 1 root root 55 Aug 19 2024 ca-bundle.trust.crt -> /etc/pki/ca-trust/extracted/openssl/ca-bundle.trust.crt
-rw-r--r-- 1 root root 233263 Mar 11 17:53 cacert.pem
[root@iZ2zeaj7tnbv8d3gsoy1w5Z certs]#
3. Configure openssl.cafile in php.ini. After restarting php-fpm, it still doesn’t work. as shown in Figure 2
openssl.cafile = /etc/ssl/certs/cacert.pem
4. In the end, I had to re-implement based on curl, and finally solve it. Reference:Request an HTTPS URL in CURL, and respond to troubleshooting and analysis of FALSE

