因此,我已閱讀IPN文檔,並且已經閱讀了大量我找到的示例。我嘗試了幾種不同的解決方案,並且在他們不工作後,I've simply copy and pasted exactly what is documented on the PayPal IPN page.因此,它仍然無法正常工作。我的IPN歷史記錄顯示它正在繼續重新發送消息。下面的代碼 - 缺少什麼?PayPal IPN監聽器不工作
protected void Page_Load(object sender, EventArgs e)
{
const string postUrl = "https://www.paypal.com/cgi-bin/webscr";
var req = (HttpWebRequest)WebRequest.Create(postUrl);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
var param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
var strRequest = Encoding.ASCII.GetString(param);
var ipnPost = strRequest;
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//for proxy
//WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
//req.Proxy = proxy;
//Send the request to PayPal and get the response
var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
// ReSharper disable AssignNullToNotNullAttribute
var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
// ReSharper restore AssignNullToNotNullAttribute
var strResponse = streamIn.ReadToEnd();
streamIn.Close();
// logging ipn messages... be sure that you give write
// permission to process executing this code
//
if (strResponse == "VERIFIED")
{
//check the payment_status is Completed
//check that txn_id has not been previously processed
//check that receiver_email is your Primary PayPal email
//check that payment_amount/payment_currency are correct
//process payment
var mailer = new Emailer();
mailer.SendMail("[email protected]", "[email protected]", "Thank you!",
"Thank you for your sponsorship. Good luck on your results!<br /><br />" + ipnPost);
}
else if (strResponse == "INVALID")
{
//log for manual investigation
}
}
如果您訪問PayPal網站上的IPN模擬器,狀態如何? 「 – Paul
」IPN傳遞失敗,無法連接到指定的URL,請驗證URL並重試。 - 從我讀過的內容來看,這意味着PayPal不喜歡聽衆上的代碼..這很奇怪,看起來就像是他們在示例中給出的代碼... – r584