【问题标题】:paypal sandbox responds bad request贝宝沙箱响应错误请求
【发布时间】:2011-08-25 14:11:48
【问题描述】:

我有以下 HTML 表单

<form action="https://sandbox.paypal.com/cgi-bin/webscr" method="post" id="paypalpost" name="paypalpost">
                <input type="hidden" name="rm" value="2"/>
                <input type="hidden" name="cmd" value="_xclick">
                <input type="hidden" name="business" value="vbnetdiscuss@yahoo.com">
                <input type="hidden" name="item_name" value="Wedding Gift">
                <input type="hidden" name="currency_code" value="EUR">
                <input type="hidden" name="amount" value="<?php echo $value['total'];?>">
                <input type="hidden" name="return" value="http://developwithus.com/wedding/return.php">
                <input type="hidden" name="cancel_return" value="http://developwithus.com/wedding/return.php?status=0">


            <input onclick="return submitatoc();" disabled type="submit" name="submit" id="pay" class="buttonBlueBg" value="Checkout" style="cursor:pointer;">

            </form>

我提到返回 URL 为 http://developwithus.com/wedding/return.php 在其上,(我已经从 https://cms.paypal.com/cms_content/US/en_US/files/developer/IPN_PHP_41.txt 下载了这个并添加

<?php 
print_r('<pre>');
print_r($_POST);
// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
}

// post back to PayPal system to validate
$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";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
    echo "HTTP Error";
} else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = fgets ($fp, 1024);
        echo $res;
        if (strcmp ($res, "VERIFIED") == 0) {
            // check the payment_status is Completed
            // check that txn_id has not been previously processed
            // check that receiver_email is your Primary PayPal email
            // check that payment_amount/payment_currency are correct
            // process payment
            echo("verified");
        }
        else if (strcmp ($res, "INVALID") == 0) {
            // log for manual investigation
            echo ("invalid");
        }
    }
    fclose ($fp);
}
echo "end";
?>

但是我收到了 Bad Request 作为响应,如果我去 paypal 沙盒帐户并付款并返回。

Array
(
   [CONTEXT] => wtgSziM4C5x0SI-9CmKcv2vkSeTLK5P_g6HqzC__YTYkcqziFNcB84p79Ja
   [myAllTextSubmitID] => 
   [cmd] => _flow
   [mc_gross] => 100.00
   [protection_eligibility] => Ineligible
   [address_status] => confirmed
   [payer_id] => Z5NWSYYVZW268
   [tax] => 0.00
   [address_street] => 1 Main St
   [payment_date] => 09:04:08 May 14, 2011 PDT
   [payment_status] => Pending
   [charset] => windows-1252
   [address_zip] => 95131
   [first_name] => Test
   [address_country_code] => US
   [address_name] => Test User
   [notify_version] => 3.1
   [custom] => 
   [payer_status] => verified
   [address_country] => United States
   [address_city] => San Jose
   [quantity] => 1
   [payer_email] => sujeet_1302606445_per@gmail.com
   [verify_sign] => AozIjtjfCe0jUnbJpR4qPrW54olKAq.SrnEktGSocrk8yYv4bpR4lJX7
   [txn_id] => 3HG58230W32603443
   [payment_type] => instant
   [last_name] => User
   [address_state] => CA
   [receiver_email] => vbnetdiscuss@yahoo.com
   [pending_reason] => unilateral
   [txn_type] => web_accept
   [item_name] => Wedding Gift
   [mc_currency] => EUR
   [item_number] => 
   [residence_country] => US
   [test_ipn] => 1
   [transaction_subject] => Wedding Gift
   [handling_amount] => 0.00
   [payment_gross] => 
   [shipping] => 0.00
   [merchant_return_link] => click here
   [form_charset] => UTF-8
)
HTTP/1.1 400 Bad Request
Date: Sat, 14 May 2011 16:05:20 GMT
Server: Apache
Set-Cookie: c9MWDuvPtT9GIMyPc3jwol1VSlO=%7cgA9mW0Yh7-iBp435VBDwyCqtOtnlE8KAk8fT_sjGXHGx2mDzXgFit5ZdHd3BOOEUt_UDRW%7cRD1g8aAyLevIAP-u4WfCokEQkimrkpQk6v6rLZ_xD-pT1ATWuv5RtcK3NIbPPwfF1cXq3G%7c; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: cookie_check=yes; expires=Tue, 11-May-2021 16:05:20 GMT; domain=.paypal.com; path=/; Secure; HttpOnly
Set-Cookie: Apache=10.191.196.11.9095130538912094; path=/; expires=Fri, 31-Mar-05 09:37:04 GMT
Connection: close
Content-Type: text/plain; charset=ISO-8859-1

你们能告诉我我做错了什么吗? 无效响应正在工作

【问题讨论】:

    标签: php paypal


    【解决方案1】:

    删除您的 *.paypal.com cookie。
    这是 PayPal 系统中的一个不幸的错误,其中 cookie 变得太大并且服务器在上面出错。
    您可以通过使用两种不同的浏览器来避免该问题,例如IE 用于 PayPal Live,FF 用于 PayPal Sandbox。

    【讨论】:

    • 无论如何,我都会收到 400 Bad Request - 在清除 cookie 或安装 Chrome 并使用它之后。它还输出“Invalid Host header”。
    • 你能给我发一封关于这个问题的电子邮件吗?附上错误页面的截图+来源的副本?我的地址是 ppmtsrob@gmail.com——这并不完全适合 SO,但我想继续研究。
    • 我在这个问题中找到了解决方案:stackoverflow.com/a/11811213/486990 我的 IPN 使用的是旧的 PHP4 示例。最初它使用 HTTP,但现在返回 302。然后我切换到 SSL,我得到了 400。但那是因为缺少 Host 标头。那是我用 localhost 调试的时候。但是,我的实时站点使用 SSL 和旧的 PHP4 示例,没有 Host 标头,但它可以工作。我发现其他人的报告说他们也注意到沙盒在没有主机的情况下会失败,但 Live IPN 不会。但是,我正在更新我的 IPN 以使用 PHP 5.2 示例以避免将来出现问题。
    • 很高兴您解决了这个问题。不过,我仍然很困惑你为什么在 Chrome 中得到它。从 chrome 访问 PayPal 时,您不应该得到这个。
    • 令人惊讶的是,他们已经知道这件事 10 个月了,却什么也没做。
    【解决方案2】:

    您正在尝试自己打开套接字,因此您需要自己在 $header = POST 下方添加 HTTP Host 标头。

    $header .= "Host: www.sandbox.paypal.com\r\n";
    

    来源:PayPal IPN Bad Request 400 Error

    【讨论】:

    • 太棒了...添加行
      $header .= "Host: www.sandbox.paypal.com\r\n";
      到标题解决问题...非常感谢!!
    【解决方案3】:

    您可以尝试如下:https://www.x.com/thread/47663 那家伙删除了贝宝回发网址上的一些参数。 这个对我有用。 希望对您有所帮助

    【讨论】:

      猜你喜欢
      • 2013-07-14
      • 2023-03-29
      • 2017-01-10
      • 2013-03-19
      • 2017-12-16
      • 2012-08-31
      • 2011-02-21
      • 2013-01-27
      • 2013-01-11
      相关资源
      最近更新 更多