php - CURL 和 PHP SSLv3 错误并且无法使 TLS 工作

标签 php ssl curl paypal

我正在尝试使用 CURL 连接到 PayPal 沙箱。我已经搜索了这个网站和许多其他试图找到正确答案的网站,但是,没有,我的意思是没有,对我有用,但我仍然得到错误:

SetExpressCheckout failed: error:14077410:SSL routines:SSL23_GET_SERVER_HELLO:sslv3 alert handshake failure ( 35 )

我安装了以下 CURL 和 PHP(它是购买和共享主机,所以我无法升级任何东西)。

  • Curl 版本:7.36.0
  • SSL 版本:OpenSSL/0.9.8b
  • PHP 版本:5.4.45

我目前使用的代码:

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/

关于php - CURL 和 PHP SSLv3 错误并且无法使 TLS 工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35094436/

相关文章:

php - Laravel中未显示的错误

postgresql - 使用 SSL 和 Elixir 后端连接到 Azure 上托管的 PostgreSQL

c++ - undefined reference 共享对象 Linux [c++]

php - postman API 不工作

php - 带有 SSL 证书的 cURL 失败 : error 58 unable to set private key file

jquery - 将curl命令转换为jQuery $.ajax()

php - 为什么使用 json 的 javascript 库选择 [ { } , { } ] 结构

php - 在 Laravel 5.7 中验证表单中的输入数组

php - 如何在PHP邮件功能中发送图像

c# web api - 使用 HTTPS 运行 web 应用程序 - 添加证书并启用 SSL 但连接被拒绝