我已经尝试过很多这个问题的解决方案,但是真的找不到。我复制了很多这样的例子,但都没有。在这里,我知道有效,因为我的朋友在他的网站上使用它没有错误。
我在这里知道的IPN,正如朋友送给我的那样,并收到了他的IPN信息。
我检查了我的HTTP访问日志,PayPal从不接触我的服务器发布数据。在PayPal IPN历史记录页面上,它显示付款的“重试”。
我的IPN和按钮代码如下。
<?php
include("inc/er.php");
include("inc/database.php");
include("inc/functions.php");
require("inc/ipn.config.php");
$req = 'cmd=_notify-validate';
// post back to PayPal system to validate //
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
if (!$fp) {
//email
$mail_From = "From: IPN@tester.com";
$mail_To = $email;
$mail_Subject = "HTTP ERROR";
$mail_Body = $errstr;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
else
{
$ids = explode("|", $_POST['custom']);
$item_username = $ids[0];
$item_userid = $ids[1];
$item_email = $ids[2];
$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'];
$txnId = $_POST['txn_id'];
$receiverEmail = $_POST['receiver_email'];
$payerEmail = $_POST['payer_email'];
$price = 4;
$payment_amount = str_replace('.00', '', $payment_amount);
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
$res = trim($res);
if (strcmp($res, "VERIFIED")==0) {
addPaypalPayment($item_name, $item_number, $item_username, $item_userid, $item_email, $payment_status, $payment_amount, $payment_currency, $txnId, $receiver_email, $payer_email, '1');
serviceAdd($item_userid, $item_number, getNumServices($item_userid));
setServiceActive($item_userid, $item_packageid);
sendEmailWithUsername("Carwash", "PayPal IPN", "Success!");
sendEmailWithUsername($_SESSION["username"], "Your new VPN purchase", "You can gain access to your new VPN account by visiting <a href='https://bvpn.biz/manage.php?do=activate'>this</a> link.");
}
else if (strcmp($res, "INVALID")==0) {
$mail_To = $email;
$mail_Subject = "PayPal - Invalid IPN ";
$mail_Body = "We have had an INVALID response. \n\nThe transaction ID number is: $txn_id \n\n username = $username";
mail($mail_To, $mail_Subject, $mail_Body);
}
} //end of while
fclose ($fp);
}
?>
按钮
<form action="https://<?php echo $url; ?>/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick"/>
<input type="hidden" name="business" value="<?php echo $email; ?>"/>
<input type="hidden" name="item_name" value="<?php echo $pname; ?>"/>
<input type="hidden" name="item_number" value="<?php echo $id; ?>"/>
<input type="hidden" name="amount" value="<?php echo $prices[$id - 1] . ".00"; ?>"/>
<input type="hidden" name="quantity" value="1"/>
<input type="hidden" name="no_note" value="1"/>
<input type="hidden" name="currency_code" value="USD"/>
<input type="hidden" name="lc" value="US"/>
<input type="hidden" name="bn" value="PP-BuyNowBF"/>
<input type="hidden" name="return"
value="https://bvpn.biz/success.php?id=<?php echo $id; ?>&met=<?php echo $met; ?>"/>
<input type="hidden" name="cancel_return"
value="https://bvpn.biz/success.php?id=<?php echo $id; ?>&met=<?php echo $met; ?>&do=2"/>
<input type="hidden" name="notify_url" value="https://bvpn.biz/ipn.php"/>
<input type="hidden" name="custom" value="<?php echo $_SESSION['username'].'|'.getUserId($_SESSION["username"]).'|'.getUserEmail($_SESSION["username"]); ?>"/>
<div style="padding-top:100px; padding-right: 40%; padding-left: 40%;">
<center><input type="submit" name="submit" class="btn" value="Checkout with PayPal"></center>
</div>
</form>
答案 0 :(得分:0)
一个可能的原因是您的回发标题已过期。
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
现在应该阅读:
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host:www.sandbox.paypal.com\r\n";
$header .= "Connection:close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
Paypal已停止支持HTTP1.0
希望这有帮助