file_get_contents("https://www.baidu.com/") //成功
file_get_contents("https://www.google.com/") //成功
file_get_contents("http://m.jxpeople.com.cn/") //失敗
錯誤信息:
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 的驗證手續(xù)
這個問題好像和ssl協(xié)議 v3有關(guān),大概理解是模擬版的瀏覽器該升級了,部分已經(jīng)趕不上時代了
php CertificateDownloader.php --mchid=145035XXX --serialno=6D5C0AF089F81CEE8A4768EB3B79XXX --privatekey=apiclient_key.pem --key=XXXXXXX
微信支付apiv3 本地獲取平臺證書也有這個問題
解決方法一:
更新openssl庫的ca證書(測試需要科學(xué)上網(wǎng)下載才行)
從curl庫官方下載這個ca證書最新版,http://curl.haxx.se/ca/cacert.pem
php.ini 配置
openssl.cafile = "/etc/ssl/certs/cacert.pem"http://你實際下載證書的路徑
重啟 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));
推薦方法一,不用修改代碼。!~