【发布时间】:2012-01-08 06:39:11
【问题描述】:
我正在我的网站上使用贝宝结帐,但我与听众不欢而散。 对于那些不熟悉 Paypal IPN 系统的人来说,Paypal 基本上会向您的脚本发送一条关于交易的消息,然后您将其发送回来并添加一些比特。如果 Paypal 收到正确的回复,它会回复 'VERIFIED',否则会说 'INVALID'。
我已经成功完成了第一点。我的代码能够从贝宝接收信息,添加附加内容并将其发回。但是,我没有从沙盒中收到“已验证”或“无效”的回复。我几乎从贝宝网站复制了我的代码,所以我希望这将是相当简单的,所以如果你可以花一点时间看看我的代码,也许一些新的眼睛可以找出我哪里出错了.
这是代码。没什么特别的,它实际上只是获取信息,对其进行调整,将其传回并读取响应(它要么没有得到,要么没有意识到它正在得到)
<?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);
}
}
}
?>
提前致谢!
【问题讨论】:
-
这个链接可能对你有帮助....stackoverflow.com/questions/14827497/…
标签: php paypal paypal-ipn paypal-sandbox