gpt4 book ai didi

php - paypal iPN mysql 值变化

转载 作者:行者123 更新时间:2023-11-30 01:01:49 25 4
gpt4 key购买 nike

我正在尝试根据 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 表单用户的用户名。用户选择付款金额并将其输入到文本框1中。必须 >= 10。

单击按钮时...沙盒 Paypal 的网址打开没有问题。付款已处理并设置为完成。

业务沙箱 IPN URL 在按钮和 Paypal 配置文件中输入。

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

最佳答案

我找到了解决方案。我制作的 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());

}
?>

关于php - paypal iPN mysql 值变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20055971/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com