lukapeharda / hmrc-exchange-rates
获取HM Revenue & Customs汇率用于关税及增值税
v1.1.0
2024-03-04 14:36 UTC
Requires
- guzzlehttp/guzzle: ^6.3
This package is auto-updated.
Last update: 2024-09-04 15:54:05 UTC
README
使用PHP从HMRC网站获取月度汇率。汇率从月度文件中解析。
获取的CSV文件存储在提供的路径中,以优化和加快过程。
安装
使用composer安装
composer require lukapeharda/hmrc-exchange-rates
用法
获取所有货币/汇率值对
<?php // Initialize the client and provide storage path for file cache. // If path isn't provided "/tmp" will be used. $hmrcClient = new LukaPeharda\HmrcExchangeRates\Hmrc('/storage/path'); // First param is a four digit representation of a year (2024). Second one is a // numeric representation of a month (5) without leading zeros. // Only first param is required. Others are optional. Current year and month // will be used. $rates = $hmrcClient->getMonthlyRates(date('Y'), date('n')); // $rates = [... , 'EUR' => 1.1545, ... , 'USD' => 1.3049, ...] at the time of // writting documentation
获取特定货币的汇率(以下示例中使用USD)
<?php // Initialize the client and provide storage path for file cache. // If path isn't provided "/tmp" will be used. $hmrcClient = new LukaPeharda\HmrcExchangeRates\Hmrc('/storage/path'); // First param is currency code in ISO 4217. Second one a four digit // representation of a year (2024). Third one is a numeric representation of a // month (5) without leading zeros. // Only first param is required. Others are optional. Current year and month // will be used. $usdRate = $hmrcClient->getMonthlyRateForCurrency('USD', date('Y'), date('n')); // $usdRate = 1.3049 at the time of writting documentation