wisonlau/identity-card

中华人民共和国居民身份证的简单证明。

dev-master 2018-07-05 03:20 UTC

This package is not auto-updated.

Last update: 2024-09-21 09:55:40 UTC


README


中国(大陆)身份证包,数据来源于国家标准 GB/T 2260-2007 (中华人民共和国行政区划代码标准)。

安装

    composer require wisonlau/identity-card

说明

基于中华人民共和国公民身份证获取用户信息的一个组件。适用于任何PHP框架,但仅当PHP版本大于7.1时。

使用

验证您的中国身份证

    // Result false OR Ofcold\IdentityCard\IdentityCard instance.
    $result = Ofcold\IdentityCard\IdentityCard::make('32010619831029081');

    if ( $result === false ) {

        return 'Your ID number is incorrect';
    }

    print_r($result->toArray());

或测试文件。

    php test
$idCard = Ofcold\IdentityCard\IdentityCard::make('320106198310290811', 'en');
//  Use locale, Current supported zh-cn,en
// $idCard = Ofcold\IdentityCard\IdentityCard::make('320106198310290811', 'zh-cn');
if ( $idCard === false ) {

    return 'Your ID number is incorrect';
}
$area = $idCard->getArea();
$gender = $idCard->getGender();
$birthday = $idCard->getBirthday();
$age = $idCard->getAge();
$constellation = $idCard->getConstellation();

结果

{
    "area": "shan xi sheng yun cheng di qu yun cheng shi",
    "province": "shan xi sheng",
    "city": "yun cheng di qu",
    "county": "yun cheng shi",
    "gender": "Male",
    "birthday": "1980-03-12",
    "zodiac": "Pig",
    "age": 38,
    "constellation": "Pisces"
}

API

  • getArea() : string 获取地区
  • getConstellation() : string 获取星座
  • getZodiac() : string 获取生肖
  • getAge() : int 获取年龄
  • getBirthday(string $format = 'Y-m-d') : string 获取生日
  • getGender() : string 获取性别
  • getCounty() : string|null 获取县
  • getCity() : string|null 获取市
  • getProvince() : string|null 获取省
  • toArray() : array 获取所有信息。
  • toJson(int $option) : string 以Json格式获取所有信息
  • __get() : mixed
  • __toString() : toJson