首页 文章

Stripe - PHP错误 - Stripe不再支持使用TLS 1.0发出的API请求

提问于
浏览
2

是否可以在没有HTTPS页面的情况下运行条带测试?我似乎在我的localhost上收到以下错误 . 有没有办法纠正它?

这在提交付款信息后发生 .

致命错误:未捕获异常'Stripe \ Error \ Authentication',消息'Stripe不再支持使用TLS 1.0发出的API请求 . 请使用TLS 1.2或更高版本启动HTTPS连接 . 您可以访问https://stripe.com/blog/upgrading-tls了解更多相关信息 . 在/Applications/MAMP/htdocs/composer/vendor/stripe/stripe-php/lib/ApiRequestor.php:110来自API请求'req_9AwHIpLsRiWhRz'堆栈跟踪:#0 / Applications / MAMP / htdocs / composer / vendor / stripe / stripe -php / lib / ApiRequestor.php(227):Stripe \ ApiRequestor-> handleApiError('{\ n“error”:{\ n ...',401,Array,Array)#1 / Applications / MAMP / htdocs / composer / vendor / stripe / stripe-php / lib / ApiRequestor.php(65):Stripe \ ApiRequestor - > _ interpretResponse('{\ n“error”:{\ n ...',401,Array)#2 / Applications /MAMP/htdocs/composer/vendor/stripe/stripe-php/lib/ApiResource.php(120):Stripe \ ApiRequestor-> request('post','/ v1 / customers',Array,Array)#3 / Applications /MAMP/htdocs/composer/vendor/stripe/stripe-php/lib/ApiResource.php(160):Stripe \ ApiResource :: _ staticRequest('post','/ v1 / custom in / Applications / MAMP / htdocs / composer /第110行的vendor / stripe / stripe-php / lib / ApiRequestor.php

3 回答

  • -1

    这里的问题不是使用HTTPS页面 . 这是您的服务器(本例中为本地计算机)和Stripe之间的TLS通信 . 几个月前,Stripe发布了一篇博文,解释说出于安全原因,他们会弃用一些被认为不安全的旧协议 . 你可以在这里阅读更多相关信息:

    https://stripe.com/blog/upgrading-tls

    现在,如果您遇到此问题,您的服务器或计算机默认使用TLS 1.0而不是所需的TLS 1.2 .

    通常这是由于您的计算机上存在过时的软件或配置问题 . 我建议您查看Stripe的支持文章,其中详细介绍了如何测试代码以及升级路径(包括针对Mac OS和MAMP的一些细节 - 基本上您需要运行应用程序系统php而不是与MAMP捆绑的版本):

    https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#php

    此外,如果您发现系统不支持TLS 1.2,则应升级服务器以正确支持TLS 1.2 . 这可能需要升级操作系统,curl,openssl和/或语言库 .

    https://support.stripe.com/questions/how-do-i-upgrade-my-openssl-to-support-tls-1-2

    此测试脚本有助于识别PHP安装使用的库版本:https://gist.github.com/olivierbellone/9f93efe9bd68de33e9b3a3afbd3835cf

    如果您使用的是3.x版本的PHP库,则可以考虑升级到4.x分支 . 虽然更新系统库是最佳解决方案,但4.x分支允许您传递 CURLOPT_SSLVERSION 标志,这可能允许某些版本的PHP / curl通过TLS 1.2成功通信 .

    https://github.com/stripe/stripe-php#ssl--tls-compatibility-issues

  • 0

    如果您使用的是Anaconda,以下解决方法适用于我的MAC机器 . 首先,使用conda安装openssl

    conda install openssl

    然后使用Anaconda管理的python安装创建一个新的虚拟环境 . 在新的虚拟环境中安装您的需求,它应该解决TLS问题 . 使用以下代码进行测试 - source - [https://support.stripe.com/questions/how-do-i-upgrade-my-stripe-integration-from-tls-1-0-to-tls-1-2#python]

    import stripe
    stripe.api_key = "sk_test_BQokikJOvBiI2HlWgH4olfQ2"
    stripe.api_base = "https://api-tls12.stripe.com"
    
    if stripe.VERSION in ("1.13.0", "1.14.0", "1.14.1", "1.15.1", "1.16.0", "1.17.0", "1.18.0", "1.19.0"):
        print ("Bindings update required.")
    
    try:
        stripe.Charge.all()
        print ("TLS 1.2 supported, no action required.")
    except stripe.error.APIConnectionError:
        print ("TLS 1.2 is not supported. You will need to upgrade your integration.")
    
  • 6

    使用下面的脚本

    require_once(APPPATH . 'libraries/vendor/autoload.php');
    try {
        $curl = new \Stripe\HttpClient\CurlClient(array(CURLOPT_SSLVERSION => CURL_SSLVERSION_TLSv1));
        \Stripe\ApiRequestor::setHttpClient($curl);
        \Stripe\Stripe::setApiKey($this->apiKey);
    
        $token = \Stripe\Token::create(array(
            "card" => array(
                "number" => $creditCard,
                "exp_month" => $expMonth,
                "exp_year" => $expYear,
                "cvc" => $cvc
            )
        ));
    
        $result = $token->getLastResponse();
        $json = json_decode($result->body);
        $token = $json->id;
    } catch (Exception $e) {
        echo $e->getMessage();
        exit;
    }
    

相关问题