gpt4 book ai didi

php - Paypal 返回 400 错误大 IP 连接

转载 作者:太空宇宙 更新时间:2023-11-03 16:05:17 27 4
gpt4 key购买 nike

我正在为 php 使用以下 paypal ipn 脚本,但它给我带来了 400 错误。如果有人能帮助我,我将不胜感激,因为它过去工作正常,没有问题,但现在我收到以下错误。我回应了

的结果

如果我的客户切换到 ssl,此脚本也有任何问题。

HTTP/1.0 400 Bad Request Server: BigIP Connection: close Content-Length: 0

  <?php
error_reporting(E_ALL ^ E_NOTICE);



$header = "";
$emailtext = "";

// read the post from paypal and add 'cmd'
$req = 'cmd=_notify-validate';
if(function_exists('get_magic_quotes_gpc'))
{
$get_magic_quotes_exits = true;
}

// handle escape characters, which depends on setting of magic quotes
foreach ($_POST as $key => $value)
{
if($get_magic_quotes_exists == true && get_magic_quotes_gpc() == 1)
{
$value = urlencode(stripslashes($value));
}
else
{
$value = urlencode($value);
}
$req .= "&$key=$value";
}

// post back to paypal 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";

// here you can use ssl, or not
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

// process validation from paypal
// TODO: This sample does not test the http response code.
// All HTTP response codes must be handles or you should use an HTTP
// library, such as cUrl.

if (!$fp)
{
// HTTP ERROR
}
else
{
// NO HTTP ERROR
fputs ($fp, $header . $req);
while (!feof($fp))
{
$res = fgets ($fp, 1024);
echo "test";
if (strcmp ($res, "VERIFIED") == 0)
{
// get variables from the paypal post to us
// see these pages for possible variables:
// https://developer.paypal.com/us/cgi-bin/devscr
// https://cms.paypal.com/us/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNIntro

// payment info
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];

// product info
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];

// buyer info
$payer_email = $_POST['payer_email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address_city = $_POST['address_city'];
$address_state = $_POST['address_state'];
$address_country = $_POST['address_country'];

// receiver_email, that's our email address
$receiver_email = $_POST['receiver_email'];

// put your actual email address here
$our_email = 'davidbuckleyweb@gmail.com';
echo $payment_status;
// if all these conditions are true, send the email
// note: should also verify that $txn_id was not used before
if (($payment_status == 'Completed') &&
($payment_amount == $amount_they_should_have_paid ) )
{
foreach ($_POST as $key => $value)
{
$emailtext .= $key . " = " .$value ."\n\n";
}
mail($payer_email, "Live-VERIFIED IPN", $emailtext . "\n\n" . $req);

echo $payment_status;
}


}
else if (strcmp ($res, "INVALID") == 0)
{
// If 'INVALID', send an email. TODO: Log for manual investigation.
foreach ($_POST as $key => $value)
{
$emailtext .= $key . " = " .$value ."\n\n";
}
mail($payer_email, "Live-INVALID IPN", $emailtext . "\n\n" . $req);
}
}
}
fclose ($fp);
?>

最佳答案

由于 Paypal Sandbox 强制执行 HTTP/1.1,因此您需要使用 HTTP/1.1

关于php - Paypal 返回 400 错误大 IP 连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48685122/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com