未收到 Paypal IPN Sandbox 的响应
我正在我的网站上进行贝宝结帐,但我对听众感到失望。 对于那些不熟悉 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
切换到使用 HTTPS url,我不确定什么时候,但最近我的所有测试脚本开始在纯 HTTP 版本上失败。他们看起来正在迁徙过来。
我正在使用与您相同的 paypal 示例代码:
或者
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:
or
所以我想我找到了解决方案。事实证明,连接到 ssl://sandbox 时没有遇到问题......,它实际上正在检索答案。代码被挂在了位上
。我所做的就是将其替换为:
并且它第一次起作用了!现在我可以继续我的生活了。再次感谢您对此事的所有帮助。
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
bit. All I did was replace it with:
and it worked first time! Now I can get on with my life. Thanks again for all the help on this one.
也许原始代码丢失了:
$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.
我注意到您发布的网址与下面的有点不同,可能是这个吗?
这是来自 IPN 测试帮助页面:
编辑:抱歉,我还想提一下,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:
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.
PayPal 测试服务器移至:
PayPal test server moved to:
检查 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.