【问题标题】:PayPal IPN on WordPress Site Stopped WorkingWordPress 网站上的 PayPal IPN 停止工作
【发布时间】:2014-02-13 01:32:03
【问题描述】:

直到昨天(今天早些时候),此 IPN 脚本是否正常工作且没有任何更改...这是核心 PayPal 代码的关键部分,我希望有人可以查看这些代码并让我知道是否有任何问题?我的 Wordpress 代码本身似乎可以正常工作(所以我排除了它)... Paypal 是否再次更改了他们的版本(1.0 到 1.1 到 ??)或 URL 或其他什么?

$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: IPN@tester.com';
 $mail_To = 'charlwoode@gmail.com';
 $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
}

【问题讨论】:

    标签: wordpress paypal paypal-ipn


    【解决方案1】:

    啊……我的标题已经过时了 - 这些有效:

    $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);
    

    【讨论】:

      【解决方案2】:

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

      我根据上述建议修改了我的一个 IPN 页面(我已经有了额外的标头,但没有 ssl: 或 443 端口或修整代码)。

      今天早上,虽然所有 IPN 页面都恢复了工作 - 不仅仅是修改后的页面 - 所以看起来 PayPal 又在玩了!

      我在 PayPal 网站上找不到指向此代码的链接,以查看是否需要进行任何其他更改。

      【讨论】:

        猜你喜欢
        • 2014-03-04
        • 2013-07-06
        • 2017-08-05
        • 2011-04-19
        • 1970-01-01
        • 2014-12-11
        • 1970-01-01
        • 2014-12-10
        • 2015-09-30
        相关资源
        最近更新 更多