我在我的帳戶上安裝了IPN,它似乎在IPN模擬器上工作,但是在沙盒模式下測試時,它不工作。 這是我的代碼,我有什麼問題嗎?PayPal在沙盒模式下的IPN
<?php
$req = 'cmd=_notify-validate';
foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}
//Set up the acknowledgement request headers
$header .= "POST /cgi-bin/webscr HTTP/1.0\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.sandbox.paypal.com\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//Open a socket for the acknowledgement request
$fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
// 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 is VERIFIED
// Send an email announcing the IPN message is VERIFIED
$mail_From = "[email protected]";
$mail_To = "[email protected]";
$mail_Subject = "VERIFIED IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
else if (strcmp ($res, "INVALID") == 0) { // Response is INVALID
// Notification protocol is NOT complete, begin error handling
// Send an email announcing the IPN message is INVALID
$mail_From = "[email protected]";
$mail_To = "[email protected]";
$mail_Subject = "INVALID IPN";
$mail_Body = $req;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
}
}
fclose ($fp);
?>
難道我有錯的代碼或者是一個問題,從貝寶的東西嗎?我怎麼解決這個問題?
在另一方面,我的帳戶已通過驗證與PayPal
您是否檢查過您的賬戶並查看了IPN日誌以確保IPN正在從您的賬戶中發出?這也會告訴你,如果你的網站正在返回200OK響應以外的東西。 –
花費了幾個小時的樣本代碼後,即使是來自PayPal自己的樣本代碼,上面的代碼片段也成功通過了我的測試。 – HenryW