我使用直接來自documentation的IPN示例。IPN帖子每次都是空的
我付款給PayPal沒有問題,貝寶重定向到我的聽衆沒有問題,但總是提出一個空的$ _POST變量。任何人都可以看到問題嗎?
<?php
// Send an empty HTTP 200 OK response to acknowledge receipt of the notification
header('HTTP/1.1 200 OK');
// Assign payment notification values 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'];
// Build the required acknowledgement message out of the notification just received
$req = 'cmd=_notify-validate'; // Add 'cmd=_notify-validate' to beginning of the acknowledgement
echo '<pre>';
var_dump($_POST);
echo '</pre><hr/>';
foreach ($_POST as $key => $value) { // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode these values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}
// Set up the acknowledgement request headers
$header = "POST /cgi-bin/webscr HTTP/1.1\r\n"; // HTTP POST request
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
// Open a socket for the acknowledgement request
$fp = fsockopen('ssl://www.paypal.com', 443, $errno, $errstr, 30);
// Send the HTTP POST request back to PayPal for validation
fputs($fp, $header . $req);
while (!feof($fp)) { // While not EOF
$res = fgets($fp, 1024); // Get the acknowledgement response
if (strcmp ($res, "VERIFIED") == 0) { // Response contains VERIFIED - process notification
// Authentication protocol is complete - OK to process notification contents
echo 'thanks for the payment, we are processing your request.';
} else if (strcmp ($res, "INVALID") == 0) {
//Response contains INVALID - reject notification
echo 'something has gone wrong. please try again.';
}
}
fclose($fp); // Close the file
?>
結果:
array(0) {
}
something has gone wrong. please try again.
更新,增加了按鈕的代碼:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="upload" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="business" value="H7G2W8WN4XXXXX">
<input type="hidden" name="item_name_1" value="Item Name">
<input type="hidden" name="amount_1" value="0.25">
<input type="hidden" name="item_name_2" value="Item Name 2">
<input type="hidden" name="amount_2" value="0.25">
<input type="submit" value="Buy Now"/>
</form>
你可以發佈你的按鈕代碼嗎? – Eshan 2014-09-09 19:22:47
@Eshan它現在包括在內。 – 2014-09-09 20:21:21
您是否嘗試過使用[IPN Simulator](https://developer.paypal.com/webapps/developer/applications/ipn_simulator)發送測試請求?我只是用一個簡單的2行腳本(返回頭文件並將$ _POST轉儲到文件)來完成這個工作,並且它按預期工作。 – timclutton 2014-09-09 20:37:35