我正在尝试基于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¤cy_code=EUR&amount=" + this.textBox1.Text + "&item_name=" + Form1.sendusername + "¬ify_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。
当单击按钮时...沙盒的URL贝宝打开没有问题。
付款已处理并设置为完成。
在按钮和Paypal个人资料中输入了企业沙盒ipn网址。
值是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/