PHPackages                             jimchen/id-card-of-china - 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. jimchen/id-card-of-china

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

jimchen/id-card-of-china
========================

中华人民共和国身份证（The identity card of the people's Republic of China）

v1.0.0(7y ago)11.2kMITPHPPHP &gt;=5.5

Since Jul 30Pushed 7y ago1 watchersCompare

[ Source](https://github.com/JimChenWYU/id-card-of-china)[ Packagist](https://packagist.org/packages/jimchen/id-card-of-china)[ RSS](/packages/jimchen-id-card-of-china/feed)WikiDiscussions master Synced yesterday

READMEChangelogDependencies (2)Versions (2)Used By (0)

Identity Card Of China (PHP)
============================

[](#identity-card-of-china-php)

中华人民共和国身份证（The identity card of the people's Republic of China）

[![Build Status](https://camo.githubusercontent.com/3de0721ab997e0e7a75435a0baff6b5238d90017cdf505e2ee6d6fa313ff3653/68747470733a2f2f7777772e7472617669732d63692e6f72672f4a696d4368656e5759552f69642d636172642d6f662d6368696e612e7376673f6272616e63683d6d6173746572)](https://travis-ci.com/JimChenWYU/id-card-of-china)

> JavaScript 版本：

`id-card-of-china` 是一个基于「公民身份号码」规则获取公民身份号码中包含的基础信息组件。

安装
--

[](#安装)

- 你的 PHP 版本应该 `>= 5.5`

我们使用 Composer 安装：

```
composer require jimchen/id-card-of-china
```

使用
--

[](#使用)

遵循 PHP-MD 原则，这个工具不提供静态调用，所以使用需要进行对象实例化：

```
use JimChen\IdentityCard\China\Identity;

$peopleIDNumber = '350301198906180060';
$peopleIdentity = new Identity($peopleIDNumber);
```

APIs
----

[](#apis)

> 基于 `JimChen\IdentityCard\China\IdentityInterface` 实例

- `legal`：检查公民身份号码是否合法
- `birthday`：获取公民身份号码中包含的生日信息
- `gender`：获取身份证包含的性别信息
- `region`: 获取身份证包含的地区信息，返回 `JimChen\IdentityCard\China\Region\RegionInterface` 实例

### `region` 对象 APIs

[](#region-对象-apis)

- `code`： 获取 GB/T 2260 的地区行政代码
- `province`：获取省份名称或者直辖市名称
- `city`：获取城市名称，如果是直辖市则返回 `''`
- `county`：获取区县名称
- `tree`：获取地区层级数组
- `treeString`：获取地区完整字符串，支持传递一个参数作为省市区的分隔符

### 演示

[](#演示)

```
use JimChen\IdentityCard\China\Identity;

$peopleIDNumber = '350302198906180060';
$peopleIdentity = new Identity($peopleIDNumber);
$peopleRegion = $peopleIdentity->region();

var_dump(
    $peopleIdentity->legal(),    // true | false
    $peopleIdentity->birthday(), // 1989-06-18
    $peopleIdentity->gender(),   // 女 | 男
    $peopleRegion->code(),       // 350302
    $peopleRegion->province(),   // 福建省
    $peopleRegion->city(),       // 莆田市
    $peopleRegion->county(),     // 城厢区
    $peopleRegion->tree(),       // ["福建省", "莆田市", "城厢区"]
    $peopleRegion->treeString(' ') // 福建省 莆田市 城厢区
);
```

疑问解答
----

[](#疑问解答)

1. 问：为什么不添加年龄、星座还有属相等信息？

    答：因为年龄需要专门的时间组件去计算，星座如果是「粗略」计算可以获得，但是没有意义，属相更加复杂，负责任的转换这些属性都比简单转换复杂，简单转换出来的不够准确。同样也失去了包本身该有的功能，例如年龄可以交给「时间组件」等。
2. 问：这个包到底干啥的？

    答：这个包就是提取公民身份号码所包含的基础信息
3. 问：可以用来验证人或者其他的吗？

    答：不基于公安部的 API 验证的身份证组件都不能叫验证组件，现在所有的 ID Card 组件都只能提取公民身份号码所包含的信息，如果说验证，那唯一能验证的就是公民身份号码是否是一个合法的公民身份号码。
4. 问：如何获取年龄？ 答：例如在 PHP 中，获取年龄是一个很简单的时区，我用最快的例子，你依赖 `nesbot/carbon` 这个「时间工具」包，依赖代码：

    ```
    composer require nesbot/carbon
    ```

    然后看我下面的 PHP 代码：

    ```
    use Carbon\Carbon;
    $birthday = new Carbon($identity->birthday());
    $age = $birthday->diffInYears();
    ```

    好了，你打印下 `$age` 试试看！

LICENSE
-------

[](#license)

This component follows the MIT open source agreement.

###  Health Score

28

—

LowBetter than 54% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity16

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity57

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

Unknown

Total

1

Last Release

2843d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/20cebafc45fd6fc5f67bf655119a3b27e9b208e248f2d7f5c98fd6c0a101485b?d=identicon)[jimchen](/maintainers/jimchen)

---

Top Contributors

[![medz](https://avatars.githubusercontent.com/u/5564821?v=4)](https://github.com/medz "medz (20 commits)")

---

Tags

identitycardidChina

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/jimchen-id-card-of-china/health.svg)

```
[![Health](https://phpackages.com/badges/jimchen-id-card-of-china/health.svg)](https://phpackages.com/packages/jimchen-id-card-of-china)
```

###  Alternatives

[cybercog/laravel-optimus

An Optimus bridge for Laravel. Id obfuscation based on Knuth's multiplicative hashing method.

192564.1k](/packages/cybercog-laravel-optimus)[alicfeng/identity-card

IdentityCard Library

1228.5k](/packages/alicfeng-identity-card)[pugx/shortid-php

An implementation of shortid in PHP

52588.5k3](/packages/pugx-shortid-php)[douyasi/identity-card

Chinese Identity Card package

17851.4k3](/packages/douyasi-identity-card)[medz/gb-t-2260

中华人民共和国国家标准 GB/T 2260 行政区划代码

10663.6k5](/packages/medz-gb-t-2260)[ericlagarda/nova-text-card

A custom card for Laravel Nova to show Text in cards with some good options

20388.6k2](/packages/ericlagarda-nova-text-card)

PHPackages © 2026

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