贝宝 IPN https 更改 2016

PayPal IPN https changes 2016

今天从 PayPal 收到的信息:

IPN 验证回发到 HTTPS

If you are using PayPal’s Instant Payment Notification (IPN) service, you will >need to ensure that HTTPS is used when posting the message back to PayPal for >verification. After Sept 30, 2016 HTTP postbacks will no longer be supported.

我正在使用 IPN,实时站点正在运行,但我们使用沙箱的 DEV IPN 侦听器已损坏:https://www.sandbox.paypal.com/cgi-bin/webscr

我很困惑我需要做什么来修复它。我添加了这段代码,监听器页面再次加载没有错误。

ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                | SecurityProtocolType.Tls11
                | SecurityProtocolType.Tls12
                | SecurityProtocolType.Ssl3;

            ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };

但是当我尝试测试交易时,侦听器从未收到来自 PayPal 的任何信息。这是因为监听器的服务器现在必须是 "https" 吗? PP沙箱现在拒绝通知非SSL地址吗?

我的 C# 代码最初来自 PayPal 示例,但它不再出现在他们的网站上。

var useSandbox = Convert.ToBoolean(ConfigurationManager.AppSettings["UsePayPalSandboxYn"]);
var server = useSandbox ? "https://www.sandbox.paypal.com/cgi-bin/webscr" : "https://www.paypal.com/cgi-bin/webscr";

var req = (HttpWebRequest)WebRequest.Create(server);

// set values for the request back
req.Method = "POST";
req.ContentType = "application/x-www-form-urlencoded";

//added today
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls
                | SecurityProtocolType.Tls11
                | SecurityProtocolType.Tls12
                | SecurityProtocolType.Ssl3;

ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


byte[] param = Request.BinaryRead(HttpContext.Current.Request.ContentLength);
var strRequest = Encoding.ASCII.GetString(param);
strRequest += "&cmd=_notify-validate";
req.ContentLength = strRequest.Length;

// send the request to PayPal and get the response
var streamOut = new StreamWriter(req.GetRequestStream(), Encoding.ASCII);
streamOut.Write(strRequest);
streamOut.Close();
var streamIn = new StreamReader(req.GetResponse().GetResponseStream());
string strResponse = streamIn.ReadToEnd();
streamIn.Close();

switch (strResponse)
{
case "VERIFIED":
                {

我使用静态 IP 地址和设置为 Web 服务器的家庭路由器进行调试。如果我必须设置ssl,那就更难了。

谁能给我指出正确的方向?

您唯一需要做的就是确保将验证 POST 发送回 PayPal 到 https:// 而不是 http://。您不必在您的网站上安装 SSL 即可让您的 IPN 侦听器 运行 开启。

我只是想分享我正在运行的代码...希望它可以帮助您对代码进行一些改进:

private void VerifyTask(HttpRequestBase ipnRequest, bool useLiveAccount = true)
{
            string verificationResponse = string.Empty;
            var request = (HttpWebRequest)WebRequest.Create(useLiveAccount
                ? WebConfigurationManager.AppSettings["PaypalURL"] 
                : WebConfigurationManager.AppSettings["SandboxURL"]);

            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            var param = ipnRequest.BinaryRead(ipnRequest.ContentLength);
            var strRequest = Encoding.ASCII.GetString(param);
            strRequest += "&cmd=_notify-validate";
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;

            using (var writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII))
            {
                writer.Write(strRequest);
                writer.Close();
            }

            using (var reader = new StreamReader(request.GetResponse().GetResponseStream()))
            {
                verificationResponse = reader.ReadToEnd();
                reader.Close();
            }

            if (verificationResponse.Equals("VERIFIED"))
            {
               //Make the validations here
            }
}

编辑: WebConfigurationManager.AppSettings["PaypalURL"] = "https://www.paypal.com/cgi-bin/webscr" WebConfigurationManager.AppSettings["SandboxURL"] = "https://www.sandbox.paypal.com/cgi-bin/webscr"