Asp.net mvc 4 Paypal IPN无法发送到我的MVC 4控制器操作
我试图从我的MVC控制器操作获取IPN消息,但IPN无法发送到我的操作控制器 以下是我的控制器操作:Asp.net mvc 4 Paypal IPN无法发送到我的MVC 4控制器操作,asp.net-mvc-4,paypal,Asp.net Mvc 4,Paypal,我试图从我的MVC控制器操作获取IPN消息,但IPN无法发送到我的操作控制器 以下是我的控制器操作: string strLive = "https://www.paypal.com/cgi-bin/webscr"; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive); //Set values for the reques
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] Param = Request.BinaryRead(HttpContext.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(Param);
strRequest = strRequest + "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//for proxy
//Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
//req.Proxy = proxy
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
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
} else if (strResponse == "INVALID") {
//log for manual investigation
} else {
//Response wasn't VERIFIED or INVALID, log for manual investigation
}
以下是我使用的paypal信息:
<add key="paypalAccount" value="abc@abc.com" />
<add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr"/>
<add key="PDTToken" value="asdfwlfti2Rc_Kskwsdfc7uK26FmT1pdAkhSdLb8FvS2kQ-ZQp6VoF2SqYem"/>
<add key="FromMail" value="myat@abc.com"/>
<add key="return_Url" value="http://testing/Purchase/PayPalResult"/>
<add key="cancel_return" value="http://testing/Purchase/Purchase"/>
<add key="notify_url" value="http://testing/Purchase/PayPalPaymentNotification"/>
<add key="Test_Live" value="live"/>
<add key="BCC" value="myat@abc.com"/>
但在贝宝IPN消息仍在重试,我并没有收到任何东西
我注意到HttpContext.Request.ContentLength始终为0,paypal的响应状态始终无效
所以请告诉我该怎么做
谢谢您返回的URL不正确-邮件永远无法返回
在控制器操作上方添加
[AllowAnonymous]
。这是我获取IPN消息的全部操作
public ActionResult PayPalPaymentNotification()
{
string strLog = "";
string currentTime = "";
currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();
strLog = "Insert into CPLog(Log,LogTime) values('Start IPN request','" + currentTime + "')";
InsertData(strLog);
string strLive = "https://www.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);
//Set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] Param = Request.BinaryRead(HttpContext.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(Param);
strRequest = strRequest + "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
//for proxy
//Dim proxy As New WebProxy(New System.Uri("http://url:port#"))
//req.Proxy = proxy
//Send the request to PayPal and get the response
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
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
currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();
strLog = "Insert into CPLog(Log,LogTime) values('Status - Verified','" + currentTime + "')";
InsertData(strLog);
}
else if (strResponse == "INVALID")
{
//log for manual investigation
currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();
strLog = "Insert into CPLog(Log,LogTime) values('Status - Invalid','" + currentTime + "')";
InsertData(strLog);
}
else
{
//Response wasn't VERIFIED or INVALID, log for manual investigation
}
currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();
strLog = "Insert into CPLog(Log,LogTime) values('Finish IPN Request','" + currentTime + "')";
InsertData(strLog);
return View();
}
Paypal需要知道您的侦听器服务的URL,该URL指示IPN需要去哪里。您必须查看Paypal帐户上的IPN通知部分并设置URL。 为此,您可以查看以下部分:并设置通知URL 之后,您必须收到付款通知。
我的建议是首先使用with Sandbox,它是可以用来测试此应用程序的伪造帐户之王。请添加您的控制器签名。我是MVC新手,请告知什么是控制器签名?没问题-控制器方法名称和参数…是的,我输入了真正的URL,我已经在浏览器中测试过了。感谢您的回复。您是否希望Paypal返回此url-?不,我只是更改了我的真实url,这是我的真实url。我刚刚检查了它,并被重新指定为登录名-控制器应允许匿名访问。您是否在控制器操作上获得了[AllowAnonymous]权限?