0
{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 沙盒帐户测试该 url 时,它显示以下消息:“IPN 成功发送”。但是当我在服务器上检查我的日志文件时,它会显示来自贝宝沙箱 url 的无效响应。如果没有 VALID 响应,我的其他代码将无法工作。请帮忙!!

4

1 回答 1

0

通过 vb.net 生成 paypal 交易,例如立即购买按钮

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&currency_code=USD&business=" + PaypalBLL.Paypal_Receiver_Email() + "&item_number=" + item_number + "&item_name=" + item_name + "&amount=" + amount + "&quantity=" + quantity + "&undefined_quantity=0&notify_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 将通过 ipn 发送交易事件。

希望您会收到正确的 ipn 响应。

于 2012-04-14T06:09:43.313 回答