PHPackages                             peter-wan/idcard - 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. [Validation &amp; Sanitization](/categories/validation)
4. /
5. peter-wan/idcard

ActiveLibrary[Validation &amp; Sanitization](/categories/validation)

peter-wan/idcard
================

根据提供的身份证号码，检测身份证号码是或否正确，以及解读身份证号码中所包含的年龄、地域等信息

1.0.6(6y ago)1181MITPHPPHP &gt;=5.3.0CI failing

Since Mar 7Pushed 6y ago1 watchersCompare

[ Source](https://github.com/PerterWan/idcard)[ Packagist](https://packagist.org/packages/peter-wan/idcard)[ Docs](https://github.com/PerterWan/idcard)[ RSS](/packages/peter-wan-idcard/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (5)Dependencies (1)Versions (4)Used By (0)

Vitale.Wang API idcard PHP Client 身份号码信息解析
==========================================

[](#vitalewang-api-idcard-php-client-身份号码信息解析)

这是Vitale.Wang API的PHP版本封装开发包，由Vitale.Wang提供，一般支持最新的 API 功能。

> 支持的 PHP 版本: 5.3.3 ～ 5.6.x, 7.0.x

Installation
------------

[](#installation)

#### 使用 Composer 安装

[](#使用-composer-安装)

- 在项目中的 `composer.json` 文件中添加 Organize 依赖：

```
{
  "require": {
     "peter-wan/idcard": "dev-master"
  }
}
```

- 执行 `$ php composer.phar install` 或 `$ composer install` 进行安装。

#### 直接下载源码安装

[](#直接下载源码安装)

> 直接下载源代码也是一种安装 SDK 的方法，不过因为有版本更新的维护问题，所以这种安装方式**十分不推荐**，但由于种种原因导致无法使用 Composer，所以我们也提供了这种情况下的备选方案。

- 下载源代码包，解压到项目中
- 在项目中引入 autoload：

```
require 'path_to_sdk/autoload.php';
```

#### 初始化

[](#初始化)

```
use \Idcard\IdcardInit as Idcard;
...
...

    $idcardObj = new Idcard('11xxxxxxxxxxxxxxxx');

...
```

OR

```
$idcardObj = new \Idcard\IdcardInit('11xxxxxxxxxxxxxxxx');
```

### 检查身份证是否生效，生效返回TRUE，失效情况下在初始化阶段抛出异常

[](#检查身份证是否生效生效返回true失效情况下在初始化阶段抛出异常)

```
  $check = $idcardObj->getParams("check");
```

### 判端性别

[](#判端性别)

```
  //可自定义返回性别值
  $gender = $idcardObj->gender()->getGender($male = '男', $female = '女');
```

### 获取年龄、出生年月、生肖、星座

[](#获取年龄出生年月生肖星座)

```
  $birthdayObj = $idcardObj->birth()->getIdCardBirthInfo();
  //年龄
  $age = $birthdayObj->age;
  //出生年月日
  $birthday = $birthdayObj->birthday;
  //出生年份
  $year = $birthdayObj->birthday_year;
  //出生月份
  $month = $birthdayObj->birthday_month;
  //出生日
  $day = $birthdayObj->birthday_day();
  //生肖
  $ChineseZodiac = $birthdayObj->chinese_zodiac();
  //星座
  $Constellation = $birthdayObj->constellation;
```

### 获取地域信息

[](#获取地域信息)

```
  //获取省份：河北省
  $province = $idcard->getArea()->getProvince();
  //获取城市：河北省石家庄市
  $city = $idcard->getArea()->getCity();
  //获取详细地址信息
  $area = $idcard->getArea()->getArea();
```

### 身份证工具

[](#身份证工具)

```
    //补全15位身份证号码
    $newIdcard = $idcardObj->tools()->get18LengthFrom15Length();
    //隐藏位数 1333***********1111 可自定义隐藏替代字符，左右值为非负整数，$left + $right =0
    $format = $idcardObj->tools()->getIdcardFormat($format = '*', $left = 4, $right = 4);
```

Contributing
------------

[](#contributing)

Bug reports and pull requests are welcome on GitHub at

License
-------

[](#license)

The library is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity9

Limited adoption so far

Community8

Small or concentrated contributor base

Maturity60

Established project with proven stability

 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 ~358 days

Total

3

Last Release

2273d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/887b5d4de3b7e05e55a36c6207e964ed5fb9361400fbb44a063526862f2caa6c?d=identicon)[HowieBird](/maintainers/HowieBird)

---

Top Contributors

[![wysszetz](https://avatars.githubusercontent.com/u/16575495?v=4)](https://github.com/wysszetz "wysszetz (24 commits)")

---

Tags

areaChinaageidcard

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/peter-wan-idcard/health.svg)

```
[![Health](https://phpackages.com/badges/peter-wan-idcard/health.svg)](https://phpackages.com/packages/peter-wan-idcard)
```

###  Alternatives

[webmozart/assert

Assertions to validate method input/output with nice error messages.

7.6k894.0M1.2k](/packages/webmozart-assert)[bensampo/laravel-enum

Simple, extensible and powerful enumeration implementation for Laravel.

2.0k15.9M104](/packages/bensampo-laravel-enum)[swaggest/json-schema

High definition PHP structures with JSON-schema based validation

48612.5M73](/packages/swaggest-json-schema)[stevebauman/purify

An HTML Purifier / Sanitizer for Laravel

5325.6M19](/packages/stevebauman-purify)[ashallendesign/laravel-config-validator

A package for validating your Laravel app's config.

217905.3k5](/packages/ashallendesign-laravel-config-validator)[crazybooot/base64-validation

Laravel validators for base64 encoded files

1341.9M8](/packages/crazybooot-base64-validation)

PHPackages © 2026

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