PayPal IPN 没有响应,只有“连接关闭”


Paypal IPN does not respond, only "Connection Close"

>我正在开发一个IPN响应页面,但似乎有一些问题:

我正确接收PayPal发布数据,当我发送数据时得到确认,PayPal没有响应!

这是我的PHP代码:

$paypal_url = "www.sandbox.paypal.com";
$url = "https://" . $paypal_url . "/cgi-bin/webscr";
$req = 'cmd=_notify-validate';                // Add 'cmd=_notify-validate' to beginning of the acknowledgement
foreach ($_POST as $key => $value)
 {                                            // Loop through the notification NV pairs
   $value = urlencode(stripslashes($value));  // Encode these values
   $req  .= "&$key=$value";                   // Add the NV pairs to the acknowledgement
 }
$header = 
"POST /cgi-bin/webscr HTTP/1.0'r'n" .
"Host: www.sandbox.paypal.com'r'n" .
"Content-Type: application/x-www-form-urlencoded'r'n" .
"Content-Length: " . strlen($req) . "'r'n'r'n";
$fp = fsockopen('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
fputs($fp, $header . $req."'r'n'r'n");
$counter = 0;
while (!feof($fp))
    {
    $res = $res . fgets($fp, 1024); 
    $counter++;
    if($counter > 10)break;
    }
fclose($fp);
$tfile=fopen("text.txt","a+");
fwrite($tfile,$req . "'r'n");
fwrite($tfile,$res . "'r'n");
fclose($tfile);

在我的文本上.txt测试文件:

cmd=_notify-  validate&mc_gross=0.02&protection_eligibility=Eligible&address_status=unconfirmed&item_number1=&payer_id=M4DXNVMDFB8TY&tax=0.00&address_street=Gandhi+5%0D%0ABO&payment_date=01%3A05%3A50+Feb+19%2C+2016+PST&payment_status=Completed&charset=windows-1252&address_zip=40069&mc_shipping=0.00&mc_handling=0.00&first_name=test&mc_fee=0.02&address_country_code=IT&address_name=test+facilitator&notify_version=3.8&custom=56&payer_status=verified&business=andreafilippini90%40gmail.com&address_country=Italy&num_cart_items=1&mc_handling1=0.00&address_city=Zola+Predosa&verify_sign=AAllE9FA13ABhVwJYLWEzvptA49cACmRumx.SAuIktyCdTEuwgwrBDOF&payer_email=andreafilippini90-facilitator%40gmail.com&mc_shipping1=0.00&tax1=0.00&txn_id=2XL26853PJ6650947&payment_type=instant&payer_business_name=test+facilitator%27s+Test+Store&last_name=facilitator&address_state=&item_name1=lol&receiver_email=andreafilippini90%40gmail.com&payment_fee=&quantity1=1&receiver_id=36AE5DEXKKHSY&txn_type=cart&mc_gross_1=0.02&mc_currency=EUR&residence_country=IT&test_ipn=1&transaction_subject=&payment_gross=&ipn_track_id=436b4ca66c696
HTTP/1.1 200 OK
Date: Fri, 19 Feb 2016 09:05:59 GMT
Server: Apache
X-Frame-Options: SAMEORIGIN
Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=B2WFzbH6YM2Qyocy2U8eFnZLXwNKbE5H6baCy7qZWiquQveA1SY6UXyZGdfVwZhcRZgDRdhebwuzWFRSDj-JjwIGDp30AX8j3Ps5vhehIHBj7BlRSHWnIDfGq1pdF2_4Ffl6U9PpApn2XMxLLOHKuaJ3avnkqrE7ZZBw9dqp1RtWr6t60ZSDuSrek2zMtn08YXZ7thh1wF88X-1wqF1u3e6pDEZKeDuUOvSxut-QuRsEwIcNSJmDkmbdqAUYASBlgTNG1TolLzQgt3FbOVOI-zXfyu1uDk9BWlgAYpxL_XL00vjCVaX6iYkdC98OXbfhj2mnJvlWxFjbPiDjCKamWlD84U_EeV7GhjUbN5qns_F5OSMbXBm0erybHvlGMTCIJ53-j8FSw68imXw6WkM6Fzl_bq67Zle08eDb3mhLuzekpw_Xg-CpL5TMZne; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Mon, 16-Feb-2026 09:06:00 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navcmd=_notify-validate; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: navlns=0.0; expires=Sun, 18-Feb-2018 09:06:00 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.72.108.11.1455872759947539; path=/; expires=Sun, 11-Feb-46 09:05:59 GMT
Vary: Accept-Encoding,User-Agent
Connection: close

知道吗??

为什么它没有响应?

谢谢。

这是使用 IPN 验证

请求的步骤,因此您可以获取PayPal已 POST 到 IPN 脚本的数据并将其发送回PayPal进行验证; 顺便说一句,即使一切正确,此步骤偶尔也会失败,因此您必须准备处理它。

您可以使用如下所示的 cURL 调用来执行此操作:

//Sandbox URL
$sURL = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
//QueryString
$sQueryString = "cmd=_notify-validate";
foreach($_POST as $sPostKey => $sPostData) { $sQueryString .= "&{$sPostKey}={$sPostData}"; }
//Open the cURL session
$hCurl = curl_init();
//set cURL options
curl_setopt($hCurl, CURLOPT_URL, $sURL);                                    //URI
curl_setopt($hCurl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);           //HTTP version
curl_setopt($hCurl, CURLOPT_HEADER, 0);                                     //no HTTP headers
curl_setopt($hCurl, CURLOPT_POST, 1);                                       //REQUEST => POST
curl_setopt($hCurl, CURLOPT_POSTFIELDS, $sQueryString);                     //POST data
curl_setopt($hCurl, CURLOPT_RETURNTRANSFER, 1);                             //return raw data to script rather than browser
curl_setopt($hCurl, CURLOPT_TIMEOUT, 60);                                   //set timeout
curl_setopt($hCurl, CURLOPT_FORBID_REUSE, 1);
curl_setopt($hCurl, CURLOPT_HTTPHEADER, array('Connection: Close'));
//ensure that cURL is using the server IP address
curl_setopt($hCurl, CURLOPT_INTERFACE, $_SERVER['SERVER_ADDR']);
//The next two lines must be present for the kit to work with newer version of cURL
//You should remove them if you have any problems in earlier versions of cURL
curl_setopt($hCurl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($hCurl, CURLOPT_SSL_VERIFYHOST, 2);
//post and retrieve the response
$sRawResponse = trim(curl_exec($hCurl));
//throw Exceptions if cURL failed
if(curl_error($hCurl)) { throw new Exception(curl_error($hCurl), E_USER_ERROR); }
if(!$sRawResponse) { throw new Exception("No response from PayPal - cURL possibly failed"); }
//close the cURL handle
curl_close($hCurl);

最后,您应该将来自PayPal的响应存储在$sRawResponse变量中,如果一切都按计划进行,则应该简单地包含"已验证"一词。