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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么