dzasa/open-exchange-rates

Openexchangerates.org API的PHP包装器,具有扩展功能。

dev-master 2014-10-25 18:57 UTC

This package is not auto-updated.

Last update: 2024-09-24 02:11:40 UTC


README

Openexchangerates.org API的PHP包装器,具有非高级选项计划的扩展功能。

特性

  • 返回所有可用货币
  • 返回默认基础货币USD或自定义货币的最新汇率
  • 返回默认基础货币USD或自定义货币的历史汇率
  • 返回默认基础货币USD或自定义货币的日期范围汇率
  • 返回单个汇率
  • 更改基础货币
  • 货币之间转换
  • 使用Memcache、APC或文件缓存缓存汇率
  • 设置结果汇率中返回的货币

用法

<?php

use Dzasa\OpenExchangeRates\OpenExchangeRates;
use Dzasa\OpenExchangeRates\Cache;

$config = array(
    'api_key' => 'your_api_key', // required
    'protocol' => 'https', // optional [http|https]
    'client' => 'curl',  // optional [curl|file_get_contents]
    'base' => 'EUR' // optional
);

// using File cache
$cache = new Cache("file", array('cache_dir'=>'/path_to_cache_dir/'));
$exchangeRates = new OpenExchangeRates($config, $cache);

// or using APC
$cache = new Cache("apc");
$exchangeRates = new OpenExchangeRates($config, $cache);

// or using Memcache
$cache = new Cache("memcache", array('host'=>'localhost', 'port'=> 11211));
$exchangeRates = new OpenExchangeRates($config, $cache);

// or not using cache
$exchangeRates = new OpenExchangeRates($config);

// get all currencies
$currencies = $exchangeRates->getAllCurrencies();

// change base currency
$exchangeRates->setBaseCurrency("BAM");

// set currencies
$exchangeRates->setSymbols("BAM,EUR,USD");

// get latest currencies
$latestRates = $exchangeRates->getLatestRates();

// get exchange rates for 01.01.2014, input can be any valid strtotime input for past
$historicalRates = $exchangeRates->getHistorical("2014-01-01");

// get exchange rates for date range, input can be any valid strtotime() input
$timeSeries = $exchangeRates->getTimeSeries("last Friday", "today");

// convert from EUR to BAM with 3 decimals
$convert = $exchangeRates->convert("EUR", "BAM", 10, 3);

// get rate for EUR currency
$singleRate = $exchangeRates->getRate("EUR");

// get base currency
$baseCurrency = $exchangeRates->getBaseCurrency();

// get API license
$license = $exchangeRates->getLicense();

// get API Disclaimer
$disclaimer = $exchangeRates->getDisclaimer();

关于

需求

  • 支持PHP 5.3或更高版本。

提交错误和功能请求

错误和功能请求在GitHub上跟踪

版本

0.7.2

作者

Jasenko Rakovic - naucnik@gmail.com

许可

在MIT许可下发布 - 详细信息请见LICENSE文件