• This repository has been archived on 23/Feb/2023
  • Stars
    star
    175
  • Rank 218,059 (Top 5 %)
  • Language
    PHP
  • License
    MIT License
  • Created over 6 years ago
  • Updated almost 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🆔一个基于「公民身份号码」规则获取身份证号码中包含的基础信息组件(PHP)

Identity Card Of China (PHP)

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

Build Status

JavaScript 版本:https://github.com/medz/id-card-of-china-js

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

安装

  • 你的 PHP 版本应该 >= 7.0

我们使用 Composer 安装:

composer require medz/id-card-of-china

使用

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

use Medz\IdentityCard\China\Identity;

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

APIs

基于 Medz\IdentityCard\China\IdentityInterface 实例

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

region 对象 APIs

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

演示

use Medz\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

This component follows the MIT open source agreement.

More Repositories

1

prisma-dart

Prisma Client Dart is an auto-generated type-safe ORM. It uses Prisma Engine as the data access layer and is as consistent as possible with the Prisma Client JS/TS APIs.
Dart
448
star
2

cors

🔮Supported(Laravel/Lumen/PSR-15/Swoft/Slim/ThinkPHP) - PHP CORS (Cross-origin resource sharing) middleware.
PHP
274
star
3

OvO

OvO is a Dart-first schema declaration and validation library.
Dart
179
star
4

gbt2260

🇨🇳中华人民共和国国家标准 GB/T 2260 行政区划代码
kvlang
105
star
5

laravel-jpush-notification-channel

Jpush notification channel for Laravel 5.5+ / 极光推送 Laravel 驱动
PHP
44
star
6

spry

Spry -A lightweight, composable Dart web framework designed to work collaboratively with various runtime platforms.
Dart
30
star
7

id-card-of-china-js

一个基于「公民身份身份号码」规则获取身份证号码中包含的基础信息组件(JS)
TypeScript
28
star
8

webpack-laravel-mix-manifest

🐶A webpack plugin that generates Laravel framework compatible mix-manifest.josn file.
TypeScript
26
star
9

prisma-library

Bind the Prisma ORM query engine to any programming language you like ❤️
Rust
20
star
10

napi-dart

Dart
14
star
11

numeral.dart

A Dart library for Format number into beautiful string, Format the number into a beautiful, readable and short string.
Dart
10
star
12

qq-emoicon

目前最新的QQ表情资源。
PHP
10
star
13

oss-stream-wrapper

Aliyun OSS support streamWrapper. (&Aliyun OSS SDK for PHP.) 支持OSS自定义流协议操作。
PHP
7
star
14

webfetch

A Dart implementation of the Web Fetch API that allows you to make requests and process results just like using fetch in a browser.
Dart
7
star
15

emoji-format

原生emoji表情格式化为base64代码和反解析为emoji工具
PHP
5
star
16

gib

📝Blog creation using GitHub issues, built by Vue.js
JavaScript
5
star
17

routingkit

🛸 Routing Kit - Lightweight and fast router for Dart.
Dart
4
star
18

thinksns-installer

The ThinkSNS-Installer is ThinkSNS 4 version installed library.
PHP
3
star
19

geohash

Longitude and Latitude Geo Hash Library.
PHP
3
star
20

stream-wrapper-interface

Common interface for streamWrapper class.
PHP
2
star
21

laravel-tencent-cloud-sms-notification-channel

腾讯云短信通知驱动
PHP
2
star
22

aliyun-oss

Aliyun OSS SDK for PHP. (&Support streamWrapper) 支持自定义流协议操作。
PHP
1
star
23

composer-vendor-install-folders

Allows components custom folders installed.
PHP
1
star
24

medz

Seven's profile website
TypeScript
1
star
25

create-order-length-php

PHP
1
star
26

public

Seven's public files.
TypeScript
1
star
27

consolekit

$ Console Kit is a tool for creating interactive CLI applications.
Dart
1
star
28

oh

Dart
1
star
29

blog-server-with-dart

Binding a REST of Blog with Dart (Spry + Prisma)
Dart
1
star