[英]CURL & PHP SSLv3 Error and Can't Get TLS to Work
我正在尝试使用CURL连接到PayPal沙箱。 我已经搜索了该网站以及许多其他网站,试图找到正确的答案,但是,没有一个,我的意思是没有一个对我有用,但仍然出现错误:
SetExpressCheckout失败:错误:14077410:SSL例程:SSL23_GET_SERVER_HELLO:sslv3警报握手失败(35)
我安装了以下CURL和PHP(已购买并共享了主机,因此我无法升级任何东西)。
我当前使用的代码:
class MyPayPal {
function PPHttpPost($methodName_, $nvpStr_, $PayPalApiUsername, $PayPalApiPassword, $PayPalApiSignature, $PayPalMode) {
// Set up your API credentials, PayPal end point, and API version.
$API_UserName = urlencode($PayPalApiUsername);
$API_Password = urlencode($PayPalApiPassword);
$API_Signature = urlencode($PayPalApiSignature);
$paypalmode = ($PayPalMode=='sandbox') ? '.sandbox' : '';
$API_Endpoint = "https://api-3t".$paypalmode.".paypal.com/nvp";
$version = urlencode('109.0');
// Set the curl parameters.
$ch = curl_init();
curl_setopt($ch, CURLOPT_SSLVERSION, 4);
curl_setopt($ch, CURLOPT_SSL_CIPHER_LIST, 'TLSv1');
curl_setopt($ch, CURLOPT_URL, $API_Endpoint);
curl_setopt($ch, CURLOPT_VERBOSE, 1);
// Turn off the server and peer verification (TrustManager Concept).
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
// Set the API operation, version, and API signature in the request.
$nvpreq = "METHOD=$methodName_&VERSION=$version&PWD=$API_Password&USER=$API_UserName&SIGNATURE=$API_Signature$nvpStr_";
// Set the request as a POST FIELD for curl.
curl_setopt($ch, CURLOPT_POSTFIELDS, $nvpreq);
// Get response from the server.
$httpResponse = curl_exec($ch);
if(!$httpResponse) {
exit("<span style='font-family: Verdana'><strong>$methodName_ failed: </strong>".curl_error($ch).'<strong> (</strong> '.curl_errno($ch).' <strong>)</strong></span>');
}
// Extract the response details.
$httpResponseAr = explode("&", $httpResponse);
$httpParsedResponseAr = array();
foreach ($httpResponseAr as $i => $value) {
$tmpAr = explode("=", $value);
if(sizeof($tmpAr) > 1) {
$httpParsedResponseAr[$tmpAr[0]] = $tmpAr[1];
}
}
if((0 == sizeof($httpParsedResponseAr)) || !array_key_exists('ACK', $httpParsedResponseAr)) {
exit("Invalid HTTP Response for POST request($nvpreq) to $API_Endpoint.");
}
return $httpParsedResponseAr;
}
}
不管做什么,我似乎都无法克服这个错误。 :(任何指导都会有所帮助。
Paypal现在在沙盒上仅支持TLS 1.2(6月份将同样适用于生产系统)。 如果要使用TLS 1.2,则需要至少升级到OpenSSL 1.0.1+,然后才能将CURLOPT_SSLVERSION设置为6
(TLS 1.2)。 如果希望在SSL请求期间自动使用TLS 1.2,则还需要升级到PHP 5.5.19+(这是理想的解决方案,但许多项目仍在较旧的PHP版本上)。
但是,您说过您正在共享主机上,无法自己升级软件...因此您很不走运。 我的建议是摆脱仍然停留在OpenSSL 0.9.8上的任何托管提供商。
参考: https : //devblog.paypal.com/upcoming-security-changes-notice/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.