0

我尝试从我的 MVC 控制器操作中获取 IPN 消息,但 IPN 无法发送到我的操作控制器

以下是我的控制器操作:

                string strLive = "https://www.paypal.com/cgi-bin/webscr";
                HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);

                //Set values for the request back
                req.Method = "POST";
                req.ContentType = "application/x-www-form-urlencoded";
                byte[] Param = Request.BinaryRead(HttpContext.Request.ContentLength);
                string strRequest = Encoding.ASCII.GetString(Param);
                strRequest = strRequest + "&cmd=_notify-validate";
                req.ContentLength = strRequest.Length;

                //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
                StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
                streamOut.Write(strRequest);
                streamOut.Close();
                StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
                string strResponse = streamIn.ReadToEnd();
                streamIn.Close();

                if (strResponse == "VERIFIED") {
                    //check the payment_status is Completed
                    //check that txn_id has not been previously processed
                    //check that receiver_email is your Primary PayPal email
                    //check that payment_amount/payment_currency are correct
                    //process payment
                } else if (strResponse == "INVALID") {
                    //log for manual investigation
                } else {
                    //Response wasn't VERIFIED or INVALID, log for manual investigation
                }

以下是我使用的贝宝信息:

<add key="paypalAccount"    value="abc@abc.com" />
<add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr"/>
<add key="PDTToken" value="asdfwlfti2Rc_Kskwsdfc7uK26FmT1pdAkhSdLb8FvS2kQ-ZQp6VoF2SqYem"/>
<add key="FromMail" value="myat@abc.com"/>
<add key="return_Url" value="http://testing/Purchase/PayPalResult"/>
<add key="cancel_return" value="http://testing/Purchase/Purchase"/>
<add key="notify_url" value="http://testing/Purchase/PayPalPaymentNotification"/>
<add key="Test_Live" value="live"/>
<add key="BCC" value="myat@abc.com"/>

但是在贝宝中,IPN 消息仍在重试,我没有收到任何我注意到HttpContext.Request.ContentLength始终为 0 并且贝宝的响应状态始终为无效的信息所以请告诉我我该怎么办?

谢谢

4

3 回答 3

1

这是我获取 IPN 消息的全部操作

    public ActionResult PayPalPaymentNotification()
    {
        string strLog = "";
        string currentTime = "";


        currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

        strLog = "Insert into CPLog(Log,LogTime) values('Start IPN request','" + currentTime + "')";
        InsertData(strLog);
        string strLive = "https://www.paypal.com/cgi-bin/webscr";
        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strLive);

        //Set values for the request back
        req.Method = "POST";
        req.ContentType = "application/x-www-form-urlencoded";
        byte[] Param = Request.BinaryRead(HttpContext.Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(Param);
        strRequest = strRequest + "&cmd=_notify-validate";
        req.ContentLength = strRequest.Length;

        //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
        StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
        streamOut.Write(strRequest);
        streamOut.Close();
        StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
        string strResponse = streamIn.ReadToEnd();
        streamIn.Close();

        if (strResponse == "VERIFIED")
        {
            //check the payment_status is Completed
            //check that txn_id has not been previously processed
            //check that receiver_email is your Primary PayPal email
            //check that payment_amount/payment_currency are correct
            //process payment
            currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

            strLog = "Insert into CPLog(Log,LogTime) values('Status - Verified','" + currentTime + "')";
            InsertData(strLog);
        }
        else if (strResponse == "INVALID")
        {
            //log for manual investigation
            currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

            strLog = "Insert into CPLog(Log,LogTime) values('Status - Invalid','" + currentTime + "')";
            InsertData(strLog);
        }
        else
        {
            //Response wasn't VERIFIED or INVALID, log for manual investigation
        }
        currentTime = DateTime.Now.Day.ToString() + "-" + DateTime.Now.Month.ToString() + "-" + DateTime.Now.Year + "|" + DateTime.Now.TimeOfDay.Hours.ToString() + ":" + DateTime.Now.TimeOfDay.Minutes.ToString() + ":" + DateTime.Now.TimeOfDay.Seconds.ToString();

        strLog = "Insert into CPLog(Log,LogTime) values('Finish IPN Request','" + currentTime + "')";
        InsertData(strLog);
        return View();
    }
于 2013-08-13T09:42:46.697 回答
0

您的返回 URL 不正确 - 消息永远无法返回。

[AllowAnonymous]在控制器动作上方添加。

于 2013-08-13T08:44:18.707 回答
0

Paypal 需要知道您的侦听器服务的 URL,该 URL 指示 IPN 需要去哪里。您必须查看您的 Paypal 帐户上的 IPN 通知部分并设置 URL。为此,您可以查看以下部分:Paypal 开发人员并设置通知 URL。

之后,您必须收到付款通知。我的建议是首先使用带有沙盒的Paypal 开发人员部分,这是您可以用来测试此应用程序的虚假帐户之王。

于 2016-02-18T23:37:53.840 回答