【问题标题】:paypal ipn mysql value change贝宝 ipn mysql 值更改
【发布时间】:2013-12-02 02:04:20
【问题描述】:

我正在尝试根据 paypal ipn 更改 mysql 数据库中的值。

我的 ipn.php:

$db=mysqli_connect("localhost","root","toor","database");

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];


if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

if($payment_status=='Completed'){

 $paylog = $db->query("UPDATE database.users SET money='$payment_amount' WHERE username='$item_name'");

}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}

c#支付按钮:

    private void pictureBox1_Click(object sender, EventArgs e)
    {
        int value;
        if (Int32.TryParse(textBox1.Text, out value))
            {
                if (value >= 10)
                {
                    Process myProcess = new Process();

                    try
                    {
                        // true is the default, but it is important not to set it to false
                        myProcess.StartInfo.UseShellExecute = true;
                        myProcess.StartInfo.FileName = "https://www.sandbox.paypal.com/cgi-bin/webscr?&cmd=_xclick&business=my.email@hidden.com&currency_code=EUR&amount=" + this.textBox1.Text + "&item_name=" + Form1.sendusername + "&notify_url=http://stormclap.it/ipn/ipn.php";
                        myProcess.Start();
                    }
                    catch (Exception em)
                    {
                        Console.WriteLine(em.Message);
                    }
                }
                else
                {
                    MessageBox.Show("Minimum deposit is 10 EUR!");
                }
            }
    }

只是为了理解。我设置 item_name = c# windows 表单用户的用户名。用户选择付款值并将其输入到 textbox1。必须 >= 10。

单击按钮时...沙箱 paypal 的 URL 将毫无问题地打开。 付款已处理并设置为完成。

在按钮和贝宝配置文件中输入业务沙箱 ipn url。

值是mysql没有改变。我做错了什么?请帮忙。谢谢!

【问题讨论】:

  • 您有什么理由使用自己的套接字和 http 标头而不是使用 curl 或流?
  • 没有理由......我认为它会毫无问题地工作。

标签: php mysql paypal paypal-ipn


【解决方案1】:

我找到了解决方案。我使 ipn.php 文件有点简单。现在工作得很好。

<?php

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// post back to PayPal system to validate
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$txn_id = $_POST['txn_id'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if($payment_status=='Completed'){

mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

mysql_query("UPDATE database.users SET money='$payment_amount' WHERE username='$item_name'") or die(mysql_error()); 

}
?>

【讨论】:

    【解决方案2】:

    我遇到了一个奇怪的问题。这是我的 notification.php 页面的代码,当 Paypal 发送 IPN 时这不起作用,但是当我重新发送 IPN 通知或尝试从 url 发布值时,这工作正常。

    <?php
    
    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    
    foreach ($_POST as $key => $value) {
    $value = urlencode(stripslashes($value));
    $req .= "&$key=$value";
    }
    
    // post back to PayPal system to validate
    $header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $header .= "Host: www.sandbox.paypal.com\r\n";
    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
    
    // assign posted variables to local variables
    $item_name = $_POST['item_name'];
    $item_number = $_POST['item_number'];
    $payment_status = $_POST['payment_status'];
    $payment_amount = $_POST['mc_gross'];
    $payment_currency = $_POST['mc_currency'];
    $txn_id = $_POST['txn_id'];
    $receiver_email = $_POST['receiver_email'];
    $payer_email = $_POST['payer_email'];
    
    if($payment_status=='Completed'){
    
        mysql_connect('mysql.abc.net', 'admin', 'pw');
                mysql_select_db('wbguru_appdb') or die(mysql_error());
    
                $sql1 = "UPDATE account SET pay_status_ipn = '1' WHERE tx_id = '" . $txn_id . "'";
                mysql_query($sql1);
    
    }
    
    ?>
    

    【讨论】:

      猜你喜欢
      • 2012-08-19
      • 2012-01-07
      • 2015-06-16
      • 2016-05-09
      • 2023-03-11
      • 2014-04-24
      • 2012-08-15
      • 2014-08-25
      • 2013-07-10
      相关资源
      最近更新 更多