douxin8610 2016-11-15 01:45
浏览 64
已采纳

PayPal notify_url无法通过strcmp验证

I'm having some issues with my notify_url in PayPal. The handshake is fine, but the code to update my DB doesn't work. So to debug, I'm using the return.php url to output some data and try to debug and echo where the problem is.

Here is what I did so far to debug (on return.php)

$req = 'cmd=_notify-validate';
 foreach ($_POST as $key => $value) 
{
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

echo "<br>test REQ: ".$req."<br><br>";;

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

";


$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

if (!$fp) 
{
    echo "FP NOT WORKIGN";
} 
else 
{
    echo "FP WORKIGN<br><br>";

    fputs ($fp, $header . $req);

    while (!feof($fp)) 
    {
        echo "whie: YES<br>";
        $res = fgets ($fp, 1024);
        if (strcmp ($res, "VERIFIED") == 0) 
        {
            echo "verified<br>";

            if($status == "Completed")
            {   
                echo "<br>####### completed<br>";
            }
        }
    }
}

My result is I get the echo of REQ, I get the echo of FP Working, I get echo "WHILE YES" 5 times, but I don't the echo of "VERIFIED". SO it seems the script doesn't get pass the if (strcmp ($res, "VERIFIED") == 0)

I'm stuck now, how can I fix this issue? Not sure what's wrong

This is the echo of my $req (if it helps to debug)

test: cmd=_notify-validate&mc_gross=1.00&protection_eligibility=Ineligible&payer_id=3EW5DFETD3E4L&tax=0.00&payment_date=15%3A35%3A43+Nov+14%2C+2016+PST&payment_status=Completed&charset=windows-1252&first_name=test&mc_fee=0.33¬ify_version=3.8&custom=1000%40%40Katia%40%40213+st-louis%40%40lemoyne%40%40quebec%40%40j4r+2l3%40%40Canada%40%401%40%40CAD%40%400%40%401.00&payer_status=verified&business=louisefrigon1-facilitator%40gmail.com&quantity=1&payer_email=louisefrigon1-buyer%40gmail.com&verify_sign=AFcWxV21C7fd0v3bYYYRCpSSRl31AchhgWj8TBE3e7K7SSx6jHwconuT&txn_id=6E11719159210262F&payment_type=instant&last_name=buyer&receiver_email=louisefrigon1-facilitator%40gmail.com&payment_fee=&receiver_id=LMCZ83V6LRE4S&txn_type=web_accept&item_name=Superfood+Powder&mc_currency=CAD&item_number=&residence_country=CA&test_ipn=1&handling_amount=0.00&transaction_subject=&payment_gross=&shipping=0.00&merchant_return_link=click+here&auth=A1CZ8ecFDP.O-dZHCSU6ouq8Gxn8qrDXHyoUX9qI-CEmFlvuS1Rq8FlqPmP8dCqlTffcxTJX84-huLEvRi5C.fA
  • 写回答

1条回答 默认 最新

  • dpxw17759 2016-11-15 01:53
    关注

    The result of fgets() includes the newline, but "VERIFIED" doesn't have a newline. You need to strip it off before comparing.

    $res = trim(fgets($fp, 1024));
    

    There's also no point in using strcmp() if you just want to test if two strings are equal, just use ==.

    if ($res == "VERIFIED") {
        ...
    }
    

    But instead of trying to do the HTTP protocol yourself, use curl.

    $req = 'cmd=_notify-validate&' . http_build_query($_POST);
    $ch = curl_init('https://www.sandbox.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_POST, true);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    $res = curl_exec($ch);
    if ($res == "VERIFIED") {
        echo "verified<br>";
        if($status == "Completed")
        {   
            echo "<br>####### completed<br>";
        }
    } else {
        echo "$res<br>";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 streamingtool
  • ¥15 MATLAB图像问题
  • ¥20 树莓派5做人脸情感识别与反馈系统
  • ¥15 selenium 控制 chrome-for-testing 在 Linux 环境下报错 SessionNotCreatedException
  • ¥15 使用pyodbc操作SQL数据库
  • ¥15 MATLAB实现下列
  • ¥30 mininet可视化打不开.mn文件
  • ¥50 C# 全屏打开Edge浏览器
  • ¥80 WEBPACK性能优化
  • ¥30 python拟合回归分析