mysql 数据库无法正常工作的 PayPal IPN

PayPal IPN to mysql database not working

我正在尝试让我的 PayPal 自动将付款插入 MySQL。

这是我的 table 结构:

CREATE TABLE IF NOT EXISTS idevicev2 (
  id int(11) NOT NULL AUTO_INCREMENT,
  transactie_id varchar(60) NOT NULL,
  programma varchar(60) NOT NULL,
  naam varchar(60) NOT NULL,
  email varchar(60) NOT NULL,
  transactie_datum datetime NOT NULL,
  status varchar(60) NOT NULL,
  totaal_bedrag varchar(8) NOT NULL,
  ieverything_else text NOT NULL,
  username varchar(60) NOT NULL,
  password varchar(2) NOT NULL DEFAULT '10',
  active varchar(2) NOT NULL DEFAULT '10',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB  DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

这是我用于 IPN 的脚本:

<?php
   //Change these with your information
$paypalmode = ''; //Sandbox for testing or empty ''
$dbusername     = 'myusername'; //db username
$dbpassword     = 'mypassword'; //db password
$dbhost     = 'localhost'; //db host
$dbname     = 'mydbname'; //db name

if($_POST)
{
        if($paypalmode=='sandbox')
        {
            $paypalmode     =   '.sandbox';
        }
    $req = 'cmd=' . urlencode('_notify-validate');
    foreach ($_POST as $key => $value) {
        $value = urlencode(stripslashes($value));
        $req .= "&$key=$value";
    }
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_POST, 1);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
    $res = curl_exec($ch);
    curl_close($ch);

    if (strcmp ($res, "VERIFIED") == 0)
    {
        $transaction_id = $_POST['txn_id'];
        $username = $_POST['txn_id'];
        $itemname = $_POST['item_name'];
        $firstname = $_POST['first_name'];
        $lastname = $_POST['last_name'];
        $payeremail = $_POST['email'];
        $paymentdate = $_POST['payment_date'];
        $paymentstatus = $_POST['payment_status'];
        $mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
        $mcgross = $_POST['mc_gross'];
        $otherstuff = json_encode($_POST); 

        $conn = mysql_connect($dbhost,$dbusername,$dbpassword);
        if (!$conn)
        {
         die('Could not connect: ' . mysql_error());
        }

        mysql_select_db($dbname, $conn);

        // insert in our IPN record table
        $query = "INSERT INTO idevicev2
        (transactie_id,programma,naam,email,transactie_datum,status,totaal_bedrag,username,ieverything_else)
        VALUES
        ('$transaction_id','$itemname','$firstname $lastname','$payeremail','$mdate','$paymentstatus','$mcgross','$username','$otherstuff')";

        if(!mysql_query($query))
        {
            //mysql error..!
        }
        mysql_close($conn);

    }

} ?>

现在,当我转到:https://developer.paypal.com/webapps/developer/applications/ipn_simulator 并输入我的 IPN URL 时,PayPal 说 IPN 已发送,但我没有在我的 MYSQL 数据库中获取数据。

我做错了什么?

使其与沙盒帐户一起使用。现在只需将沙盒更改为 ''

<?php
           //Change these with your information
        $paypalmode = 'sandbox'; //Sandbox for testing or empty ''
        $dbusername     = ''; //db username
        $dbpassword     = ''; //db password
        $dbhost     = ''; //db host
        $dbname     = ''; //db name

    if($_POST)
    {
            if($paypalmode=='sandbox')
            {
                $paypalmode     =   '.sandbox';
            }
            $req = 'cmd=' . urlencode('_notify-validate');
            foreach ($_POST as $key => $value) {
                $value = urlencode(stripslashes($value));
                $req .= "&$key=$value";
            }
            $ch = curl_init();
            curl_setopt($ch, CURLOPT_URL, 'https://www'.$paypalmode.'.paypal.com/cgi-bin/webscr');
            curl_setopt($ch, CURLOPT_HEADER, 0);
            curl_setopt($ch, CURLOPT_POST, 1);
            curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
            curl_setopt($ch, CURLOPT_POSTFIELDS, $req);
            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
            curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
            curl_setopt($ch, CURLOPT_HTTPHEADER, array('Host: www'.$paypalmode.'.sandbox.paypal.com'));
            $res = curl_exec($ch);
            curl_close($ch);

            if (strcmp ($res, "VERIFIED") == 0)
            {
                $transaction_id = $_POST['txn_id'];
                $payerid = $_POST['payer_id'];
                $firstname = $_POST['first_name'];
                $lastname = $_POST['last_name'];
                $payeremail = $_POST['payer_email'];
                $paymentdate = $_POST['payment_date'];
                $paymentstatus = $_POST['payment_status'];
                $mdate= date('Y-m-d h:i:s',strtotime($paymentdate));
                $otherstuff = json_encode($_POST);

                $conn = mysql_connect($dbhost,$dbusername,$dbpassword);
                if (!$conn)
                {
                 die('Could not connect: ' . mysql_error());
                }

                mysql_select_db($dbname, $conn);

                // insert in our IPN record table
                $query = "INSERT INTO ibn_table
                (transactie_id,koper_id,naam,email,transactie_datum,betalings_status,ieverything_else)
                VALUES
                ('$transaction_id','$payerid','$firstname $lastname','$payeremail','$mdate', '$paymentstatus','$otherstuff')";

                if(!mysql_query($query))
                {
                    //mysql error..!
                }
                mysql_close($conn);

            }
    }
    ?>