file_get_contents("https://www.baidu.com/") //成功
file_get_contents("https://www.google.com/") //成功
file_get_contents("https://www.pbottle.com/") //失败
错误信息:
PHP Warning: file_get_contents(): Failed to enable crypto in ......
PHP Warning: file_get_contents......: failedream: operation failed in ......
PHP Warning: file_get_contents(): SSL operatwith code 1. OpenSSL Error messages:
error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verin ......
cURL error 60 unable to get local issuer certificate
无论是 file_get_contents 还是 curl 都是模拟浏览器访问,需要通过 https 的验证手续
这个问题好像和ssl协议 v3有关,大概理解是模拟版的浏览器该升级了,部分已经赶不上时代了
php CertificateDownloader.php --mchid=145035XXX --serialno=6D5C0AF089F81CEE8A4768EB3B79XXX --privatekey=apiclient_key.pem --key=XXXXXXX
微信支付apiv3 本地获取平台证书也有这个问题
解决方法一:
更新openssl库的ca证书(测试需要科学上网下载才行)
从curl库官方下载这个ca证书最新版,http://curl.haxx.se/ca/cacert.pem
php.ini 配置
openssl.cafile = "/etc/ssl/certs/cacert.pem"//你实际下载证书的路径
重启 php 或者 重新加载配置文件
解决方法二:
直接忽略https
$stream_opts = [
"ssl" => [
"verify_peer"=>false,
"verify_peer_name"=>false,
]
];
$response = file_get_contents("https://xxx.xxx.xxx",false, stream_context_create($stream_opts));
推荐方法一,不用修改代码。!~