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 已损坏。
我很困惑我需要做些什么来修复它。我添加了这段代码,监听器页面再次加载而没有错误。
1 2 3 4 5 6 | ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3; ServicePointManager.ServerCertificateValidationCallback = delegate { return true; }; |
但是当我尝试测试交易时,侦听器永远不会从 PayPal 收到任何东西。这是因为监听器的服务器现在必须是"https"吗?
PP 沙盒现在是否拒绝通知非 SSL 地址?
我的 c# 代码最初来自一个 PayPal 示例,但它不再在他们的网站上。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | 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 侦听器。
我只是想分享我正在运行的代码...希望它可以帮助您对您的代码进行一些改进:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | 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"