IPN未发送,握手未经验证。

时间:2017-03-07 10:03:10

标签: c# paypal-ipn

Paypal已将其沙盒IPN模拟器网址从https://sandbox.paypal.com/cgi-bin/webscr更改为https://ipnpb.sandbox.paypal.com/cgi-bin/webscr

但是我一直收到以下错误:

  

未发送IPN,并且未验证握手。请查看您的信息。

我的代码:

    //Post back to either sandbox or live
    string strSandbox = "https://ipnpb.sandbox.paypal.com/cgi-bin/webscr";
    // string strLive = "https://ipnpb.paypal.com/cgi-bin/webscr";
    //   System.Net.ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12;
    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
    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 += "&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
    //string Item_Name = Request["item_name"];
    //string item_number = Request["item_name"];
    //string Item_Name = Request["item_name"];
    //string Item_Name = Request["item_name"];
    //string Item_Name = Request["item_name"];
    //string Item_Name = Request["item_name"];
    //string Item_Name = Request["item_name"];
    //string Item_Name = Request["item_name"];

    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")
    {
        string InsertStatement = "insert into Trial(testData,reseller_id,Transaction_no)values('" + strResponse + "',1,1)";
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
        SqlCommand cmd = new SqlCommand(InsertStatement, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
        //process payment
    }
    else if (strResponse == "INVALID")
    {
        string InsertStatement = "insert into Trial(testData,reseller_id,Transaction_no)values('" + strResponse + "',1,2)";
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
        SqlCommand cmd = new SqlCommand(InsertStatement, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
    }
    else
    {
        string InsertStatement = "insert into Trial(testData,reseller_id,Transaction_no)values('Nothing ',1,2)";
        SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"].ToString());
        SqlCommand cmd = new SqlCommand(InsertStatement, conn);
        conn.Open();
        cmd.ExecuteNonQuery();
 }
}

0 个答案:

没有答案
相关问题