2013-02-12 47 views
3

幾天前,突然停止接收來自PayPal的IPN消息。 我已經寫在下面無法獲得PayPal IPN沙箱的回覆

$url_parsed=parse_url('https://www.sandbox.paypal.com/cgi-bin/webscr'); 
$post_string = '';  
foreach ($_POST as $field=>$value) { 
    $post_string .= $field.'='.urlencode(stripslashes($value)).'&'; 
} 
$post_string.="cmd=_notify-validate"; 
$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30); 

$myFile = "testpaypal.txt"; 

$fh = fopen($myFile, 'w') or die("can't open file"); 
$stringData = $post_string; 
fwrite($fh, $stringData); 
fwrite($fh, "------------"); 


if(!$fp){ 
    return false; 
} else { 

    fputs($fp, "POST $url_parsed[path] HTTP/1.0\r\n"); 
    fputs($fp, "Host: $url_parsed[host]\r\n"); 
    fputs($fp, "Content-type: application/x-www-form-urlencoded\r\n"); 
    fputs($fp, "Content-length: ".strlen($post_string)."\r\n"); 
    fputs($fp, "Connection: close\r\n\r\n"); 
    fputs($fp, $post_string . "\r\n\r\n");  
    while(!feof($fp)) 
    { 
     $ipn_response .= fgets($fp, 1024); 
    } 
    fclose($fp); 
    if (eregi("VERIFIED",$ipn_response)) { 
     fwrite($fh, "VERIFIED"); 
     return true; 
    } else { 
     fwrite($fh, "UNVERIFIED"); 
     return false; 
    } 
} 
    fclose($fh); 

該代碼的代碼返回到err_num 「」 以及當我後打印$ ipn_response 「FCLOSE($ FP);」行它打印 「HTTP/1.0 302找到的位置:https://www.sandbox.paypal.com服務器:BIGIP連接:關閉內容長度:0

,但無法在$ ipn_respnse得到 「已檢查」。

我已經嘗試了所有可能的方法,如更改解析網址與「ssl://sandbox.paypal.com」 和網絡上建議的所有其他解決方案。

自從最近三天以來,我一直陷在這個問題中。所以,請幫助我。

在此先感謝。

回答

0

我也一度爲這個問題而苦苦掙扎。它完全工作我瘋了!問題在於Hetzner(託管在哪裏)出於某種原因阻止了PayPal IP。在這種情況下,當您在PayPal賬戶中查看IPN賬戶時,您會發現IPN已經停止發送來自某個日期的通知。

0

嘗試將parse_url(https://www.paypal.com/cgi-bin/webscr)更改爲沙箱網址(https://sandbox.paypal.com/cgi-bin/webscr)。

接下來,使用phpinfo()函數檢查您的服務器是否已啓用openssl以接收來自HTTPS的響應。

+0

是的,我已經做了沙箱爲了在這裏提到它,以及在我的phpinfo捲曲啓用。 cURL支持\t已啓用 cURL信息\t libcurl/7.16。0 OpenSSL/0.9.8i zlib/1.2.3 – user1996999 2013-02-12 08:44:30

5

您應該通過SSL連接。嘗試改變這一點:

$fp = fsockopen($url_parsed['host'],"80",$err_num,$err_str,30); 

要這樣:

$fp = fsockopen("tls://" . $url_parsed['host'],"443",$err_num,$err_str,30); 
+0

我使用了一個我從Internet上下載的類。看起來像過去在80港口的連接是允許的。但是,現在這個腳本無法連接。該解決方案解決了這個問題。 – DreamWave 2014-06-02 08:04:07

+0

感謝它適合我.....真棒的傢伙 – 2015-08-19 14:58:53

0

在貝寶的消息:

爲了提高我們網站的性能,可擴展性和可用性,我們 將擴大www.paypal.com的IP地址數量。我們 公佈了一個公告於10月18日,2011年作爲這個 擴張計劃的一部分,我們將在 停止對HTTP 1.0協議支持2013年2月1,...

據稱更多信息可在http://www.paypal.com/pdthttp://www.paypal.com/ipn

發現我在你的代碼注意這裏:

fputs($fp, "POST $url_parsed[path] HTTP/1.0\r\n"); 

你還在使用HTTP 1.0

我不知道這是否能解決您的問題,但希望它能幫助您解決問題。