承接 reaway/exchange-rate 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

reaway/exchange-rate

最新稳定版本:v1.0.0

Composer 安装命令:

composer require reaway/exchange-rate

包简介

A PHP exchange rate query library with multi-source support

README 文档

README

PHP Version License

A PHP exchange rate query library supporting multiple data sources.

简体中文

Features

  • Multi-source Support — Built-in CurrencyLayer and ExchangeRate-API data sources
  • Easy Extension — Simple driver extension mechanism to add new data sources
  • Lazy Loading — Automatically fetches exchange rate data on first access
  • Type Safe — Full PHP 8.1+ type declarations

Requirements

  • PHP >= 8.1
  • ext-curl

Installation

composer require reaway/exchange-rate

Usage

Basic Usage

<?php

use ExchangeRate\Rate;

// Configuration
$config = [
    'default' => 'currency_layer',
    'sources' => [
        'currency_layer' => [
            'access_key' => 'your-exchange-rate-api-key', // API访问密钥
        ],
        'exchange_rate_api' => [
            'access_key' => 'your-exchange-rate-api-key', // API访问密钥
        ],
    ],
];

$rate = new Rate($config);

// Get all exchange rates (based on USD)
$rates = $rate->getRates('USD');
// Returns: ['EUR' => 0.92, 'CNY' => 7.23, 'JPY' => 150.45, ...]

// Get specific currency exchange rate
$eurRate = $rate->getRate('EUR', 'USD');
// Returns: 0.92

// Switch data source
$rates = $rate->source('exchange_rate_api')->getRates('USD');

Using Facade

<?php

use ExchangeRate\Facade\RateFacade;
use Think\Component\Config\Facade\ConfigFacade;

require dirname(__DIR__) . '/vendor/autoload.php';

// Configuration
$config = [
    'default' => 'currency_layer',
    'sources' => [
        'currency_layer' => [
            'access_key' => 'your-exchange-rate-api-key', // API访问密钥
        ],
        'exchange_rate_api' => [
            'access_key' => 'your-exchange-rate-api-key', // API访问密钥
        ],
    ],
];
ConfigFacade::set($config, 'rate');

// Get all exchange rates
$rates = RateFacade::getRates('USD');

// Get specific currency exchange rate
$rate = RateFacade::getRate('EUR', 'USD');

Supported Data Sources

Source Website Free Tier Features
CurrencyLayer currencylayer.com Real-time rates, 168 currencies
ExchangeRate-API exchangerate-api.com Reliable, easy to use

Extending Custom Data Source

Create a new driver by extending RateAbstract:

<?php

namespace ExchangeRate\Source;

use ExchangeRate\Abstract\RateAbstract;

class MySource extends RateAbstract
{
    protected function fetchData(): array
    {
        // Implement your API request
        $url = 'https://api.example.com/rates';
        $response = $this->makeRequest($url);
        
        // Parse and return rates
        $this->rates = $response['rates'];
        return $response;
    }
}

License

This project is licensed under the MIT License - see the LICENSE file for details.

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 5
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-03-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固