【问题标题】:PayPal IPN not return VERIFIED to 0PayPal IPN 未将 VERIFIED 返回为 0
【发布时间】:2012-09-14 18:06:51
【问题描述】:

我已经要求我的 paypal api 发送 $res 的电子邮件以查看响应是什么。 while (!feof($fp)) {}

这是我从 $res 到我的电子邮件收到的内容

HTTP/1.0 400 Bad Request
Server: BigIP
Connection: close
Content-Length: 19
Invalid Host header

这是我的贝宝代码。

$req = 'cmd=_notify-validate';
$req .= payment_safe_check ($_POST);

$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

$mode = strtolower($paymod_data['PAYMENT_MODE']);

    mail("to email", "subject",serialize($_POST) );


if ($mode == 'test')
{
    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
}
else
{
    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);
}

if (!$fp)
{
    // HTTP ERROR
    die ("Error");
}
else 
{
    // NO HTTP ERROR
    fputs ( $fp, $header . $req );
    while (!feof($fp))
    {
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0)
        {
            processing ( $_POST );
        }
        else if (strcmp ($res, "INVALID") == 0)
        {

        }
    }
    fclose ($fp);
}

这不起作用 if (strcmp ($res, "VERIFIED") == 0){} 但如果我将其更改为 if (strcmp ($res, "VERIFIED") == -1){} 它会正常工作。

更新

我已将代码更改为

$mode = $paymod_data['PAYMENT_MODE'];
$paypal_url = ($mode == 'test') ? 'www.sandbox.paypal.com' : 'www.paypal.com';

$raw_post_data = file_get_contents('php://input');
$raw_post_array = explode('&', $raw_post_data);
$myPost = array();
foreach ($raw_post_array as $keyval)
{
  $keyval = explode ('=', $keyval);
  if (count($keyval) == 2)
     $myPost[$keyval[0]] = urldecode($keyval[1]);
}
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';
$req .= payment_safe_check ($_REQUEST);

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://'.$paypal_url.'/cgi-bin/webscr');
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: '.$paypal_url));

$res = curl_exec($ch);
curl_close($ch);


if (strcmp ($res, "VERIFIED") == 0) {
    processing ( $_POST );
}
else if (strcmp ($res, "INVALID") == 0) {
    // log for manual investigation
}

有人可以确认他们是否对此代码有任何问题。

【问题讨论】:

    标签: php paypal paypal-ipn


    【解决方案1】:

    VERIFIED 和 INVALID 是您从 PAYPAL 收到响应后需要验证的两个响应。
    您可以参考代码示例
    https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

    【讨论】:

      【解决方案2】:

      strcmp 检查一个字符串是否比另一个“大”。 Is 区分大小写,可以被空格和换行符忽略。

      我建议你改用

      if ( stristr($res,"VERIFIED") === 0 )   {}
      else if ( stristr($res,"INVALID") === 0 )   {}
      

      【讨论】:

      • 更改我的代码后,我得到了这个。 HTTP/1.0 400 错误请求服务器:BigIP 连接:关闭内容长度:19 无效主机标头
      • 你知道我可以使用什么新的 paypal IPN 代码吗?这是最新的代码吗x.com/instant-payment-notification-4
      【解决方案3】:

      找不到url中的问题... 您必须将网址更改为如下所示...

      $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');   // (for Sandbox IPNs)
      $ch = curl_init(' https://www.paypal.com/cgi-bin/webscr');   // (for live IPNs)
      

      【讨论】:

        猜你喜欢
        • 2013-09-06
        • 2011-06-22
        • 2013-08-15
        • 2014-05-22
        • 2015-08-16
        • 1970-01-01
        • 2011-10-26
        • 2015-10-14
        相关资源
        最近更新 更多