未收到 Paypal IPN Sandbox 的响应

发布于 2024-12-18 14:01:50 字数 1405 浏览 5 评论 0原文

我正在我的网站上进行贝宝结帐,但我对听众感到失望。 对于那些不熟悉 Paypal IPN 系统的人来说,基本上 Paypal 会向您的脚本发送一条有关交易的消息,您将其发送回来并添加一些位。如果 Paypal 收到正确的回复,则会回复“已验证”,否则会回复“无效”。

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

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

<?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);
        }
    }
}

?>

提前致谢!

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'.

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

深居我梦 2024-12-25 14:01:50

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

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

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

或者

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

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.

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);
手心的温暖 2024-12-25 14:01:50

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

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

。我所做的就是将其替换为:

$res=stream_get_contents($fp, 1024);

并且它第一次起作用了!现在我可以继续我的生活了。再次感谢您对此事的所有帮助。

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

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.

ㄖ落Θ余辉 2024-12-25 14:01:50

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

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

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

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

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

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

百善笑为先 2024-12-25 14:01:50

我注意到您发布的网址与下面的有点不同,可能是这个吗?

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

检查您是否将回复发布到正确的网址,即 https:// /www.sandbox.paypal.com/cgi-bin/webscrhttps://www.paypal.com/cgi-bin/webscr,分别取决于您是在沙盒中测试还是在现场进行测试。

验证您的响应是否包含完全相同的 IPN 变量和值(顺序相同),前面带有 cmd=_notify-validate。

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

编辑:抱歉,我还想提一下,HTTP 和 HTTPS 的端口是不同的,80 而不是 443。我对 Paypal API 不太熟悉,但可以研究一下,因为我看到您正在使用 80。

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:

Check that your are posting your response to the correct URL, which is https://www.sandbox.paypal.com/cgi-bin/webscr or 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.

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.

岁月静好 2024-12-25 14:01:50

PayPal 测试服务器移至:

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

PayPal test server moved to:

$fp = fsockopen('ssl://ipnpb.paypal.com', 443, $errno, $errstr, 30);
暖阳 2024-12-25 14:01:50

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

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

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

访问链接

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.

paypal has disabled the service of sslv3 and changed to 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.

visit the link.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文