2014-01-22 76 views
0

有这个IPN脚本工作正常,没有变化,直到昨天(今天早些时候)...这里是核心PayPal代码的关键位置,我希望有人可以检讨,让我知道如果有问题是什么?我的Wordpress代码似乎在它自己的工作正常(所以我排除它)...贝宝改变了他们的版本(1.0到1.1)?或URL或其他?PayPal IPN在WordPress网站停止工作

$req = 'cmd=_notify-validate'; 
foreach ($_POST as $key => $value) { 
$value = urlencode(stripslashes($value)); 
$value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix 
$req .= "&$key=$value"; 
} 
// post back to PayPal system to validate 
$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"; 
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); 
if (!$fp) { 
echo $errstr . ' (' . $errno . ')'; 
$mail_From = 'From: [email protected]'; 
$mail_To = '[email protected]'; 
$mail_Subject = 'HTTP ERROR'; 
$mail_Body = $errstr;//error string from fsockopen 
mail($mail_To, $mail_Subject, $mail_Body, $mail_From); 
$fh = fopen("logipn.txt", 'a');//open file and create if does not exist 
fwrite($fh, "\r\n/////////////////////////////////////////\r\n HTTP ERROR \r\n");//Just for spacing in log file 
fwrite($fh, $errstr);//write data 
fclose($fh);//close file 
} 
elseif 
{ 
    fputs ($fp, $header . $req); 
    while (!feof($fp)) { 
    $res = fgets ($fp, 1024); 
    $res=trim($res); 
    if (strcmp ($res, "VERIFIED") == 0) { 
     $item_name = $_POST['item_name']; 
     $item_number = $_POST['item_number']; 
     $aid= $_POST['custom']; 
     $payment_status = $_POST['payment_status']; 
     $payment_amount = $_POST['mc_gross'];   //full amount of payment. payment_gross in US 
     $payment_currency = $_POST['mc_currency']; 
     $txn_id = $_POST['txn_id'];     //unique transaction id 
     $receiver_email = $_POST['receiver_email']; 
     $payer_email = $_POST['payer_email']; 
//do stuff 
     } 
else { 
//do stuff 
} 

回答

0

唉唉......我的头已经过时了 - 这些工作:

$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; 
$header .= "Content-Type: application/x-www-form-urlencoded\r\n"; 
$header .= "Host: www.paypal.com\r\n"; // NEW 
$header .= "Connection: close\r\n"; // NEW 
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n"; 
// OLD VERSION THAT DIDN"T WORK $fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30); 
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30); // NEW CORRECT VERSION 

也不要忘记修剪!

while (!feof($fp)) { 
$res = fgets ($fp, 1024); 
$res=trim($res); 
0

我一直在过去几天有同样的问题,并试图在贝宝网站上进行研究。他们现在为IPN提供的示例代码看起来与上面完全不同(这是我正在使用的)。

我修改了我的一个IPN页面以上的建议(我已经有了额外的头,但没有ssl:或44​​3端口或修剪码)。

今天早上虽然所有的IPN页面都在重新工作 - 不仅仅是修改后的页面 - 所以看起来PayPal已经重新播放了!

我无法在PayPal网站上找到此编码的链接,以查看是否需要其他更改。