【问题标题】:PayPal IPN : IPN was not sent, and the handshake was not verifiedPayPal IPN : IPN 未发送,握手未验证
【发布时间】:2016-05-27 08:50:12
【问题描述】:

我正在使用用 asp.net,c# 编码的 IIS 服务器的 IPN Samulator,但我遇到错误“未发送 IPN,未验证握手。”。我的托管服务器使用纯 http 并且不支持 ssl。我的测试网址是http://realestate.owncircles.com/ipn.aspx

还有代码:

ServicePointManager.Expect100Continue = true;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    // receive PayPal ipn data

    // extract ipn data into a string
    byte[] param = Request.BinaryRead(Request.ContentLength);
    string strRequest = Encoding.ASCII.GetString(param);

    // append PayPal verification code to end of string
    strRequest += "&cmd=_notify-validate";

    // create an HttpRequest channel to perform handshake with PayPal
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(System.Configuration.ConfigurationManager.AppSettings["paypalIPN"].ToString());
    req.Method = "POST";
    req.ContentType = "application/x-www-form-urlencoded";
    req.ContentLength = strRequest.Length;

    // send data back to PayPal to request verification
    StreamWriter streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
    streamOut.Write(strRequest);
    streamOut.Close();

    // receive response from PayPal
    StreamReader streamIn = new StreamReader(req.GetResponse().GetResponseStream());
    string strResponse = streamIn.ReadToEnd();
    streamIn.Close();

    // if PayPal response is successful / verified
    if (strResponse.Equals("VERIFIED"))
    {

    }

【问题讨论】:

标签: c# asp.net paypal-ipn


【解决方案1】:

用这个替换你的代码

//Post back to either sandbox or live 
    string strSandbox = "https://www.sandbox.paypal.com/cgi-bin/webscr";
    string strLive = "https://www.paypal.com/cgi-bin/webscr";
    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(strSandbox);


    //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);
    strRequest = strRequest + "&cmd=_notify-validate";
    req.ContentLength = strRequest.Length;


    //for proxy 
    //var proxy = 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 
    }
}
public vbIPNexample()
{
    Load += Page_Load;
}

【讨论】:

  • 以上是确认条件中的所有代码接受计算。我用你的代码改变了,但同样的问题。
  • 你传入了哪些变量以及如何传入?
  • @Own 当我转到您的链接时,我收到一条错误消息The request was aborted: Could not create SSL/TLS secure channel. ,这是您所看到的吗?
  • 嗨,西蒙,我正在使用来自 paypal 模拟 Windows 的realestate.owncircles.com/ipn.aspx .... 但无法成功。所以我添加了 ServicePointManager.Expect100Continue = true; ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12; ****** 仍然没有成功 :) 所以我用你建议的代码替换了我的可能还是一样的......
猜你喜欢
  • 2016-03-05
  • 2017-01-04
  • 2017-02-17
  • 2016-02-11
  • 2016-01-27
  • 2016-09-27
  • 2015-12-11
  • 2018-05-12
  • 2012-03-09
相关资源
最近更新 更多