gpt4 book ai didi

php - Paypal 沙箱 IPN 没有更新我的数据库表

转载 作者:太空宇宙 更新时间:2023-11-03 16:03:30 24 4
gpt4 key购买 nike

我使用了 paypal IPN,但是我的数据库中没有任何内容。这是我的按钮(我让它重新出现)和我的代码,有人看到我哪里出错了吗?任何人都可以帮助我解决这个问题

<?php
$conn = mysql_connect('localhost', 'USERNAME', 'PASSWORD');
if(!$conn) { die("Could not connect: ".mysql_error()); }

$database = mysql_select_db('fbkidsonlinedb', $conn);
if(!$database) { die("Can't use database: ".mysql_error()); }


// 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";
}

// If testing on Sandbox use:
$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n";
//$header .= "Host: <!-- w --><a class="postlink" href="http://www.paypal.com:443">www.paypal.com:443</a><!-- w -->\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";

// If testing on Sandbox use:
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
//$fp = fsockopen ('ssl://www.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"];
$user_id = mysql_real_escape_string($_POST["custom"]);

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') {
$txn_id_check = mysql_query("SELECT txn_id FROM log WHERE txn_id =".$txn_id."");
if (mysql_num_rows($txn_id_check) !=1) {
if ($payment_amount=='29.95' && $payment_currency=='USD') {
$log_query = mysql_query("INSERT INTO log VALUES ('', '".$txn_id."', '".$payer_email."')");
$update_premium = mysql_query("UPDATE users SET authLevel='1' where fbID='".$user_id."'");
}
}
}
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick-subscriptions">
<input type="hidden" name="business" value="hiddenForStackQuestion">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="hiddenForStackQuestion">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="hiddenForStackQuestion">
<input type="hidden" name="cancel_return" value="hiddenForStackQuestion">
<input type="hidden" name="src" value="1">
<input type="hidden" name="a3" value="29.95">
<input type="hidden" name="p3" value="1">
<input type="hidden" name="t3" value="Y">
<input type="hidden" name="notify_url" value="hiddenForStackQuestion" />
<input type="hidden" name="custom" value="<?php echo $userId ?>" />
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-SubscriptionsBF:btn_subscribeCC_LG.gif:NonHosted">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_subscribeCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" style="border:none;">
</form>

最佳答案

为什么要为主机分配链接:

$header .= "Host: <!-- w --><a class="postlink" href="http://www.sandbox.paypal.com:443">www.sandbox.paypal.com:443</a><!-- w -->\r\n";

我认为应该是:

$header .= "Host:http://www.sandbox.paypal.com:443\r\n";

反正对PayPal不太熟悉,如果是我的错误,请见谅

关于php - Paypal 沙箱 IPN 没有更新我的数据库表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13930674/

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