{Following is the vb.net code for IPN listener:
If Me.TestMode = True Then
Me.RequestUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr"
Else
Me.RequestUrl = "https://www.sandbox.paypal.com/cgi-bin/webscr" '"https://www.paypal.com/cgi-bin/webscr"
End If
'====================================Test======================================'
Dim startTime As String = String.Format("{0:MM-dd-yyyy hh:mm:ss:tt}", Now)
'=============================================================================='
Dim req As HttpWebRequest = CType(WebRequest.Create(Me.RequestUrl), HttpWebRequest)
req.Method = "POST"
req.ContentType = "application/x-www-form-urlencoded"
Dim Param() As Byte = HttpContext.Current.Request.BinaryRead(HttpContext.Current.Request.ContentLength)
Dim strRequest As String = Encoding.ASCII.GetString(Param)
strRequest = strRequest & "&cmd=_notify-validate"
req.ContentLength = strRequest.Length
' Dim pairs() As String = strRecieved.Split("&")
Using streamOut As StreamWriter = New StreamWriter(req.GetRequestStream(), Encoding.ASCII)
streamOut.Write(strRequest.ToString)
streamOut.Close()
End Using
Dim streamIn As StreamReader = New StreamReader(req.GetResponse().GetResponseStream())
Dim strResponse As String = streamIn.ReadToEnd()
streamIn.Close()
WriteLog(strResponse)
我已经在vb.net中为paypal IPN监听器完成了代码。当我使用paypal沙盒帐户测试该网址时,它会显示以下消息: “IPN成功发送。” 但是当我在服务器上检查我的日志文件时,它会显示来自paypal沙盒网址的INVALID响应。没有VALID响应我的其他代码将无法正常工作。 请帮忙!!
答案 0 :(得分:0)
生成paypal交易,例如通过vb.net立即购买按钮
Public Shared Function GetPayPalPaymentUrl(item_name As String, item_number As String, amount As String, quantity As String, username As String) As String
Dim strURL As String = "https://www.sandbox.paypal.com/cgi-bin/webscr"
If PaypalBLL.Paypal_Live_Status() = 1 Then
strURL = "https://www.paypal.com/cgi-bin/webscr"
End If
Dim BaseUrl As String = Config.GetUrl()
Dim cancel_url As String = BaseUrl + "paypal/cancel.aspx"
Dim return_url As String = BaseUrl + "paypal/confirmation.aspx"
Dim notifyUrl As String = BaseUrl + "paypal/ipn.aspx"
'string image_url = ""
Dim image_url As String = ""
' paypal header url
Dim paypal_logo As String = HttpUtility.UrlEncode(BaseUrl + "images/logo.png")
Dim Url As New StringBuilder()
Dim CustomFieldValue As String = username
'User-defined field which PayPal passes through the system and returns to you in your merchant payment notification email. Subscribers do not see this field.
Url.Append(strURL + "?cmd=_xclick&upload=1&rm=2&no_shipping=1&no_note=1¤cy_code=USD&business=" + PaypalBLL.Paypal_Receiver_Email() + "&item_number=" + item_number + "&item_name=" + item_name + "&amount=" + amount + "&quantity=" + quantity + "&undefined_quantity=0¬ify_url=" + notifyUrl + "&return=" + return_url + "&cancel_return=" + cancel_url + "&cpp_header_Image=" + image_url + "&cpp_headerback_color=ECDFDF&cpp_headerborder_color=A02626&cpp_payflow_color=ECDFDF&image_url=" + paypal_logo + "&custom=" + CustomFieldValue + "")
Return Url.ToString()
End Function
生成paypal链接,当您点击链接时,您将重定向到paypal沙盒或实时链接。完成交易后,您将被重定向到网站,在后台paypal将通过ipn发送交易事件。
希望您收到正确的ipn响应。