php - 异常 'Viewflex\Forex\ForexException' 带有消息'检索汇率时出错
问题描述
我正在使用这个包的版本 "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
如果您单击该链接,将为您提供答案:
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,然后发送拉取请求,或更改作曲家包名称https://github.com/viewflex/forex/blob/master/composer.json#L2并使用https:/注册您自己的新包/packagist.org/(如果你这样做,也改变所有的文件命名空间。)
如果您注册新的 API 并发送新的端点,我可以向该人发送带有修复的拉取请求。
推荐阅读
- ios - iOS 上 Safari 上的 geolocation.getCurrentPosition
- amazon-web-services - 使用聊天机器人在 Slack 中启用 aws 命令
- python - 使用 Scrapy Splash 和 Lua 在鼠标点击时动态加载内容
- csv - 如何从标记的 CSV 文件中进行训练?
- java - GWT - 网格行标题点击事件
- c++ - 具有未知参数类型的 C++ 空虚函数
- matlab - 使用matlab求两个变量函数的上确界和下确界
- c# - 加快向 Oracle 发出取消信号
- python - python中的简单二维输入
- java - 如何将字符串发送到另一个套接字?