gpt4 book ai didi

asp.net-mvc-3 - Paypal IPN状态总是无效?

转载 作者:太空宇宙 更新时间:2023-11-03 16:18:57 25 4
gpt4 key购买 nike

我从 IPN 收到无效响应,有些人提到返回 URL 和通知 URL 不应该相同,但我以这种方式进行了更改,甚至得到了相同的结果。这是我的付款代码,付款正常。

 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+"&currency_code="+paypal.currency_code+"&item_name="+ paypal.item_name+"&amount="+ paypal.amount;

但是我猜不出 Paypal 帐户中以下代码或配置的问题。最有可能使用 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";
}

如果有人帮助我,我将不胜感激。

最佳答案

“INVALID” 消息是由于以下原因造成的:
- 检查您是否将您的回复发布到正确的 URL,即 https://www.sandbox.paypal.com/cgi-bin/webscrhttps://www.paypal.com/cgi-bin/webscr ,分别取决于您是在沙盒中测试还是在现场。
- 确认您对测试 IPN 消息的响应包含与测试消息完全相同的变量和值,并且它们的顺序与测试消息中的顺序相同。最后,验证原始变量前面是否有 cmd=_notify-validate 变量。
- 确保您正在编码您的响应字符串并使用与测试 IPN 消息所用的相同字符编码。 (例如,我可以看到他正在使用带有变音符号和其他符号(如“/”等)的字母)。

关于最后一点,商家可以尝试更改其PayPal账户中使用的编码语言,步骤如下:

  1. 登录您的 PayPal 帐户
  2. 点击个人资料
  3. 点击“我的销售偏好”标签
  4. 点击“PayPal Button Language Encoding”(在页面末尾)
  5. 点击“其他选项”
  6. 从下拉菜单中选择:UTF-8
  7. 第二个选项也选择相同的字符集,与IPN相关
  8. 点击“保存”

如果问题仍然存在,我们建议检查正在使用的脚本,PayPal 在以下位置提供了一些 IPN 代码示例:https://github.com/paypal/ipn-code-samples

有关更多信息,我提供了链接:https://developer.paypal.com/webapps/developer/docs/classic/ipn/integration-guide/IPNTesting/#id091GFE00WY4

关于asp.net-mvc-3 - Paypal IPN状态总是无效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20607219/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com