aveiv / open-exchange-rates-api
Open Exchange Rates API 的 PHP 封装
v2.1.1
2022-11-02 16:59 UTC
Requires
- php: ^7.4|^8.0
- ext-curl: *
- ext-json: *
- aveiv/mixed-value: ^0.3
Requires (Dev)
- phpunit/phpunit: ^9.2
- vimeo/psalm: ^3.14
README
安装
composer require aveiv/open-exchange-rates-api
使用示例
$api = new OpenExchangeRates('YOUR_APP_ID'); // or $client = new OpenExchangeRates('YOUR_APP_ID', new YourHttpClient()); // Getting currencies $api->currencies(); // returns ["USD" => "United States Dollar", ...] $api->currencies([ 'show_alternative' => true, // include alternative currencies 'show_inactive' => true, // include historical/inactive currencies ]); // Getting latest rates $api->latest(); // returns ["USD" => 1.0, ...] $api->latest([ 'base' => 'EUR', // base currency 'symbols' => ['CNY', 'USD'], // limit results to specific currencies 'show_alternative' => true, // include alternative currencies ]); // Getting historical rates $api->historical(new \DateTime('2020-01-01')); // ["USD" => 1.0, ...] $api->historical(new \DateTime('2020-01-01'), [ 'base' => 'EUR', // base currency 'symbols' => ['CNY', 'USD'], // limit results to specific currencies 'show_alternative' => true, // include alternative currencies ]); // Currency conversion $api->convert(99.99, 'USD', 'EUR'); // returns the converted value (from USD to EUR)