5

这种无法解释的可能会影响或将影响成千上万的网站管理员。

问题是 Paypal 根本没有对此请求作出响应。以下是我使用的示例代码以及我的程序员的评论:

我的订单日期 - 重复了 5 次!为什么?谁知道...这仅意味着 PayPal 尝试对该脚本进行 5 次 IPN,但均未成功。仅当我将 HTTP 更新为 1.0 并重新上传脚本时,PayPal 才会出现“已验证”响应。在那之后,贝宝仍在查询它。似乎当 HTTP = 1.1 时,PayPal 正在正确获取所有内容,但没有正确响应;然后由于某种原因返回为同一付款创建另一个响应。使用 HTTP 1.0,一切都像一朵花:一个请求,一个响应,一切正常。我不知道它有什么问题... 0 并重新上传脚本。在那之后,贝宝仍在查询它。似乎当 HTTP = 1.1 时,PayPal 正在正确获取所有内容,但没有正确响应;然后由于某种原因返回为同一付款创建另一个响应。使用 HTTP 1.0,一切都像一朵花:一个请求,一个响应,一切正常。我不知道它有什么问题... 0 并重新上传脚本。在那之后,贝宝仍在查询它。似乎当 HTTP = 1.1 时,PayPal 正在正确获取所有内容,但没有正确响应;然后由于某种原因返回为同一付款创建另一个响应。使用 HTTP 1.0,一切都像一朵花:一个请求,一个响应,一切正常。我不知道它有什么问题...

附言。我们不是在谈论“无效”响应。'INVALID' 响应实际上是成功的一部分——但在 HTTP 1.1 的情况下,PayPal 根本不提供任何响应,它是一个空字符串。”

<?php

$req = 'cmd=_notify-validate';
$r='';

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

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
#I also tried: $fp =fsockopen('ssl://www.paypal.com',443,$err_num,$err_str,30);

if (!$fp) {
$r.="----\nHTTP ERROR\n";
// HTTP ERROR
} else {

$r.="----\nReceived IPN request\n";

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

while (!feof($fp)) {
$res = fgets ($fp, 1024);
}
fclose ($fp);

if (strcmp ($res, 'VERIFIED') == 0) {

$proceed=TRUE;

}
else{
$proceed=FALSE;
}
}

?>

PS。这是notify_url我们使用的脚本的一部分:

<input type="hidden" name="notify_url" value="{$main_url}/index.php?action=ipn&amp;user_id={$user_id}" />

当它在沙盒中测试时它正在工作..

4

7 回答 7

12

改变这个:

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
#I also tried: $fp =fsockopen('ssl://www.paypal.com',443,$err_num,$err_str,30);

对此:

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n";
$header .= "Connection: close\r\n\r\n";
$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

和这个:

if (strcmp ($res, 'VERIFIED') == 0) {

对此:

if (strcmp (trim($res), 'VERIFIED') == 0) {

它几乎可以保证工作。

您当前的设置失败,因为 PayPal 在 fsockopen 欣然接受的响应中发送了 Connection: keep-alive 标头,因此它使连接保持打开状态。
而像 cURL 这样的 HTTP 库会自动关闭连接。

我的一般建议是;如果您不想控制连接到 PayPal 的每一位,请使用 HTTP 库,例如 cURL,而不是 fsockopen,后者只是一个普通的 TCP 连接。
(PayPal 在https://www.paypal.com/ipnhttps://www.paypal.com/pdt提供了使用 cURL 的示例代码)

于 2012-09-18T21:53:25.787 回答
2

在上面的代码中,您可以替换:

if (strcmp ($res, "VERIFIED") == 0) { 

if (strcmp (trim($res), "VERIFIED") == 0) { 

唯一的区别是修剪

于 2012-09-26T09:01:25.850 回答
1

我添加了以下行,这很好用

$res = 修剪($res);

参考链接

  1. http://www.johnboy.com/blog/http-11-paypal-ipn-example-php-code
  2. http://www.johnboy.com/scripts/paypal-ipn/paypal_ipn_1_1.phps
于 2013-09-10T05:03:12.980 回答
1

我发现了这个http://www.justmyusecase.com/2012/09/subject-action-required-update-your.html

看起来您只需要修剪“已验证”字符串。

于 2012-09-18T19:21:40.823 回答
0

Since middle of December 2012 we did not receive any IPN from PayPal. There are no entries in the web servers access or error logs that indicates that PayPal is trying to send IPNs since then.

So i had a phone call with the german paypal support today (After more then 2 hours in the waiting line - i reached finally somebody).

They confirmed to me, that there is a problem with some accounts (No sending of IPN) and that they try to fix it. So before you try to change your Scripts, watchout for the server log files first!

于 2013-01-23T12:51:16.493 回答
0

好吧,我的 IPN 有类似的东西

尝试更改 PayPal 上的 IPN 编码

我的帐户 => 我的个人资料 => 我的销售工具 => 语言编码

于 2013-02-10T21:57:44.147 回答
-1

我也有这个问题,PP 拒绝承认有问题。我不知道该怎么办,但客户会在四个月后发疯。

您应该进行的一项更改是:

$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n"; // wrong  
$header .= "POST cgi-bin/webscr HTTP/1.1\r\n"; // right (according to PP)
于 2012-09-18T18:38:41.540 回答