php 未收到 Paypal IPN Sandbox 的响应

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8302028/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 04:22:59  来源:igfitidea点击:

Not receiving a response from Paypal IPN Sandbox

phppaypalpaypal-ipnpaypal-sandbox

提问by user1070084

I'm putting a paypal checkout onto my website but am falling down with the listener. For those of you who are unfamiliar with the Paypal IPN system, basically Paypal sends your script with a message about the transaction, which you send back with a couple of bits added. If Paypal receives the correct reply, it'll reply with 'VERIFIED', and if not it'll say 'INVALID'.

我在我的网站上放了一个 paypal 结账,但我对听众失望了。对于那些不熟悉 Paypal IPN 系统的人,基本上 Paypal 会向您的脚本发送一条有关交易的消息,然后您将添加的几位发回。如果 Paypal 收到正确的回复,它会回复“已验证”,否则会回复“无效”。

I've succeeded with the first bit. My code is able to receive the info from paypal, add on the extras and post it back. However, I get no response from the Sandbox saying either 'VERIFIED' or 'INVALID'. I've pretty much copied my code from the paypal website so I was hoping this was going to be fairly straightforward, so if you could take a minute to look at my code, perhaps some new eyes could pick out where I've gone wrong.

第一点我已经成功了。我的代码能够从贝宝接收信息,添加额外内容并将其发回。但是,我没有收到沙箱的回复,说“已验证”或“无效”。我几乎从贝宝网站复制了我的代码,所以我希望这会相当简单,所以如果你能花点时间看看我的代码,也许一些新人可以找出我出错的地方.

Here's the code. Nothing special, it literally just gets the info, adjusts it, passes it back and reads the response (which it either isn't getting or doesn't realise it's getting)

这是代码。没什么特别的,它实际上只是获取信息,调整它,将其传回并读取响应(它要么没有得到,要么没有意识到它正在得到)

<?php

$debug=true;

//Put together postback info

$postback = 'cmd=_notify-validate';

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

// build the header string to post back to PayPal system to validate
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($postback) . "\r\n\r\n";

$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);//open the connection

if(!$fp){ //no conn
    die();
}

//post data back
fputs($fp, $header . $postback);

while(!feof($fp)){

    $res=fgets ($fp, 1024);

    if((strcmp($res, "VERIFIED")) == 0){ //verified!
        if($debug){         
            $filename = 'debug/debug5_verified.txt'; //create a file telling me we're verified
            $filehandle=fopen($filename, 'w');
            fwrite($filehandle,'VERIFIED!');
            fclose($filehandle);
        }
    }
}

?>

Thanks in advance!

提前致谢!

采纳答案by user1070084

So I think I found a solution. Turns out it wasn't having trouble with connecting to ssl://sandbox...., it was actually retrieving the answer. The code was getting hung up on the

所以我想我找到了解决方案。事实证明,它在连接到 ssl://sandbox 时没有问题....,它实际上是在检索答案。代码被挂断了

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

bit. All I did was replace it with:

少量。我所做的只是将其替换为:

$res=stream_get_contents($fp, 1024);

and it worked first time! Now I can get on with my life. Thanks again for all the help on this one.

它第一次奏效!现在我可以继续我的生活了。再次感谢您对这一问题的所有帮助。

回答by preinheimer

Switch over to using the HTTPS url, I'm not sure when but recently all of my test scripts started failing on the plain HTTP version. They look to be migrating over.

切换到使用 HTTPS url,我不确定什么时候但最近我的所有测试脚本都开始在纯 HTTP 版本上失败。他们看起来要迁移过来了。

I'm using the same paypal sample code you are:

我正在使用与您相同的贝宝示例代码:

    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);    

or

或者

    $fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

回答by kitchin

Perhaps the original code was missing: $header .= "Connection: close\r\n\r\n";

也许原始代码丢失了: $header .= "Connection: close\r\n\r\n";

Note that the Paypal sample codeuses HTTP/1.0 so does not have that line. And HTTP/1.1 is fine but might need the line.

请注意,Paypal示例代码使用 HTTP/1.0,因此没有该行。HTTP/1.1 很好,但可能需要该行。

On another issue, Sandbox may no longer support port 80. I am getting a 302 redirect to https://www.sandbox.paypal.com.

在另一个问题上,Sandbox 可能不再支持端口 80。我收到了一个 302 重定向到https://www.sandbox.paypal.com

回答by Ademus

PayPal test server moved to:

PayPal 测试服务器移至:

$fp = fsockopen('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);

回答by deepu np

check up php version tls socket. it should be tls 1.2 to get the response from sandbox account. upgrade the php version to 5.5 to get tls 1.2 socket.

检查 php 版本 tls 套接字。它应该是 tls 1.2 从沙箱帐户获得响应。将 php 版本升级到 5.5 以获得 tls 1.2 套接字。

paypal has disabled the service of sslv3 and changed to tls 1.2.

paypal已经禁用了sslv3的服务,改为tls 1.2。

if you need to get the response,php version must require tls 1.2, in order to get tls 1.2 php can be upgraded to 5.5 or more.

如果你需要得到响应,php版本必须需要tls 1.2,为了得到tls 1.2 php可以升级到5.5或更高。

visit the link.

访问链接

回答by Ace

I've noticed that the URL you are posting to is a little different than below, could this be it?

我注意到您发布的网址与下面的网址略有不同,是这样吗?

this is from the IPN Testing help page:

这是来自 IPN 测试帮助页面:

Check that your are posting your response to the correct URL, which is https://www.sandbox.paypal.com/cgi-bin/webscror https://www.paypal.com/cgi-bin/webscr, depending on whether you are testing in the Sandbox or you are live, respectively.

Verify that your response contains exactly the same IPN variables and values in the same order, preceded with cmd=_notify-validate.

Ensure that you are encoding your response string and are using the same character encoding as the original message.

检查您是否将回复发布到正确的 URL,即https://www.sandbox.paypal.com/cgi-bin/webscrhttps://www.paypal.com/cgi-bin/webscr,具体取决于无论您是在沙盒中测试还是在线测试。

验证您的响应是否以相同的顺序包含完全相同的 IPN 变量和值,并以 cmd=_notify-validate 开头。

确保您对响应字符串进行编码并使用与原始消息相同的字符编码。

EDIT: Sorry I also wanted to mention that the port for HTTP and HTTPS are different, 80 as opposed to 443. I'm not too familiar with Paypal API but could look into it as I see you are using 80.

编辑:抱歉,我还想提到 HTTP 和 HTTPS 的端口不同,80 与 443 相对。我对 Paypal API 不太熟悉,但可以查看它,因为我看到您使用的是 80。