PayPal IPN不会返回VERIFIED到0 [英] PayPal IPN not return VERIFIED to 0

查看:112
本文介绍了PayPal IPN不会返回VERIFIED到0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已要求我的Paypal api发送$ res电子邮件以查看响应是什么.一会儿(!feof($ fp)){}

I have asked my paypal api to send email of $res to see what the response is. Inside of the while (!feof($fp)) {}

这就是我从$ res到我的电子邮件的电子邮件

This is what i'm getting from $res to my email

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){},它将正常工作.

This doesn't work if (strcmp ($res, "VERIFIED") == 0){} but if I change it to if (strcmp ($res, "VERIFIED") == -1){} It works fine.

更新

我已将代码更改为

$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
}

有人可以确认此代码是否有问题.

Can someone please confirm if they is any problem with this code.

推荐答案

VERIFIED和INVALID是从PAYPAL取回响应后需要验证的两个响应.
您可以在
中引用代码示例. https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

VERIFIED and INVALID are the two responses that you need to validate once you get the response back from PAYPAL.
You can refer the code samples at
https://www.x.com/developers/PayPal/documentation-tools/code-sample/216623

这篇关于PayPal IPN不会返回VERIFIED到0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆