问题描述
我正在将贝宝(Paypal)结帐到我的网站上,但与收听者不合.对于那些不熟悉Paypal IPN系统的人,基本上Paypal会向您的脚本发送有关交易的消息,然后再添加一些附加位,将其发送回去.如果Paypal收到正确的答复,它将以'VERIFIED'答复,否则,将显示'INVALID'.
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网站上复制了我的代码,所以我希望这将非常简单,因此,如果您花一点时间查看我的代码,也许有些新的眼睛可能会发现我出了问题的地方
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);
}
}
}
?>
提前谢谢!
推荐答案
所以我想我找到了解决方案.事实证明,连接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
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.
这篇关于没有收到Paypal IPN沙箱的回复的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!