Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/missuo/IDCard-Verify

China's second-generation ID card verification and analysis
https://github.com/missuo/IDCard-Verify

idcard idcard-check idcard-china

Last synced: 12 days ago
JSON representation

China's second-generation ID card verification and analysis

Awesome Lists containing this project

README

        

# IDCard-Verify
China's second-generation ID card verification and analysis

# Feature
- [X] Correctness Recognition
- [X] Region Identification
- [X] Date of Birth Recognition
- [X] Constellation Recognition
- [X] Gender Recognition

# How to Use
```
https://iij.asia/idcard?id=1021321999010112232
```
**Just need to send a POST or GET request to the above interface.**

## Correct return
```json
{
"code": 200,
"verify": "核验通过",
"idcard": "33041120010402####",
"address": "浙江省嘉兴市秀洲区",
"constellations": "白羊座",
"birthday": "2001年4月2日",
"gender": "女",
"author": "Vincent Young",
"contact": "https://t.me/missuo"
}
```

# Programming environment
- CentOS 7.9
- PHP 7.3
- Nginx 1.17
- MySQL 5.6
- Python 3.7

# Build Instructions
## Need to have a database to store address number information
```python
import re
import pymysql

db = pymysql.connect(host="localhost",user="root",password="root2021",db="idcard",charset='utf8',port=3306)
cur = db.cursor()

def insert(num,add):
sql = "insert into fullinfo(numid,address) values('%s', '%s')"%(num,add)
try:
cur.execute(sql)
db.commit()
except Exception as e:
print("Insert error:", e)
db.rollback()
cur.close()

filename = r'/root/id'
f = open (filename, 'r', encoding='gb18030')
line = f.readline()
count = 1
while line:
try:
txt = re.split(r' ', line)
num = str(txt[0])
add = str(txt[1])
insert(num, add)
print("Inserting No.",count," Data")
line = f.readline()
count+=1
except Exception as e:
print(e)
db.close()

```
## Use PHP7 to receive and extract key information to identify
```php
query($sql);
if ($res -> num_rows > 0) {
$row = mysqli_fetch_array($res);
$address = $row['address'];
}else{
$address = '未知地区';
}
$address = str_replace("\n","",$address);
$birth_code = substr($id,6,8);
$birth_year = substr($birth_code,0,4);
$birth_month = preg_replace('/^0+/','',substr($birth_code,4,2));
$birth_day = preg_replace('/^0+/','',substr($birth_code,6,2));
$constellations = get_constellation($birth_month,$birth_day);
$sex_code = substr($id,16,1);
if($sex_code % 2 == 0){
$sex = '女';
}else{
$sex = '男';
}
$info = array(
'code' => 200,
'verify' => '核验通过',
'idcard' => $id,
'address' => $address,
'constellations' => $constellations,
'birthday' => $birth_year.'年'.$birth_month.'月'.$birth_day.'日',
'gender' => $sex,
'author' => 'Vincent Young',
'contact' => 'https://t.me/missuo'
);
}else{
$info = array(
'code' => 500,
'verify' => '核验失败',
'idcard' => $id,
'author' => 'Vincent Young',
'contact' => 'https://t.me/missuo'
);
}
echo json_encode($info,JSON_PRETTY_PRINT|JSON_UNESCAPED_UNICODE|JSON_UNESCAPED_SLASHES);
?>
```