我的CURL有问题。
当我运行下面的代码时,会抛出异常:“CURL:SSL证书问题:无法获取本地颁发者证书”。 cacert.pem来自https://curl.haxx.se/ca/cacert.pem。
protected static function curlHttpPost($url, $data) {
$ch = curl_init($url);
$verifyFile = Yii::getAlias('@common') . '/curl/cacert.pem';
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
if(file_exists($verifyFile))
{
curl_setopt($ch, CURLOPT_CAINFO, $verifyFile);
}
$response = curl_exec($ch);
$curlError = curl_error($ch);
if($curlError)
{
throw new Exception($curlError);
}
curl_close($ch);
return $response;
}