PHP code example of reaway / boc-cny-quote

1. Go to this page and download the library: Download reaway/boc-cny-quote library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

reaway / boc-cny-quote example snippets


use BocCnyQuote\CnyQuote;

 => 'desktop', // 默认驱动:desktop、mobile、we_chat_mini_program、juhe
    'sources' => [
        'juhe' => [
            'key' => 'your-api-key', // 聚合数据 API 访问密钥
        ],
    ],
];

$cnyQuote = new CnyQuote($config);

// 获取所有汇率
$quotes = $cnyQuote->getQuotes();
var_dump($quotes);

// 获取指定货币的汇率
$usdQuote = $cnyQuote->getQuote('USD');
var_dump($usdQuote);

// 切换到其他数据源
$mobileQuotes = $cnyQuote->source('mobile')->getQuotes();
var_dump($mobileQuotes);

use BocCnyQuote\Facade\CnyQuoteFacade;
use Think\Component\Config\Facade\ConfigFacade;

     'key' => 'your-api-key',
        ],
    ],
];
ConfigFacade::set($config, 'boc_cny_quote');

// 获取所有汇率
$quotes = CnyQuoteFacade::getQuotes();
var_dump($quotes);

// 获取指定货币的汇率
$usdQuote = CnyQuoteFacade::getQuote('USD');
var_dump($usdQuote);

// 切换数据源
$mobileQuotes = CnyQuoteFacade::source('mobile')->getQuotes();
var_dump($mobileQuotes);

[
    'USD' => [
        'currency_name' => '美元',           // 货币名称
        'currency_code' => 'USD',           // 货币代码
        'exchange_buy' => 723.45,           // 现汇买入价
        'cash_buy' => 717.89,               // 现钞买入价
        'exchange_sell' => 726.59,          // 现汇卖出价
        'cash_sell' => 726.59,              // 现钞卖出价
        'bank_conversion' => 724.52,        // 中行折算价
        'publish_time' => '2024-01-15 09:30:00', // 发布时间
    ],
    // ... 其他货币
]