代码之家  ›  专栏  ›  技术社区  ›  Jeff Anderson

我需要新的PayPal API来支持.Net服务器上的TLS 1.2吗?

  •  4
  • Jeff Anderson  · 技术社区  · 8 年前

    我正在运行ASP。Net 4.5,但使用的是非常旧的PayPal SOAP api版本。参考是paypal_base。dll的报告版本为4.3.1.0。调用API的代码具有引用以下内容的“using”语句:

    com.paypal.sdk.服务

    com.paypal.soap.api公司。

    我已经在调用PayPal api时验证了该值

    系统网络服务点管理器安全协议

    包括ssl3和tls1.2。

    但是,当执行setExpressCheckout调用时,我会得到一个运行时异常,它表示: 请求已中止:无法创建SSL/TLS安全通道。

    我下载了PayPal API Samples项目,并使用相同的沙盒凭证,它可以工作。在Fiddler中,除了样本API调用指向API-3t.sandbox.paypal之外,其他调用几乎相同。com,而我的代码是api-aa.sandbox.paypal。但是根据TLS1.2就绪性的文档,这两个api都应该可以工作。除了在“live”和“sandbox”之间切换之外,我在两个API中都没有看到其他地方可以设置端点。

    在小提琴手的回应中,两者都显示: “找到与SSLv3兼容的ServerHello握手。Fiddler提取了以下参数。 版本:3.3(TLS/1.2)“ 除了“随机”参数外,响应是相同的。因此,旧的API调用使用TLS 1.2

            SetExpressCheckoutRequestType request = new SetExpressCheckoutRequestType();
            populateRequestObject(request); //populate request data
            SetExpressCheckoutReq wrapper = new SetExpressCheckoutReq();
            wrapper.SetExpressCheckoutRequest = request;
            Dictionary<string, string> configurationMap = Configuration.GetAcctAndConfig(); //set merchant config
            PayPalAPIInterfaceServiceService service = new PayPalAPIInterfaceServiceService(configurationMap);
            SetExpressCheckoutResponseType setECResponse = service.SetExpressCheckout(wrapper); //make the call
    

    我的(同样,非常旧的代码看起来是这样的):

        CallerServices caller = new CallerServices();
        caller.APIProfile = SetProfile.ApplicationProfile; //set merchant config
        SetExpressCheckoutRequestType pp_request = new SetExpressCheckoutRequestType();
        // Create the request details object
        pp_request.SetExpressCheckoutRequestDetails = new SetExpressCheckoutRequestDetailsType();
        pp_request.SetExpressCheckoutRequestDetails.PaymentAction = paymentAction;
        pp_request.SetExpressCheckoutRequestDetails.PaymentActionSpecified = true;
    
        pp_request.SetExpressCheckoutRequestDetails.OrderTotal = new BasicAmountType();
    
        pp_request.SetExpressCheckoutRequestDetails.OrderTotal.currencyID = currencyCodeType;
        pp_request.SetExpressCheckoutRequestDetails.OrderTotal.Value = paymentAmount;
    
        pp_request.SetExpressCheckoutRequestDetails.CancelURL = cancelURL;
        pp_request.SetExpressCheckoutRequestDetails.ReturnURL = returnURL;
        return (SetExpressCheckoutResponseType) caller.Call("SetExpressCheckout", pp_request); //do the call
    

    示例代码正常工作,我的代码抛出SSL/TLS错误。我尝试升级到最新的SDK,但变化太大了,要迁移所有这些代码将需要很大的努力。

    从fiddler看来,它似乎在使用TLS 1.2,甚至与旧API一起使用,但我得到了一个关于SSL/TLS连接的运行时异常。是因为端点不同吗?旧API是不是太旧了?

    提前感谢您的任何帮助-我希望避免迁移所有那些古老的代码!。

    编辑:我应该提到我使用的是用户名/密码/签名凭据,而不是基于证书的凭据。

    2 回复  |  直到 4 年前
        1
  •  2
  •   PP_MTS_hzhu    8 年前

    由于.Net4.5支持TLS1.2,但它不是默认协议。你需要选择使用它。以下代码将使TLS 1.2成为默认值,请确保在连接到安全资源之前执行它:

    ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
    
        2
  •  0
  •   Cwinds    4 年前

    我阅读了这个Q/A,并应用了上面答案中的ServicePointManager引用——作为我的HttpWebRequest调用方法中的第一行,它工作了。谢谢大家。 仅供参考,我正在构建的示例代码来自//docs.microsoft。com,“ASP.NET 4.5 Web Forms and Visual Studio 2017入门”。