Php IPN Post每次都是空的
我使用的IPN示例直接来自于 我支付给PayPal没有问题,PayPal重定向到我的侦听器没有问题,但总是产生一个空的$\u POST变量。有人能看到问题吗Php IPN Post每次都是空的,php,paypal,paypal-ipn,Php,Paypal,Paypal Ipn,我使用的IPN示例直接来自于 我支付给PayPal没有问题,PayPal重定向到我的侦听器没有问题,但总是产生一个空的$\u POST变量。有人能看到问题吗 <?php // Send an empty HTTP 200 OK response to acknowledge receipt of the notification header('HTTP/1.1 200 OK'); // Assign payment notification values to
<?php
// Send an empty HTTP 200 OK response to acknowledge receipt of the notification
header('HTTP/1.1 200 OK');
// Assign payment notification values 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'];
// Build the required acknowledgement message out of the notification just received
$req = 'cmd=_notify-validate'; // Add 'cmd=_notify-validate' to beginning of the acknowledgement
echo '<pre>';
var_dump($_POST);
echo '</pre><hr/>';
foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode these values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}
// Set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// Send the HTTP POST request back to PayPal for validation
fputs($fp, $header . $req);
while (!feof($fp)) { // While not EOF
$res = fgets($fp, 1024); // Get the acknowledgement response
if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
// Authentication protocol is complete - OK to process notification contents
echo 'thanks for the payment, we are processing your request.';
} else if (strcmp ($res, "INVALID") == 0) {
//Response contains INVALID - reject notification
echo 'something has gone wrong. please try again.';
}
}
fclose($fp); // Close the file
?>
更新以添加按钮代码:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
您没有看到任何内容的原因是
var\u dump()
用于向浏览器输出$\u POST
。因此,当您访问IPN URL时,您没有向页面发布任何内容,因此页面中没有任何内容。此外,脚本的其余部分仍然执行,发送空白响应到贝宝进行验证,但由于它是空的,所以您得到<>代码>无效< /Calp> Read。
如果您想查看IPN向侦听器发布的内容,建议使用error\u log()
写入IPN日志。这将向您展示当PayPal向您的听众发帖时发生的事情
此外,我还注意到一些原本让我感到困惑的事情。首先是标题信息。PayPal更新了他们的系统,因此需要更多的标题信息。有关更新的通知,请参阅。BasicCall建议您改变这一点:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Host: www.paypal.com:443\r\n"; //<---added this
$header .= "Connection: close\r\n"; //<---and this
为此:
$header=“POST/cgi-bin/webscr HTTP/1.1\r\n”;//HTTP POST请求
$header.=“内容类型:application/x-www-form-urlencoded\r\n”;
$header.=“内容长度:”。斯特伦($req)。“\r\n\r\n”;
$header.=“主机:www.paypal.com:443\r\n”// 最后,我在PayPal网站的某个地方找到了另一个文档,其中有一个更新的示例脚本。它马上就起作用了,开箱即用(就像原来的一样)
以下是查找此链接的所有人的链接:您能在此处发布您的按钮代码吗?@Eshan它现在已包含在内。您是否尝试使用发送测试请求?我只是用一个简单的两行脚本(返回页眉并将$\u POST转储到文件)自己完成了这项工作,它按预期工作。实际上,我正试图访问签出页面,但由于按钮代码没有业务参数的完整值,我无法测试使用FireFoxtamperdata
插件查看PayPal服务器返回的内容。谢谢。看起来确实不错,但实际上,这些改变还不足以让脚本正常工作。
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Host: www.paypal.com:443\r\n"; //<---added this
$header .= "Connection: close\r\n"; //<---and this