我已經建立了Paypal帳戶通知URL去這個腳本:貝寶IPN失敗
// Read the notification from PayPal which comes in the form of a POST array and create the acknowledgement response
$req = 'cmd=_notify-validate'; // add 'cmd' to beginning of the acknowledgement you send back to PayPal
foreach ($_POST as $key => $value)
{ // Loop through the notification NV pairs
$value = urlencode(stripslashes($value)); // Encode the values
$req .= "&$key=$value"; // Add the NV pairs to the acknowledgement
}
// Assign the paypal payment notification values to local variables
if($_POST){
$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'];}
//Set up the acknowledgement request headers (this is the updated version for http 1.1)
$header .= "POST /cgi-bin/webscr HTTP/1.1\r\n";
$header .= "Content-Type: application/x-www-form-urlencoded\r\n";
$header .= "Host: www.paypal.com\r\n";
$header .= "Connection: close\r\n";
$header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
//Open a socket for the acknowledgement request
$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);
if(!$fp){
echo "HTTP ERROR";
}
else
{//start 1
// Post request back to PayPal for validation
fputs ($fp, $header . $req);
//once paypal receives the acknowledgement response, another message will be send containing the single word VERIFIED or INVALID
while (!feof($fp))
{ //start 2, while not EndOfFile
$res = fgets ($fp, 1024); // Get the acknowledgement response
$res = trim($res);
if (strcmp ($res, "VERIFIED") == 0)
{// start 3, Response is OK
if ($payment_status == "Completed")
{//start 4
//send email announcing success
$from = "Rupert Heath Literary Agency";
$to = $payer_email;
$subject = "Ebook";
$body = "It works";
mail($to, $subject, $body, $from);
}//end 4
}//end 3
else if(strcmp ($res, "INVALID") == 0)
{//start 5
//send email announcing failure
//$error_log .= 'Line 57'
$from = "Guide Test Page";
$to = $payer_email;
$subject = "INVALID IPN";
$body = "Doesn't work";
mail($to, $subject, $body, $from);
}//end 5
} //end 2
fclose ($fp); //close file pointer
} //end 1
這是基於大量的Web託管的例子,迎合升級到HTTP 1.1
該腳本作爲測試,根據PayPal的VERIFIED或INVALID響應發送成功或失敗電子郵件。問題是我總是收到無效的電子郵件,無法理解原因。我查看了PayPal IPN歷史記錄,HTTP響應代碼是200,似乎表明IPN交換正常工作,因此可能PayPal正在響應驗證,但我的腳本有錯誤。
的IPN歷史細節:
即時付款通知(IPN)詳情
消息ID69025489S2598613V
日期/時間created18/07/2013 - 23:22 PDT
原始/了Resent原件
最近的投遞嘗試日期/時間18/07/2013 23:22 PDT
通知URL http://www.rupertheath.com/ipn/ipn_script
HTTP響應代碼200
交貨狀態發送
重試號0
事務ID4D0877596N038120Y
IPN typeTransaction製成
IPN消息 mc_gross = 0.01 & protection_eligibility =合格& address_status =確認& payer_id = C3USV8A4Q2QDW &稅= 0.00 & address_street =拉姆齊房屋34福勒路& PAYMENT_DATE = 23:22:44 2013年7月18日PDT & PAYMENT_STATUS =完成&的charset = Windows的1252 & address_zip = SP1 2QU & FIRST_NAME =邁克爾& mc_fee = 0.01 & address_country_code = GB & ADDRESS_NAME =邁克爾·希思& notify_version = 3.7 &定製= & payer_status =驗證& [email protected] & = ADDRESS_COUNTRY英國& ADDRESS_CITY =索爾茲伯裏&量= 1 & verify_sign = AhKyCHsfiy2frgZNNoQmGHQ3LhKMAboweJqZzYCdqp30Hb7b99tF.04a & [email protected] & txn_id = 4D0877596N038120Y & payment_type =即時&姓氏=希思& ADDRESS_STATE =威爾特& RECEIVER_EMAIL = emailagency @ rupertheath。COM & payment_fee = & receiver_id = BRM2TYMP4ACZ8 & txn_type = web_accept & ITEM_NAME =電子書& mc_currency = GBP & ITEM_NUMBER = & residence_country = GB & handling_amount = 0.00 & transaction_subject =電子書& payment_gross = &運費= 0.00 & ipn_track_id = b0a3b4ae3c51c
任何人都可以幫我調試這個問題嗎?
你從哪裏得到驗證碼? –
貝寶有一個IPN歷史頁面,如果你點擊一個特定的IPN事件,你可以獲得所有這些數據。從數據中看來,貝寶認爲一切正常,所以我懷疑我的劇本,儘管經過了一百遍! – Perkin5