C# IPN listner使用.NET SDK Paypal?

C# IPN listner使用.NET SDK Paypal?,c#,asp.net-mvc,paypal,sdk,C#,Asp.net Mvc,Paypal,Sdk,我正在与.NETSDK贝宝合作。我不确定SDK是否提供IPN侦听器功能。我试过下面的代码,它总是返回真的,这是正确的方式来IPN验证与否,我试图找到谷歌。但是什么也没找到 var ipn = Request.Form.AllKeys.ToDictionary(k => k, k => Request[k]); var param = Request.BinaryRead(Request.ContentLength); PayPal.IPNMessa

我正在与.NETSDK贝宝合作。我不确定SDK是否提供IPN侦听器功能。我试过下面的代码,它总是返回真的,这是正确的方式来IPN验证与否,我试图找到谷歌。但是什么也没找到

 var ipn = Request.Form.AllKeys.ToDictionary(k => k, k => Request[k]);

        var param = Request.BinaryRead(Request.ContentLength);
        PayPal.IPNMessage iPNMessage = new PayPal.IPNMessage(ipn, param);
        PayPal.IPNMessage service = null;

        try
        {
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig();
            service = new PayPal.IPNMessage(configurationMap, param);
            var response = service.Validate();
        }
        catch (System.Exception ex)
        {
        }

您必须在Paypals站点上使用IPN测试工具,除非您这样做,否则Paypal端没有匹配的事务,因此所有内容都将显示为无效。您当前使用的是沙盒端点,因此它将只验证来自测试人员的请求

对于使用实际付款进行的实时交易,您不使用沙盒端点

 public HttpStatusCodeResult Receive()
    {
        LogRequest(Request);
        Task.Run(() => VerifyTask(Request));
        return new HttpStatusCodeResult(HttpStatusCode.OK);
    }

    private void VerifyTask(HttpRequestBase ipnRequest)
    {
        var verificationResponse = string.Empty;
        try
        {

            var verificationRequest = (HttpWebRequest)WebRequest.Create("https://www.sandbox.paypal.com/cgi-bin/webscr");
            verificationRequest.Method = "POST";
            verificationRequest.ContentType = "application/x-www-form-urlencoded";
            var param = Request.BinaryRead(ipnRequest.ContentLength);
            var strRequest = Encoding.ASCII.GetString(param);
            strRequest = "cmd=_notify-validate&" + strRequest;
            verificationRequest.ContentLength = strRequest.Length;
            var streamOut = new StreamWriter(verificationRequest.GetRequestStream(), Encoding.ASCII);
            streamOut.Write(strRequest);
            streamOut.Close();
            var streamIn = new StreamReader(verificationRequest.GetResponse().GetResponseStream());
            verificationResponse = streamIn.ReadToEnd();
            streamIn.Close();
        }
        catch (Exception exception)
        {
        }
        ProcessVerificationResponse(verificationResponse);
    }