2016-01-29 36 views
0

我正嘗試使用CURL連接到PayPal沙箱。我搜索都本網站和其他許多人試圖然而,找到正確的答案,沒有,我的意思是沒有,爲我工作,我仍然得到錯誤:CURL&PHP SSLv3錯誤並且無法讓TLS工作

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

我有以下的捲曲和PHP安裝(這是購買和共享主機,所以我不能升級任何東西)。

  • 捲曲Verison: 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; 
} 

} 

我所做的並不重要,我似乎無法克服這個錯誤。 :(任何指導都會有所幫助

+1

根據較早的問題貝寶說,你至少需要OpenSSL 1.1.2(或周圍的東西)。因此升級OpenSSL。 –

+0

而且你不應該設置'CURLOPT_SSLVERSION'。 cURL已經盡力使用最佳的SSL/TLS版本。 –

+0

正如我的文章所述,我無法升級OpenSSL,因爲這是共享付費託管。不過,我會嘗試聯繫我的主機,看看他們是否可以升級。 –

回答

2

Paypal現在只支持沙箱上的TLS 1.2(如果你想使用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/