【问题标题】:setExpressCheckout and SSL/TLS errorsetExpressCheckout 和 SSL/TLS 错误
【发布时间】:2012-09-22 18:23:16
【问题描述】:

我正在尝试开发一个简单的应用程序,使用户能够通过 Paypal API 从网站购买服务。此应用程序使用 C# 在 ASP.NET 上运行。

我在尝试让 Paypal API 进行合作时运气不佳。我调用的方法是带有所有适当变量的 SetExpressCheckout。

我进行了研究,发现由于我在 Localhost 中进行测试,它可能会影响 Paypal 与应用程序通信的能力。所以接下来我尝试通过一个开放端口和一个可公开访问的 IP 地址访问我的应用程序,但在调用 SetExpressCheckout 时会出现同样的错误。

这是错误:

Exception Details: System.Net.WebException: The request was aborted: Could not create SSL/TLS secure channel.

Source Error: 


Line 1790:        [return: System.Xml.Serialization.XmlElementAttribute("SetExpressCheckoutResponse", Namespace="urn:ebay:api:PayPalAPI")]
Line 1791:        public SetExpressCheckoutResponseType SetExpressCheckout([System.Xml.Serialization.XmlElementAttribute(Namespace="urn:ebay:api:PayPalAPI")] SetExpressCheckoutReq SetExpressCheckoutReq) {
Line 1792:            object[] results = this.Invoke("SetExpressCheckout", new object[] {
Line 1793:                        SetExpressCheckoutReq});
Line 1794:            return ((SetExpressCheckoutResponseType)(results[0]));

Source File: c:\WINDOWS\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\anan_p2\730602d6\31a8d74e\App_WebReferences.c8vgyrf8.2.cs    Line: 1792 

我也尝试过使用 OpenSSL 生成证书并将其上传到 Paypal 帐户的加密卖家选项,但仍然没有效果。

非常感谢您阅读我的问题!

更新:这里要求的是正在使用的代码。

        String hostingOn = ConfigurationManager.AppSettings["default_site_url"];
        reqDetails.ReturnURL = hostingOn + "marketplace_confirm.aspx";
        reqDetails.CancelURL = hostingOn + "marketplace.aspx";
        reqDetails.NoShipping = "1";
        reqDetails.ReqConfirmShipping = "0";

        reqDetails.OrderTotal = new BasicAmountType()
        {
            currencyID = CurrencyCodeType.CAD,
            Value = payment_amt.Value,
        };

        SetExpressCheckoutReq req = new SetExpressCheckoutReq()
        {
            SetExpressCheckoutRequest = new SetExpressCheckoutRequestType()
            {
                Version = UtilPayPalAPI.Version,
                SetExpressCheckoutRequestDetails = reqDetails
            }

        };

        PayPalAPIAASoapBinding paypal = new PayPalAPIAASoapBinding();

        paypal.SetExpressCheckout(req);

我也在使用https://api-aa-3t.paypal.com/2.0/ url 来访问 API

【问题讨论】:

  • 您能否发布您用于连接的实际代码而不是错误,我将在下面发布其他几个问题

标签: c# asp.net paypal paypal-sandbox


【解决方案1】:

自 2016 年初以来,Paypal 开始要求 TLS 1.2 协议在沙盒中进行通信,并将从 6 月 17 日开始在实时环境中强制执行。请参阅 here 以获取参考。

在大多数 .NET 应用程序中,TLS 1.2 将默认禁用,因此您需要启用它。

你需要在Application_Start方法的开头添加如下一行:

public class Site : HttpApplication
{
    protected void Application_Start()
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
        // other configuration
    }
}

【讨论】:

  • 上帝保佑你!你拯救了我的一天。 :)
  • 对于那些使用旧版本 MVC (3) 或 .NET Framework (ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
【解决方案2】:

您可能连接到 api.paypal.com 或 api.sandbox.paypal.com,而不是发送您的 API 证书。 API 证书是用于完成 SSL 链的客户端 SSL 证书。

如果您没有或未使用 API 证书,则应分别连接到 api-3t.paypal.com 或 api-3t.sandbox.paypal.com 以进行 Live 或 Sandbox。

【讨论】:

  • 问题似乎是当我使用正确的服务器时,我没有正确调用它。我去了贝宝网站并自动生成了贝宝功能,并使用包含的 ShortcutExpressCheckout 方法,我能够成功获得令牌。生成器在这里:paypal-labs.com/integrationwizard/ecpaypal/main.php
  • paypal-labs.com 主页当前显示“我们目前正在开发一个新网站”,上面的链接返回一个空白页面。试试这个:devtools-paypal.com/integrationwizard C# 向导似乎运行了 好的,我还没有尝试过代码。
【解决方案3】:

我一直在使用 PayPal (NVP/Signature) Express Checkout 集成并遇到此 SSL/TLS 错误。

我所做的一切似乎都无法解决,但后来我发现以下代码要添加到我的请求之上。作为参考,我使用的是 MVC3/.NET 4,因此默认情况下我无法使用 Tls1.2(就像在 .NET 4.5 + 中一样)。这段代码的前三行绕过了这个问题。希望对大家有所帮助!

ServicePointManager.Expect100Continue = true;
ServicePointManager.SecurityProtocol = (SecurityProtocolType)3072;
ServicePointManager.DefaultConnectionLimit = 9999;

var url = "https://[paypal-api-url]/nvp";
var uri = new Uri(url);
var request = WebRequest.Create(uri);
var encoding = new UTF8Encoding();
var requestData = encoding.GetBytes(data);

request.ContentType = "application/x-www-form-urlencoded";
request.Method = "POST";
request.Timeout = (300 * 1000); 
request.ContentLength = requestData.Length;

using (var stream = request.GetRequestStream())
{
    stream.Write(requestData, 0, requestData.Length);
}

var response = request.GetResponse();
...

【讨论】:

    【解决方案4】:

    非常感谢这对我很有帮助。

    这里是我在 VB.NET 中建立接口的代码供参考

      'Create a service Binding in code
                                Dim ppEndpointAddress As New System.ServiceModel.EndpointAddress("https://api-3t.sandbox.paypal.com/2.0/")
                                Dim ppBinding As New System.ServiceModel.BasicHttpBinding(System.ServiceModel.BasicHttpSecurityMode.Transport)
    
                                Dim ppIface As New PayPalAPI.PayPalAPIAAInterfaceClient(ppBinding, ppEndpointAddress)
    
                                Dim ppPaymentReq As New PayPalAPI.DoDirectPaymentReq()
    
                                ppPaymentReq.DoDirectPaymentRequest = ppRequest
    

    【讨论】:

      猜你喜欢
      • 2019-03-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-02
      • 1970-01-01
      • 1970-01-01
      • 2011-07-31
      • 2015-06-19
      相关资源
      最近更新 更多