C# C3#Asp.net贝宝IPN

C# C3#Asp.net贝宝IPN,c#,asp.net,paypal,C#,Asp.net,Paypal,我有按钮1作为支付按钮,正在向我的paypal业务帐户发送付款。我遵循这一点,支付发送完美,甚至显示在我的ipn历史。我已将我的IPN通知URL设置为“domain/pay_IPN.aspx”。 该问题验证失败,并且在pay_ipn.aspx页面中始终显示无效 用于存储paypal URL的WebConfig <appSettings> <add key="token" value="PW1BDVNqVPVanwduF_Tb2Ey91aT1Uhx1kL7HPc-7e8S-6An

我有
按钮1
作为支付按钮,正在向我的paypal业务帐户发送付款。我遵循这一点,支付发送完美,甚至显示在我的ipn历史。我已将我的IPN通知URL设置为“domain/pay_IPN.aspx”。 该问题验证失败,并且在
pay_ipn.aspx
页面中始终显示无效

用于存储paypal URL的WebConfig

<appSettings>
<add key="token" value="PW1BDVNqVPVanwduF_Tb2Ey91aT1Uhx1kL7HPc-7e8S-6AnUwSSHyasolSe" />
<add key="paypalemail" value="email@yahoo.com" />
<!--Here i used sandbox site url only if you hosted in live change sandbox to live paypal URL-->
<add key="PayPalSubmitUrl" value="https://www.paypal.com/cgi-bin/webscr" />
<add key="FailedURL" value="domain/dashboard.aspx" />
<add key="SuccessURL" value="domain/dashboard.aspx" />
<add key="NotifyURL" value="domain/pay_ipn.aspx" />
支付

    protected void Page_Load(object sender, EventArgs e)
  {
      //Post back to either sandbox or live
      string strSandbox = "http://sandbox.paypal.com/cgi-bin/webscr";
      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.Current.Request.ContentLength);
      string strRequest = Encoding.ASCII.GetString(param);
      string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
      strRequest += "&cmd=_notify-validate";
      req.ContentLength = strRequest.Length;

      //for proxy
      //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
      //req.Proxy = proxy;
      //Send the request to PayPal and get the response
      StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.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

          // pull the values passed on the initial message from PayPal

          NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
          string user_email = these_argies["payer_email"];
          string pay_stat = these_argies["payment_status"];
          string fName = these_argies["first_name"];
          string itemName = these_argies["item_name"];
          //.
          //.  more args as needed look at the list from paypal IPN doc
          //.
          TextBox1.Text += "Verified: "+pay_stat + Environment.NewLine;

          if (pay_stat.Equals("Completed"))
          {
              TextBox1.Text += "complete";

          }


          // more checks needed here specially your account number and related stuff
      }
      else if (strResponse == "INVALID")
      {
          TextBox1.Text = "INVALID";
          //log for manual investigation
      }
      else
      {
          TextBox1.Text = "error";
          //log response/ipn data for manual investigation
      }
  }

你的问题是…?你必须接近让它工作,因为你得到字符串“无效”。我怀疑http消息中的标头有问题。通常,我建议从两方面着手解决这些问题。首先,使用IE访问站点,查看您的帐户设置是否正确。其次,使用wireshark或fiddler等嗅探器捕获http消息。如果IE正常工作,您可以使用嗅探器比较IE头结果和应用程序结果。获取响应的状态。如果成功的话,应该是200。同时从IE中删除cookie。坏cookie可能会出错。@JCM我如何跟踪付款!这显然是通过发送,但没有显示在支付_ipn@jdweng好的,我看看会出现什么。我可以告诉您,历史记录中显示的IPN详细信息显示了200 http响应代码。我是在发工资吗?不知道。参数应该在嗅探器结果的http头中。
    protected void Page_Load(object sender, EventArgs e)
  {
      //Post back to either sandbox or live
      string strSandbox = "http://sandbox.paypal.com/cgi-bin/webscr";
      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.Current.Request.ContentLength);
      string strRequest = Encoding.ASCII.GetString(param);
      string strResponse_copy = strRequest;  //Save a copy of the initial info sent by PayPal
      strRequest += "&cmd=_notify-validate";
      req.ContentLength = strRequest.Length;

      //for proxy
      //WebProxy proxy = new WebProxy(new Uri("http://url:port#"));
      //req.Proxy = proxy;
      //Send the request to PayPal and get the response
      StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), System.Text.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

          // pull the values passed on the initial message from PayPal

          NameValueCollection these_argies = HttpUtility.ParseQueryString(strResponse_copy);
          string user_email = these_argies["payer_email"];
          string pay_stat = these_argies["payment_status"];
          string fName = these_argies["first_name"];
          string itemName = these_argies["item_name"];
          //.
          //.  more args as needed look at the list from paypal IPN doc
          //.
          TextBox1.Text += "Verified: "+pay_stat + Environment.NewLine;

          if (pay_stat.Equals("Completed"))
          {
              TextBox1.Text += "complete";

          }


          // more checks needed here specially your account number and related stuff
      }
      else if (strResponse == "INVALID")
      {
          TextBox1.Text = "INVALID";
          //log for manual investigation
      }
      else
      {
          TextBox1.Text = "error";
          //log response/ipn data for manual investigation
      }
  }