ranium/fixerio-php-client

fixer.io 外汇汇率和货币转换API的PHP客户端。

v1.2.0 2021-01-05 11:11 UTC

This package is auto-updated.

Last update: 2024-09-05 19:04:34 UTC


README

Build Status Total Downloads Latest Stable Version License

Fixer.io PHP客户端

fixer.io 交易所率和货币转换JSON API提供易于使用的客户端。

寻找Laravel包?请使用 ranium/laravel-fixerio 而不是这个库。

安装

可以使用Composer安装此项目

composer require ranium/fixerio-php-client

使用

此包使用Guzzle的Service Description来向fixer.io API发送HTTP请求。

要在您的应用程序中使用此包,只需使用包并如下实例化客户端:

use Ranium\Fixerio\Client;

$accessKey = '12345678901234567890';
$secure = true; // Optional, default is true (only paid plans of fixer.io supports SSL)
$config = []; // Optional, guzzle command client config that you might want to pass

$fixerio = Client::create($accessKey, $secure, $config);

以下是访问fixer.io端点的方法:

注意:默认情况下,所有请求都会发送 access_key 参数,因此调用方法时无需传递它。但是,如果您想覆盖在实例化fixerio客户端时使用的访问密钥,则可以包含它。

最新汇率端点

$latestRates = $fixerio->latest(
    [
        'base' => 'USD', // optional
        'symbols' => 'INR', // optional
    ]
);

// Display the INR rates
echo $latestRates['rates']['INR'];

历史汇率端点

$historicalRates = $fixerio->historical(
    [
        'date' => '2019-01-01',
        'base' => 'USD', // optional
        'symbols' => 'INR', //optional
    ]
);

// Display the INR rates
echo $latestRates['rates']['INR'];

转换端点

$convertedRates = $fixerio->convert(
    [
        'from' => 'USD',
        'to' => 'INR',
        'amount' => 50.75,
        'date' => '2019-01-01', //optional
    ]
);

// Display the converted amount
echo $convertedRates['result'];

时间序列数据端点

$timeseriesData = $fixerio->timeseries(
    [
        'start_date' => '2019-01-01',
        'end_date' => '2019-01-05',
        'base' => 'USD', // optional
        'symbols' => 'INR', //optional
    ]
);

// Display the INR rate for 2019-01-02
echo $timeseriesData['rates']['2019-01-02']['INR'];

波动数据端点

$fluctuationData = $fixerio->fluctuation(
    [
        'start_date' => '2019-01-01',
        'end_date' => '2019-01-05',
        'base' => 'USD', // optional
        'symbols' => 'INR', //optional
    ]
);

// Display the change/fluctuation amount of INR between the given date range
echo $fluctuationData['rates']['INR']['change'];

上述所有调用的响应都将是一个JSON对象。请参阅fixer.io的 文档 获取有关各种端点、请求参数和响应对象的更多详细信息。

许可证

此包是开源软件,许可协议为 MIT许可证