简体   繁体   English

PayPal IPN:IPN未发送,并且握手未验证

[英]PayPal IPN : IPN was not sent, and the handshake was not verified

I am using IPN Samulator from IIS server coded in asp.net,c# but I am encountering an error "IPN was not sent, and the handshake was not verified.". 我正在使用ASP.net,c#中编码的IIS服务器使用IPN Samulator,但遇到错误“未发送IPN,并且握手未验证。”。 My hosting server use plain http and not support ssl. 我的托管服务器使用纯http而不支持ssl。 My test url is http://realestate.owncircles.com/ipn.aspx . 我的测试网址是http://realestate.owncircles.com/ipn.aspx

And code : 和代码:

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"))
    {

    }

replace your code with this 用这个替换你的代码

//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;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM