2

我的 IPN 列表器无法正常工作。当我尝试使用 IPN 列表器时,错误显示如下“抱歉,我们无法发送 IPN。” 但我可以从浏览器访问 IPN 处理程序 url。

这是我的 IPN 处理程序代码。

  public ActionResult IPN()
    {
        LogMessage ("entering ipn action ");
        var formVals = new Dictionary<string, string>();
        formVals.Add("cmd", "_notify-validate");

        string response = GetPayPalResponse(formVals, true);
        LogMessage ("IPN Response received: " + response + " <-- That was response. . . ");

        if (response == "VALID")
        {
            LogMessage("Response Was Verified");
        }

        else
        {
            LogMessage("RESPONSE WAS NOT VERIFIED");
        }

        return Json("Sucess",JsonRequestBehavior.AllowGet);
    }

 string GetPayPalResponse(Dictionary<string, string> formVals, bool useSandbox)
    {
        string paypalUrl = useSandbox
                                ? "https://www.sandbox.paypal.com/cgi-bin/webscr"
                                : "https://www.paypal.com/cgi-bin/webscr";

        HttpWebRequest req = (HttpWebRequest)WebRequest.Create(paypalUrl);

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

        byte[] param = Request.BinaryRead(Request.ContentLength);
        string strRequest = Encoding.ASCII.GetString(param);

        StringBuilder sb = new StringBuilder();
        sb.Append(strRequest);

        foreach (string key in formVals.Keys)
        {
            sb.AppendFormat("&{0}={1}", key, formVals[key]);
        }
        strRequest += sb.ToString();
        req.ContentLength = strRequest.Length;

        string response = "";
        using (StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.Encoding.ASCII))
        {
            streamOut.Write(strRequest);
            streamOut.Close();
            using (StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream()))
            {
                response = streamIn.ReadToEnd();
            }
        }
        return response;
    }
4

1 回答 1

1

我们之前遇到过同样的问题,我觉得这可能是因为您的 MVC 应用程序可能是在共享主机环境中发布的然后您必须按照一些步骤来使 MVC RC 应用程序工作这里是帮助我解决问题的博客。请检查这个

http://helpnshareidea.blogspot.in/2013/11/mvc3-applications-in-windows-shared.html

于 2013-11-11T15:35:17.210 回答