PHPackages                             reaway/boc-cny-quote - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. reaway/boc-cny-quote

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

reaway/boc-cny-quote
====================

Bank of China CNY quote

v1.0.0(3mo ago)05Apache-2.0PHPPHP &gt;=8.1

Since Mar 28Pushed 3mo agoCompare

[ Source](https://github.com/reaway/boc-cny-quote)[ Packagist](https://packagist.org/packages/reaway/boc-cny-quote)[ Docs](https://github.com/reaway/boc-cny-quote)[ RSS](/packages/reaway-boc-cny-quote/feed)WikiDiscussions main Synced 3w ago

READMEChangelog (2)Dependencies (10)Versions (3)Used By (0)

BocCnyQuote
===========

[](#boccnyquote)

[![PHP Version](https://camo.githubusercontent.com/04744bae0a61d2ffe29c26f07a9612eae20445fc6feaeb77b3af1f0e9be6447c/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f7068702d253345253344382e312d3838393242462e737667)](https://www.php.net/)[![License](https://camo.githubusercontent.com/798509b4df525f56802b56f8096862487f08023e3d7561c68656f8dab10d0d6e/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f6c6963656e73652d4170616368652d2d322e302d626c75652e737667)](https://github.com/reaway/boc-cny-quote/blob/main/LICENSE)

一个用于获取中国银行人民币汇率数据的 PHP 库，支持多种数据源（桌面版网页、移动版网页、微信小程序、聚合数据 API）。

功能特性
----

[](#功能特性)

- 支持多种数据源：
    - `desktop` - 中国银行桌面版网页（默认）
    - `mobile` - 中国银行移动版网页
    - `we_chat_mini_program` - 中国银行微信小程序接口
    - `juhe` - 聚合数据 API（需要申请 API Key）
- 支持门面（Facade）模式调用
- 支持获取所有汇率或指定货币汇率
- 支持现汇买入价、现钞买入价、现汇卖出价、现钞卖出价、中行折算价

安装
--

[](#安装)

```
composer require reaway/boc-cny-quote
```

环境要求
----

[](#环境要求)

- PHP &gt;= 8.1
- 扩展：bcmath、dom、mbstring

支持的货币
-----

[](#支持的货币)

货币代码货币名称货币代码货币名称AED阿联酋迪拉姆AUD澳大利亚元BND文莱元BRL巴西雷亚尔CAD加拿大元CHF瑞士法郎CZK捷克克朗DKK丹麦克朗EUR欧元GBP英镑HKD港币HUF匈牙利福林IDR印尼卢比ILS以色列谢克尔INR印度卢比JPY日元KHR柬埔寨瑞尔KRW韩国元KWD科威特第纳尔MNT蒙古图格里克MOP澳门元MXN墨西哥比索MYR林吉特NOK挪威克朗NPR尼泊尔卢比NZD新西兰元PHP菲律宾比索PKR巴基斯坦卢比QAR卡塔尔里亚尔RSD塞尔维亚第纳尔RUB卢布SAR沙特里亚尔SEK瑞典克朗SGD新加坡元THB泰国铢TRY土耳其里拉TWD新台币USD美元VND越南盾ZAR南非兰特使用方法
----

[](#使用方法)

### 基础用法

[](#基础用法)

```
use BocCnyQuote\CnyQuote;

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

$config = [
    'default' => '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);
```

### 使用门面（Facade）

[](#使用门面facade)

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

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

$config = [
    'default' => 'desktop',
    'sources' => [
        'juhe' => [
            '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);
```

配置说明
----

[](#配置说明)

配置项类型说明defaultstring默认数据源驱动，可选值：desktop、mobile、we\_chat\_mini\_program、juhesources.juhe.keystring聚合数据 API 访问密钥（仅在 juhe 驱动时需要）数据源说明
-----

[](#数据源说明)

### desktop（桌面版网页）

[](#desktop桌面版网页)

- 数据源：中国银行官网桌面版
- 特点：数据完整，无需 API Key
- URL：

### mobile（移动版网页）

[](#mobile移动版网页)

- 数据源：中国银行官网移动版
- 特点：数据完整，无需 API Key
- URL：[https://www.boc.cn/sourcedb/whpj/sjmfx\_1621.html](https://www.boc.cn/sourcedb/whpj/sjmfx_1621.html)

### we\_chat\_mini\_program（微信小程序）

[](#we_chat_mini_program微信小程序)

- 数据源：中国银行微信小程序接口
- 特点：数据实时，无需 API Key

### juhe（聚合数据）

[](#juhe聚合数据)

- 数据源：聚合数据 API
- 特点：需要申请 API Key
- URL：
- 申请地址：

返回数据格式
------

[](#返回数据格式)

```
[
    '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', // 发布时间
    ],
    // ... 其他货币
]
```

API 方法
------

[](#api-方法)

### CnyQuote 类

[](#cnyquote-类)

方法说明`getQuotes(): array`获取所有人民币汇率数据`getQuote(string $currency): array|null`获取指定货币的人民币汇率`source(string|null $name): CnyQuoteAbstract`获取指定驱动实例`getResponse(): string`获取数据源响应内容（原始数据）`getSourceUrl(): string`获取数据源 URL许可证
---

[](#许可证)

Apache-2.0 License. 详情请查看 [LICENSE](LICENSE) 文件。

###  Health Score

36

—

LowBetter than 79% of packages

Maintenance82

Actively maintained with recent releases

Popularity4

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity44

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~10 days

Total

2

Last Release

91d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/d342ebe348631bdfbe41ebcd414f0b5fa2334027d413e3543afb301f3503a13f?d=identicon)[reaway](/maintainers/reaway)

---

Top Contributors

[![reaway](https://avatars.githubusercontent.com/u/60423559?v=4)](https://github.com/reaway "reaway (1 commits)")

### Embed Badge

![Health badge](/badges/reaway-boc-cny-quote/health.svg)

```
[![Health](https://phpackages.com/badges/reaway-boc-cny-quote/health.svg)](https://phpackages.com/packages/reaway-boc-cny-quote)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
