问题概述:
我已经实现了 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 :)