Php 努力接收Paypal沙盒IPN Post数据

Php 努力接收Paypal沙盒IPN Post数据,php,paypal,paypal-ipn,Php,Paypal,Paypal Ipn,我的主机启用了PHP5.0和SSL,但在严格搜索在线论坛和博客之后,我一辈子都搞不明白为什么我会空手而归,而我正试图使用Paypal IPN脚本。我正在使用沙盒模拟器测试脚本,因此在检索Post数据时没有任何风险。请参阅我的以下代码- $header = ''; $req = 'cmd=_notify-validate'; foreach($_POST as $key => $value) { //All PayPal reqs must be URL encoded

我的主机启用了PHP5.0和SSL,但在严格搜索在线论坛和博客之后,我一辈子都搞不明白为什么我会空手而归,而我正试图使用Paypal IPN脚本。我正在使用沙盒模拟器测试脚本,因此在检索Post数据时没有任何风险。请参阅我的以下代码-

$header = '';

$req = 'cmd=_notify-validate';

foreach($_POST as $key => $value) {
    //All PayPal reqs must be URL encoded
    $value = urlencode(stripslashes($value));
    //Append key => value pair to CMD string
    $req .= "&$key=$value";
} 


//Post info back to paypal for verification
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
// $header .= "Host: ssl://www.sandbox.paypal.com\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//$header .= "Connection: Close\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

$con=mysql_connect("localhost","quadsour_xswitch","xswitch");
mysql_select_db("quadsour_xswitch",$con);//$data="NULL"

if(!$fp) {
    //Process HTTP Error
     $filename = 'debug.txt';
    $filehandle=fopen($filename, 'w');
    fwrite($filehandle, $errstr.'('.$errno.')');
    fclose($filehandle);
    die();

 $message .= "\n HTTP ERROR. \n";

} else {
    fputs ($fp, $header . $req);
    while (!feof($fp)) {
        $res = stream_get_contents($fp, 1024);
        /* $data="INSERT INTO ipn SET
        complete='".$errstr."',invoice='".$errno."'";
        $query=mysql_query($data);
        */

        //VERIFIED TRANSACTION
        //PAYMENT
        if($_POST['payment_status'] == 'completed') {
            $data="INSERT INTO ipn SET
            complete='cond'";
            $query=mysql_query($data);

            $data="INSERT INTO ipn SET
            complete='true',
            invoice='".$_POST['invoice']."',
            email='".$_POST['payer_email']."'
            ";
            $query=mysql_query($data);

            //$subscription = //Do SQL to retrieve the subscription based on $_POST['invoice']


        } 

    }

    fclose ($fp);
}

作为一个编写了两个PHP库来使用PayPal IPN(下面是CodeIgniter和Symfony2库)的人,我不得不说,您的脚本远远不足以以安全和健壮的方式处理PayPal IPN的所有可能情况

与其重新发明轮子,不如根据您的PHP设置插入以下库之一:

  • (通用PHP 5)

错误日志中有错误吗?检查paypal上的日志,它为IPN呼叫提供了什么状态代码?