定制 truncgil/finance 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

truncgil/finance

最新稳定版本:5.0

Composer 安装命令:

composer require truncgil/finance

包简介

A Laravel package to integrate Truncgil Finance API

README 文档

README

Light Logo Dark Logo

This package allows you to easily use the Truncgil Finance API in your Laravel projects.

Features

  • Easy access to currency rates, gold prices, and cryptocurrency data
  • Automatic caching
  • Facade support
  • Error handling
  • Easy configuration

Installation

Use the following command to add the package to your project:

composer require truncgil/finance

Configuration

To configure the package, create a config/finance.php file and add the following settings:

return [
    'api_url' => 'https://api.truncgil.com/finance',
    'cache_key' => 'finance_data',
    'cache_duration' => 3600, // 1 hour
    'timeout' => 5, // 5 seconds
    'throw_exceptions' => true, // Throw exceptions
];

Usage

Fetching Data

You can fetch data by using the main class of the package:

use Truncgil\Finance\Finance;

$finance = new Finance();
$data = $finance->getRates();

Example Output:

{
    "USD": {
        "Type": "Currency",
        "Change": 0.16,
        "Name": "Amerikan Doları",
        "Buying": 35.6896,
        "Selling": 35.6942
    },
    "EUR": {
        "Type": "Currency",
        "Change": 0.45,
        "Name": "Euro",
        "Buying": 37.3753,
        "Selling": 37.3873
    }
    // ... other currencies
}

Fetches the current exchange rates for all currencies.

Fetching a Specific Currency

To fetch a specific currency, you can use the getCurrency method:

$currency = $finance->getCurrency('USD'); // Get USD currency data

Example Output:

{
    "Type": "Currency",
    "Change": 0.16,
    "Name": "Amerikan Doları",
    "Buying": 35.6896,
    "Selling": 35.6942
}

Fetches the data for the specified currency (e.g., USD).

Fetching Gold Prices

To fetch gold prices, you can use the getGold method:

$gold = $finance->getGold(); // Get all gold data

Example Output:

{
    "GRA": {
        "Type": "Gold",
        "Name": "GRAMALTIN",
        "Buying": 3192.08,
        "Selling": 3192.59,
        "Change": 1.19
    },
    "GUM": {
        "Type": "Gold",
        "Name": "GUMUS",
        "Buying": 35.44,
        "Selling": 35.49,
        "Change": 1.58
    }
    // ... other gold types
}

Fetches the current prices for gold types.

Fetching Cryptocurrency Data

To fetch cryptocurrency data, you can use the getCryptoCurrency method:

$crypto = $finance->getCryptoCurrency('BTC'); // Get BTC data

Example Output:

{
    "Name": "Bitcoin",
    "USD_Price": 105184,
    "TRY_Price": 3747780,
    "Selling": 3747780,
    "Change": 3.17
}

Fetches the current data for the specified cryptocurrency (e.g., Bitcoin).

Fetching Data by Code or Name

You can use the get method to fetch data by a specific code or name:

$item = $finance->get('Bitcoin'); // Get Bitcoin data

Example Output:

{
    "Name": "Bitcoin",
    "USD_Price": 105184,
    "TRY_Price": 3747780,
    "Selling": 3747780,
    "Change": 3.17
}

Fetches data for a specific item by its code or name.

Refreshing Data

To clear the cache and refresh the data, you can use the refreshData method:

$updatedData = $finance->refreshData(); // Refresh data

Example Output:

{
    "status": "success",
    "message": "Data refreshed successfully."
}

Clears the cache and fetches the latest data from the API.

Error Handling

If the API request fails, error handling is done automatically. The Log class is used to log errors. If the throw_exceptions setting is set to true, an exception will be thrown.

License

This package is licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-01-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固