0
這是我第一次處理貝寶IPN。我瀏覽過網頁獲得了一些幫助,並且遇到了以下代碼。我花了一段時間,它總是返回無效。我想知道,但這也可能與我在Paypal上選擇的設置有關嗎?我所有啓用的是IPN和重定向。PHP - 貝寶IPN總是返回無效
<?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.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);
//handle 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) {
echo $errstr.' ('.$errno.').<br />';
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {
echo "Verified";
if(strcmp($payment_status, 'Completed') == 0) {
if(strcmp($payment_currency, 'USD') == 0) {
//process data
}
}
} elseif(strcmp ($res, "INVALID") == 0) {
echo "Invalid";
}
}
fclose ($fp);
}
?>
好吧。我發現這一點:http://pastebin.com/vRYmPDGD - 不要發送電子郵件,但(又名從來都是有效的,總是無效) – George