我正在将paypal结账放到我的网站上,但是我和听众一起倒下了.对于那些不熟悉Paypal IPN系统的人来说,Paypal基本上会向您的脚本发送一条有关交易的消息,您可以通过添加几个位来发回该消息.如果Paypal收到正确的答复,它将回复'已验证',如果没有,它会说'无效'.
第一位我成功了.我的代码能够从paypal接收信息,添加额外内容并将其发回.但是,Sandbox没有回复说"已验证"或"无效".我几乎从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, …Run Code Online (Sandbox Code Playgroud) 我的Paypal IPN监听器脚本问题已经有几天了.对于那些不熟悉Paypal IPN系统的人来说,Paypal基本上会向您的脚本发送一条有关交易的消息,您可以通过添加几个位来发回该消息.如果Paypal收到正确的答复,它将回复'已验证',如果没有,它会说'无效'.
我最初认为我遇到的问题是'fsockopen'命令:$ fp = fsockopen('ssl://sandbox.paypal.com',443,$ errno,$ errstr,30); 但是,将我的所有代码简化为这一行,它似乎连接好了.问题在于'feof'和'fgets'命令.脚本挂断了,我不知道为什么.我基本上复制了Paypal IPN Listener网站上建议的代码,所以我认为它会起作用!如果你能帮助我理解为什么feof或fgets导致它失速,那么你的帮助将非常感激.
这是完整的脚本:
$postback = 'cmd=_notify-validate'; //doesn't matter what these include for now
$header='abc';
//Script has been activated, create debug
$filename = 'debug/debug1_script.txt';
$filehandle=fopen($filename, 'w');
fwrite($filehandle,$postback);
fclose($filehandle);
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);//open the connection
//no connection, create debug file
if(!$fp){
$filename = 'debug/debug2_fpfail.txt';
$filehandle=fopen($filename, 'w');
fwrite($filehandle, $errstr.'('.$errno.')');
fclose($filehandle);
die();
}
//post data back
fputs($fp, $header . $postback);
//create debug file
$filename = 'debug/debug3_postback.txt';
$filehandle=fopen($filename, 'w');
fwrite($filehandle, $header.$postback); …Run Code Online (Sandbox Code Playgroud)