georgii-web/cbr-api-exchange

Cbr.ru汇率API包。从俄罗斯中央银行API获取货币汇率,http://www.cbr.ru。

1.0.3 2023-10-16 18:16 UTC

This package is auto-updated.

Last update: 2024-09-16 20:16:30 UTC


README

Cbr.ru汇率API。

从俄罗斯中央银行API获取货币汇率,http://www.cbr.ru

所有货币列表: http://www.cbr.ru/scripts/XML_val.asp?d=0

获取美元汇率示例URL: http://www.cbr.ru/scripts/XML_dynamic.asp?date_req1=01/01/2021&date_req2=12/01/2021&VAL_NM_RQ=R01235

功能

中央银行每天发布第二天(在一天的第二部分)的汇率公告。

在节假日没有公告,因此使用前一天的汇率。

例如,在2020年12月31日08:00,我们不会得到2021年1月1日的汇率,但在21:00我们会得到。如果我们检查2021年1月4日的汇率,我们会得到2021年1月1日的汇率。

安装

$ composer require georgii-web/cbr-api-exchange

如何使用

添加类

use CbrApiExchange\CbrApiExchange;

使用示例

CbrApiExchange::get(); // Get default currency 'R01235'(USD) on default date 'Today()'
CbrApiExchange::get('R01239'); // Get currency 'R01239'(EUR) on default date 'Today()'
CbrApiExchange::get('R01239', '2021-01-01'); // Get currency 'R01239'(EUR) on date '2021-01-01'

返回值

[
  "code" => "R01235", // The actual currency code
  "date" => "2021-01-01", // The actual date of the exchange rate
  "rate" => 73.8757, // Exchange rate of this currency to the Ruble
]

开发

测试

$ ./vendor/bin/pest

Psalm检查

$ ./vendor/bin/psalm