异常 'Viewflex\Forex\ForexException',消息为“检索汇率时出错
exception 'Viewflex\Forex\ForexException' with message 'Error retrieving exchange rate
我正在使用这个包的版本 "viewflex/forex":“^0.1.1”
但是在更新 -
的货币汇率时
$usdRate = $server->getRate('USD', 'INR');
报错如下
异常 'Viewflex\Forex\ForexException',消息为“检索汇率时出错。
任何帮助!!!
谢谢,
查看他们的源代码,我看到了这个:
https://github.com/viewflex/forex/blob/master/src/Forex.php#L57-L68
if (
array_key_exists('rates', $content)
&& array_key_exists($target, $content['rates'])
&& $content['rates'][$target]
) {
$rate = floatval($content['rates'][$target]);
} else {
throw new ForexException('Error retrieving exchange rate.');
}
if($rate <= 0)
throw new ForexException('Error retrieving exchange rate.');
所以看起来,如果响应不包含所需信息,它将抛出异常。此外,如果它通过了第一次检查但速率 < 0,它也会抛出异常。所以看起来你实际上并没有做错任何事。
进一步观察,我看到它发出了这个调用:
$response = $this->request('https://api.fixer.io/latest?base='.$source.'&symbols='.$target);
我根据您的代码将其翻译为:
https://api.fixer.io/latest?base=USD&symbols=INR
如果你点击 link,你会得到答案:
0 "#################################################################################################################################"
1 "# #"
2 "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT #"
3 "# #"
4 "# This API endpoint is deprecated and has now been shut down. To keep using the Fixer API, please update your integration #"
5 "# to use the new Fixer API endpoint, designed as a simple drop-in replacement. #"
6 "# You will be required to create an account at https://fixer.io and obtain an API access key. #"
7 "# #"
8 "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/fixerAPI/fixer#readme #"
9 "# #"
a "#################################################################################################################################"
看起来图书馆已经过时了。
要么使用不同的库,要么让它再次运行。
要解决这个问题,您可以先使用新的 api 创建一个帐户,如果您还没有注册 github,请 fork 存储库,更改此行 https://github.com/viewflex/forex/blob/master/src/Forex.php#L53, and either send a pull request, or change the composer package name https://github.com/viewflex/forex/blob/master/composer.json#L2 and register your own new package with https://packagist.org/ (如果你这样做,也要更改所有文件命名空间。)
如果您注册新的 API 并发送新的端点,我可以向他发送带有修复程序的拉取请求。
我正在使用这个包的版本 "viewflex/forex":“^0.1.1” 但是在更新 -
的货币汇率时$usdRate = $server->getRate('USD', 'INR');
报错如下 异常 'Viewflex\Forex\ForexException',消息为“检索汇率时出错。
任何帮助!!! 谢谢,
查看他们的源代码,我看到了这个:
https://github.com/viewflex/forex/blob/master/src/Forex.php#L57-L68
if (
array_key_exists('rates', $content)
&& array_key_exists($target, $content['rates'])
&& $content['rates'][$target]
) {
$rate = floatval($content['rates'][$target]);
} else {
throw new ForexException('Error retrieving exchange rate.');
}
if($rate <= 0)
throw new ForexException('Error retrieving exchange rate.');
所以看起来,如果响应不包含所需信息,它将抛出异常。此外,如果它通过了第一次检查但速率 < 0,它也会抛出异常。所以看起来你实际上并没有做错任何事。
进一步观察,我看到它发出了这个调用:
$response = $this->request('https://api.fixer.io/latest?base='.$source.'&symbols='.$target);
我根据您的代码将其翻译为:
https://api.fixer.io/latest?base=USD&symbols=INR
如果你点击 link,你会得到答案:
0 "#################################################################################################################################"
1 "# #"
2 "# IMPORTANT - PLEASE UPDATE YOUR API ENDPOINT #"
3 "# #"
4 "# This API endpoint is deprecated and has now been shut down. To keep using the Fixer API, please update your integration #"
5 "# to use the new Fixer API endpoint, designed as a simple drop-in replacement. #"
6 "# You will be required to create an account at https://fixer.io and obtain an API access key. #"
7 "# #"
8 "# For more information on how to upgrade please visit our Github Tutorial at: https://github.com/fixerAPI/fixer#readme #"
9 "# #"
a "#################################################################################################################################"
看起来图书馆已经过时了。
要么使用不同的库,要么让它再次运行。
要解决这个问题,您可以先使用新的 api 创建一个帐户,如果您还没有注册 github,请 fork 存储库,更改此行 https://github.com/viewflex/forex/blob/master/src/Forex.php#L53, and either send a pull request, or change the composer package name https://github.com/viewflex/forex/blob/master/composer.json#L2 and register your own new package with https://packagist.org/ (如果你这样做,也要更改所有文件命名空间。)
如果您注册新的 API 并发送新的端点,我可以向他发送带有修复程序的拉取请求。