PayPal IPN 通知验证正在返回 ASP.NET 的沙盒登录 HTML

Posted

技术标签:

【中文标题】PayPal IPN 通知验证正在返回 ASP.NET 的沙盒登录 HTML【英文标题】:PayPal IPN notify-validate is returning sandbox login HTML for ASP.NET 【发布时间】:2012-10-28 13:18:26 【问题描述】:

问题概述:

我已经实现了 IPN 侦听器,并且我知道 PayPal 正在指向它(因为生成的文本文件),正确的参数会在 QueryString 中发送给我,但是当我将“&cmd=notify-validate”附加到进行验证的查询字符串并将其发送到 PayPal,我得到以下 html 响应:

当我将返回的 HTML 复制并粘贴到空白 HTML 文档中时,我看到以下内容:

最初我以为我的会话已经过期,但是当我通过浏览器访问沙盒时,我自动登录了。我什至尝试单击我的 html 文档中的链接以确保我已登录并尝试处理另一个测试 IPN通过沙箱中的模拟器,但我不断得到这个结果。我只是看不出我做错了什么,可悲的是大约一个小时前它工作正常:(

用于发送和获取验证响应的 IPN 侦听器代码:

    Dim payPalUrl As String = PayPalPayment.PayPalURL 'This returns https://www.sandbox.paypal.com/cgi-bin/webscr
    Dim req As HttpWebRequest = CType(WebRequest.Create(payPalUrl), HttpWebRequest)

    'Set values for the request back
    req.Method = "POST"
    req.ContentType = "application/x-www-form-urlencoded"

    Dim params() As Byte = Request.BinaryRead(Request.ContentLength)
    Dim ipnRequest As String = Encoding.ASCII.GetString(params)
    Dim ipnPost As String = ipnRequest
    ipnRequest &= "&cmd=notify-validate"
    req.ContentLength = ipnRequest.Length

    myUtility.AuditIPN(filename, ipnRequest)

    ''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
    Dim streamOut As New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
    streamOut.Write(ipnRequest)
    streamOut.Close()

    Dim streamIn As New StreamReader(req.GetResponse().GetResponseStream())
    Dim ipnResponse = streamIn.ReadToEnd()
    streamIn.Close()

    'Rest of the code here... not necessary for this problem

将付款过帐到 PayPal(如果需要)。注意:我在页面中构建表单和 Response.Write()。这是表单生成:

    Dim form As New StringBuilder
    form.AppendLine("<!DOCTYPE html>")
    form.AppendLine("<html xmlns=""http://www.w3.org/1999/xhtml"">")
    form.AppendLine("<head runat=""server"">")
    form.AppendLine(String.Format("<title>0 1</title>", "PayPal payment for", ItemName))
    form.AppendLine("<link href=""../css/paypal.css"" rel=""stylesheet"" />")
    form.AppendLine("</head>")
    form.AppendLine("<body>")
    form.AppendLine("<div class=""paypal""></div>")
    form.AppendLine(String.Format("<p>Accessing PayPal to process your payment for the 0.</p>", ItemName))
    form.AppendLine("<div class=""loading""></div>")
    form.AppendLine("<form id=""myform"" action=""https://www.sandbox.paypal.com/cgi-bin/webscr"" method=""post"">")
    form.AppendLine("<input type=""hidden"" name=""cmd"" value=""_xclick"">")
    form.AppendLine(String.Format("<input type=""hidden"" name=""business"" value=""0"">", BusinessEmail))
    form.AppendLine(String.Format("<input type=""hidden"" name=""item_name"" value=""0"">", ItemName))
    form.AppendLine(String.Format("<input type=""hidden"" name=""amount"" value=""0"">", Amount))
    form.AppendLine(String.Format("<input type=""hidden"" name=""currency_code"" value=""0"">", Currency))
    form.AppendLine(String.Format("<input type=""hidden"" name=""return"" value=""0"">", ReturnURL))
    form.AppendLine("<input type=""hidden"" name=""button_subtype"" value=""products"">")
    form.AppendLine("<input type=""hidden"" name=""bn"" value=""HHMRKWQT8NRTW:PP-BuyNowBF_P"">")
    form.AppendLine("<input type=""hidden"" name=""no_note"" value=""0"">")
    form.AppendLine("</form>")
    form.AppendLine("<script type=""text/javascript"">")
    form.AppendLine("    document.forms[""myform""].submit();")
    form.AppendLine("</script>")
    return form.ToString()

如果我需要发布有关此问题的任何其他内容,请告诉我,因为我的大脑此刻完全被炒了。

我们将不胜感激您的时间和帮助!

注意:虽然我的代码是用 VB.NET 开发的,但我也是用 C# 开发的,所以 C# 示例代码绝对不会被讨厌!

答案:

如果您收到 HTML 作为回报,则 notify-validate 未正确发送到 PayPal。它需要是 &cmd=_notify-validate (下划线直接在 cmd 键之后)我必须以某种方式在我朦胧的昏迷中以某种方式将其删除。我的 IPN 监听器现在成功返回 VERIFIED :)

【问题讨论】:

【参考方案1】:

如果您收到 HTML 作为回报,则 notify-validate 未正确发送到 PayPal。它需要是 &cmd=_notify-validate (下划线直接在 cmd 键之后)我一定是在我朦胧的昏迷中不小心删除了它。我的 IPN 监听器现在成功返回 VERIFIED :)

【讨论】:

这样一个简单的错误,但我也这样做了。感谢您发布答案,现在这个周末我可以睡觉了! 这里的游戏有点晚,但重要的是要注意这必须是第一个参数,并且您需要在末尾使用 & 分隔符,以便您拥有 &cmd=_notify-validate&

以上是关于PayPal IPN 通知验证正在返回 ASP.NET 的沙盒登录 HTML的主要内容,如果未能解决你的问题,请参考以下文章

nodejs - 无法让 paypal-ipn 工作。 Paypal 不断返回“无效”

Paypal 沙盒 IPN 返回无效

Paypal IPN 获得空白确认(应为“已验证”或“无效”)

(Laravel)无法从PayPal IPN获得响应,但模拟的响应返回已经过验证

Paypal IPN:证书验证失败

Paypal 会每月发送定期付款 IPN 通知吗