【问题标题】:Paypal sandbox CURL execution - " SSL connect error "Paypal 沙箱 CURL 执行 - “SSL 连接错误”
【发布时间】:2016-08-05 16:45:24
【问题描述】:

我在 PHP 实时网站的 CURL 执行下方收到“SSL 连接错误”作为您的响应。

$ch     = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');

$header  = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";  
$header .="Connection: close\r\n\r\n";  
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Connection: Close'));
if( !($res = curl_exec($ch)) ) {
    curl_close($ch); // SSL connection Error
}

我尝试了实时和沙盒 URL。但是错误是一样的。

我尝试像某些论坛所说的那样更改 CURL 参数。

curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); 
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
curl_setopt($ch, CURLOPT_SSLVERSION, 6); 

但没有运气:(。

$req 是下面代码的结果。

$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc')) {
   $get_magic_quotes_exists = true;
} 
foreach ($myPost as $key => $value) {        
   if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1) { 
        $value = urlencode(stripslashes($value)); 
   } else {
        $value = urlencode($value);
   }
   $req .= "&$key=$value";
}

POST参数正确,我确定。

curl_getinfo 给出以下结果。

[url] => https://www.sandbox.paypal.com/cgi-bin/webscr
[content_type] => 
[http_code] => 0
[header_size] => 0
[request_size] => 1020
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0.220374
[namelookup_time] => 1.7E-5
[connect_time] => 0.080843
[pretransfer_time] => 0
[size_upload] => 855
[size_download] => 0
[speed_download] => 0
[speed_upload] => 3879
[download_content_length] => -1
[upload_content_length] => 0
[starttransfer_time] => 0
[redirect_time] => 0.220472
[certinfo] => Array
    (
    )

[redirect_url] => 

此外,curl_error($ch) 显示“SSL 连接错误”。 TSL 已经升级,SSL 版本没问题。

  curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);

正如本文档所述,我尝试添加上述行。

http://jmsliu.com/3511/paypal-ipn-ssl-connection-error-solution.html

但没有运气。

任何帮助将不胜感激。

【问题讨论】:

  • 您必须提供有关您的问题的更多详细信息。最好的方法是 HTTP 标头(请求和响应)输出。使用 CURL 请求设置 CURLOPT_HEADERCURLINFO_HEADER_OUT 选项,然后在此处发布响应内容和 curl_getinfo 调用的输出。
  • curl_getinfo($ch) 结果已添加。

标签: php ssl curl paypal


【解决方案1】:

网站在过去 5 年中运行良好...

在这种情况下,您可能只是在运行一个太旧的 OpenSSL 版本。 Paypal 现在需要 TLS 1.2。 TLS 1.2 是在 03/2012,即大约 4 年前与 OpenSSL 版本 1.0.1 一起添加的。
有关如何检查您使用的 OpenSSL 版本的信息,请参阅How to check if installed OpenSSL version is >= 0.9.8k

【讨论】:

【解决方案2】:

问题已解决!!!

我更新了 CURL 库,问题已解决。

检查,

$ php -r '$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://tlstest.paypal.com/"); var_dump(curl_exec($ch));'

成功时,会打印 PayPal_Connection_OK。 失败时,将打印 bool(false)。

【讨论】:

    猜你喜欢
    • 2017-09-10
    • 2016-04-27
    • 2010-12-19
    • 2017-07-16
    • 2016-04-28
    • 2018-01-02
    • 2017-11-27
    • 2016-06-02
    相关资源
    最近更新 更多