Stripe - PHP 错误 - Stripe 不再支持使用 TLS 1.0 发出的 API 请求
Stripe - PHP error - Stripe no longer supports API requests made with TLS 1.0
是否可以在没有 HTTPS 页面的情况下 运行 条带化测试?我的本地主机上似乎出现以下错误。有办法改正吗?
这是在提交付款信息后发生的。
Fatal error: Uncaught exception 'Stripe\Error\Authentication' with
message 'Stripe no longer supports API requests made with TLS 1.0.
Please initiate HTTPS connections with TLS 1.2 or later. You can learn
more about this at https://stripe.com/blog/upgrading-tls.' in
/Applications/MAMP/htdocs/composer/vendor/stripe/stripe-php/lib/ApiRequestor.php:110
from API request 'req_9AwHIpLsRiWhRz' Stack trace: #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/vendor/stripe/stripe-php/lib/ApiRequestor.php
on line 110
这里的问题不是使用 HTTPS 页面。这是您的服务器(在本例中为本地计算机)和 Stripe 之间的 TLS 通信。几个月前,Stripe 发布了一篇博客 post 解释说,出于安全原因,他们将弃用一些被认为不安全的旧协议。您可以在此处阅读更多相关信息:
https://stripe.com/blog/upgrading-tls
现在,如果您遇到此问题,您的服务器或计算机默认使用 TLS 1.0 而不是所需的 TLS 1.2。
通常这是由于软件过时或您的计算机配置问题所致。我建议您查看 Stripe 的支持文章,其中详细介绍了如何测试您的代码以及升级路径(包括一些特定于 Mac OS 和 MAMP 的细节——本质上您将需要 运行 您的应用程序与系统 php 而不是与 MAMP 捆绑在一起的版本):
此外,如果您发现您的系统不支持 TLS 1.2,您应该升级您的服务器以正确支持 TLS 1.2。这可能需要升级操作系统、curl、openssl and/or 语言库。
https://support.stripe.com/questions/how-do-i-upgrade-my-openssl-to-support-tls-1-2
此测试脚本有助于识别您的 PHP 安装使用的库版本:https://gist.github.com/olivierbellone/9f93efe9bd68de33e9b3a3afbd3835cf
如果您使用的是 PHP 库的 3.x 版本,您可以考虑升级到 4.x 分支。虽然更新您的系统库是这里最好的解决方案,但 4.x 分支允许您传递 CURLOPT_SSLVERSION
标志,这可能允许某些版本的 PHP/curl 通过 TLS 1.2 成功通信。
https://github.com/stripe/stripe-php#ssl--tls-compatibility-issues
使用下面的脚本
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;
}
如果您使用的是 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.")
是否可以在没有 HTTPS 页面的情况下 运行 条带化测试?我的本地主机上似乎出现以下错误。有办法改正吗?
这是在提交付款信息后发生的。
Fatal error: Uncaught exception 'Stripe\Error\Authentication' with message 'Stripe no longer supports API requests made with TLS 1.0. Please initiate HTTPS connections with TLS 1.2 or later. You can learn more about this at https://stripe.com/blog/upgrading-tls.' in /Applications/MAMP/htdocs/composer/vendor/stripe/stripe-php/lib/ApiRequestor.php:110 from API request 'req_9AwHIpLsRiWhRz' Stack trace: #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/vendor/stripe/stripe-php/lib/ApiRequestor.php on line 110
这里的问题不是使用 HTTPS 页面。这是您的服务器(在本例中为本地计算机)和 Stripe 之间的 TLS 通信。几个月前,Stripe 发布了一篇博客 post 解释说,出于安全原因,他们将弃用一些被认为不安全的旧协议。您可以在此处阅读更多相关信息:
https://stripe.com/blog/upgrading-tls
现在,如果您遇到此问题,您的服务器或计算机默认使用 TLS 1.0 而不是所需的 TLS 1.2。
通常这是由于软件过时或您的计算机配置问题所致。我建议您查看 Stripe 的支持文章,其中详细介绍了如何测试您的代码以及升级路径(包括一些特定于 Mac OS 和 MAMP 的细节——本质上您将需要 运行 您的应用程序与系统 php 而不是与 MAMP 捆绑在一起的版本):
此外,如果您发现您的系统不支持 TLS 1.2,您应该升级您的服务器以正确支持 TLS 1.2。这可能需要升级操作系统、curl、openssl and/or 语言库。
https://support.stripe.com/questions/how-do-i-upgrade-my-openssl-to-support-tls-1-2
此测试脚本有助于识别您的 PHP 安装使用的库版本:https://gist.github.com/olivierbellone/9f93efe9bd68de33e9b3a3afbd3835cf
如果您使用的是 PHP 库的 3.x 版本,您可以考虑升级到 4.x 分支。虽然更新您的系统库是这里最好的解决方案,但 4.x 分支允许您传递 CURLOPT_SSLVERSION
标志,这可能允许某些版本的 PHP/curl 通过 TLS 1.2 成功通信。
https://github.com/stripe/stripe-php#ssl--tls-compatibility-issues
使用下面的脚本
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;
}
如果您使用的是 Anaconda,则以下解决方法适用于我的 MAC 机器。首先,使用 conda
安装 opensslconda 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.")