Asp.net mvc 3 Paypal IPN状态始终无效?
我收到来自IPN的无效响应,一些人提到的返回url和通知url不应该是相同的,但我以这种方式更改了,甚至得到了相同的结果。 这是我的付款代码,付款正常Asp.net mvc 3 Paypal IPN状态始终无效?,asp.net-mvc-3,paypal,Asp.net Mvc 3,Paypal,我收到来自IPN的无效响应,一些人提到的返回url和通知url不应该是相同的,但我以这种方式更改了,甚至得到了相同的结果。 这是我的付款代码,付款正常 Paypal paypal = new Paypal(); paypal.cmd = "_xclick"; paypal.business = ConfigurationManager.AppSettings["BusinessAccountKey"]; bool useS
Paypal paypal = new Paypal();
paypal.cmd = "_xclick";
paypal.business = ConfigurationManager.AppSettings["BusinessAccountKey"];
bool useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UseSandbox"]);
paypal.cancel_return = "http://www.patronalerts.com/";
//paypal.@return = ConfigurationManager.AppSettings["ReturnURL"];
paypal.@return = "http://www.patronalerts.com/";
paypal.notify_url = ConfigurationManager.AppSettings["NotifyURL"];
paypal.currency_code = ConfigurationManager.AppSettings["CurrencyCode"];
paypal.item_name = "Test Product";
paypal.amount = "10";
url = "https://www.sandbox.paypal.com/cgi-bin/webscr?cmd="+paypal.cmd +"&business="+ paypal.business+"&no_shipping=&return="+paypal.@return+"&cancel_return="+paypal.cancel_return+"¤cy_code="+paypal.currency_code+"&item_name="+ paypal.item_name+"&amount="+ paypal.amount;
但我猜不出贝宝账户中的以下代码或配置有什么问题。很可能是paypal配置,因为每个人都使用此代码
string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";
byte[] param = Request.BinaryRead(System.Web.HttpContext.Current.Request.ContentLength);
string strRequest = Encoding.ASCII.GetString(param);
string strResponse_copy = strRequest; //Save a copy of the initial info sent by PayPal
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;
StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();
if (strResponse == "VERIFIED")
{
NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
string user_email = these_argies["payer_email"];
string pay_stat = these_argies["payment_status"];
if (pay_stat.Equals("Completed"))
{
ViewBag.Result = "Kishore Suceess";
}
}
else if (strResponse == "INVALID")
{
ViewBag.Result = "invalids";
}
else
{
ViewBag.Result = "Ipn data for manual investigation";
}
如果有人愿意帮助我,我将不胜感激。一条“无效”的消息是由于以下原因造成的:
-检查您的是否将您的响应发布到正确的URL,这取决于您是在沙箱中测试还是在现场测试。
-验证您对测试IPN消息的响应是否包含与测试消息完全相同的变量和值,以及它们的顺序是否与测试消息中的顺序相同。最后,验证原始变量前面是否有cmd=\u notify-validate变量。
-确保您正在对响应字符串进行编码,并且使用与测试IPN消息相同的字符编码。(例如,我可以看到他正在使用带有umlaut的字母和其他符号,如“/”等) 关于最后一点,商户可以尝试按照以下步骤更改其PayPal帐户中使用的编码语言:
关于其他信息,我添加了链接:Am using sandbox account,我提到了这个url,也提到了一个不是问题的sandbox url。我已经将这些字符集设置为UTF-8。仍然收到相同的响应“Invalid”。我检查了您共享的示例代码段,这些代码段是相同的。您是在本地计算机上还是在公共IIS服务器上进行测试?您必须在必须启用https的公用IIS服务器上托管应用程序。