EST系列身份证阅读器读卡器Python语言二次开发demo上线
人工智能的兴起,最近这段时间碰到很多开发工程师咨询Python语言二次开发使用身份证阅读器的问题,这次特增加了Python语言的demo,供大家参考使用。
Python读取身份证示例图
1.说明:
appMain.py为程序主文件,运行工程源程序必须安装python3+PyQt5运行环境,依赖库dll必须与源程序同一路径。
2.命令行中执行:
python3 appMain.py
3.支持的型号:
EST-100、EST-100GS、EST-100G、EST-100U、EST-200G、EST-J13X等系列身份证社保卡读卡器
4、开发包下载地址:
http://www.eastcoms.com/service/downdrive/561.html
Python部分代码:
#-*- coding : utf-8-*-
import sys
from ctypes import *
id_dev_name = b"USB1"
dll_path = './est64.dll'
id_image_path = './zp.bmp'
pBmpFile = c_char_p(b'/0'*100)
#pFingerData = c_char_p(b'/0'*1025)
#pBmpData = c_char_p(b'/0'*77725)
#pBase64Data = c_char_p(b'/0'*6025)
pName = c_char_p(b'/0'*100)
pSex = c_char_p(b'/0'*100)
pNation = c_char_p(b'/0'*100)
pBirth = c_char_p(b'/0'*100)
pAddress = c_char_p(b'/0'*100)
pCertNo = c_char_p(b'/0'*100)
pDepartment = c_char_p(b'/0'*100)
pEffectData = c_char_p(b'/0'*100)
pExpire = c_char_p(b'/0'*100)
pData = c_char_p(b'/0'*100)
pErrMsg = c_char_p(b'/0'*100)
pTXZHM = c_char_p(b'/0'*100)
pTXZQFCS = c_char_p(b'/0'*100)
pEnName = c_char_p(b'/0'*200)
pEnNation = c_char_p(b'/0'*100)
pAuthorCode = c_char_p(b'/0'*100)
pCardVersion = c_char_p(b'/0'*100)
pErrMsg = c_char_p(b'/0'*100)
class idreader(object):
def __init__(self, parent=None):
self.dev_name = c_char_p(id_dev_name)
self.id_dev = CDLL(dll_path)
self.id_handle = self.id_dev.EU_Reader_Open(self.dev_name)
def get_msg(self):
global pBmpFile,pName,pSex,\
pNation,pBirth,pAddress,pCertNo,pDepartment,pEffectData,\
pExpire,pData,pErrMsg,pTXZHM,pTXZQFCS,pEnName,pEnNation,\
pAuthorCode,pCardVersion
#pFingerData,pBmpData,pBase64Data,
pBmpFile.value = bytes(id_image_path,encoding="utf8")
id_msg_str = ""
self.id_handle = self.id_dev.EU_Reader_Open(self.dev_name)
if self.id_handle <= 0:
print('reader port open failure.')
return (self.id_handle,)
sUID = c_char_p(b'/0'*30)
self.id_dev.PEU_Reader_ID_ReadUID(self.id_handle, sUID)
ret = self.id_dev.PEU_Reader_ReadIDCard(self.id_handle, pErrMsg)
if ret == 0:
idcardType = int(-1)
idcardType = self.id_dev.GetCardType()
if idcardType == 0:
id_msg_str = "证件类型:居民身份证" + "\r\n"
self.id_dev.GetName(pName)
id_msg_str += "姓名:" + str(pName.value,encoding='gbk') + "\r\n"
self.id_dev.GetSex(pSex)
id_msg_str += "性别:" + str(pSex.value,encoding='gbk') + "\r\n"
self.id_dev.GetNation(pNation)
id_msg_str += "民族:" + str(pNation.value,encoding='gbk') + "\r\n"
self.id_dev.GetBirth(pBirth)
id_msg_str += "出生日期:" + str(pBirth.value,encoding='gbk') + "\r\n"
self.id_dev.GetAddress(pAddress)
id_msg_str += "住址:" + str(pAddress.value,encoding='gbk').strip() + "\r\n"
self.id_dev.GetCertNo(pCertNo)
id_msg_str += "身份证号码:" + str(pCertNo.value,encoding='gbk') + "\r\n"
self.id_dev.GetDepartemt(pDepartment)
id_msg_str += "签发机关:" + str(pDepartment.value,encoding='gbk') + "\r\n"
self.id_dev.GetEffectDate(pEffectData)
id_msg_str += "有效起始日期:" + str(pEffectData.value,encoding='gbk') + "\r\n"
self.id_dev.GetExpireDate(pExpire)
id_msg_str += "有效截止日期:" + str(pExpire.value,encoding='gbk') + "\r\n"
elif idcardType == 1:
id_msg_str = "证件类型:外国人永久居留证" + "\r\n"
self.id_dev.GetName(pName)
id_msg_str += "中文姓名:" + str(pName.value,encoding='gbk') + "\r\n"
self.id_dev.GetEnName(pEnName)
id_msg_str += "英文姓名:" + str(pEnName.value,encoding='gbk')
self.id_dev.GetSex(pSex)
id_msg_str += "性别:" + str(pSex.value,encoding='gbk')
self.id_dev.GetNationalityCode(pEnNation)
id_msg_str += "国籍代码:" + str(pEnNation.value,encoding='gbk') + "\r\n"
self.id_dev.GetBirth(pBirth)
id_msg_str += "出生日期:" + str(pBirth.value,encoding='gbk') + "\r\n"
self.id_dev.GetCertNo(pCertNo)
id_msg_str += "永久证号码:" + str(pCertNo.value,encoding='gbk') + "\r\n"
self.id_dev.GetEffectDate(pEffectData)
id_msg_str += "有效起始日期:" + str(pEffectData.value,encoding='gbk') + "\r\n"
self.id_dev.GetExpireDate(pExpire)
id_msg_str += "有效截止日期:" + str(pExpire.value,encoding='gbk') + "\r\n"
elif idcardType == 2:
id_msg_str = "证件类型:港澳台居民居住证" + "\r\n"
self.id_dev.GetName(pName)
id_msg_str += "姓名:" + str(pName.value,encoding='gbk') + "\r\n"
self.id_dev.GetSex(pSex)
id_msg_str += "性别:" + str(pSex.value,encoding='gbk') + "\r\n"
self.id_dev.GetBirth(pBirth)
id_msg_str += "出生日期:" + str(pBirth.value,encoding='gbk') + "\r\n"
self.id_dev.GetCertNo(pCertNo)
id_msg_str += "身份证号码:" + str(pCertNo.value,encoding='gbk') + "\r\n"
self.id_dev.GetAddress(pAddress)
id_msg_str += "住址:" + str(pAddress.value,encoding='gbk').strip() + "\r\n"
self.id_dev.GetDepartemt(pDepartment)
id_msg_str += "签发机关:" + str(pDepartment.value,encoding='gbk') + "\r\n"
self.id_dev.GetEffectDate(pEffectData)
id_msg_str += "有效起始日期:" + str(pEffectData.value,encoding='gbk') + "\r\n"
self.id_dev.GetExpireDate(pExpire)
id_msg_str += "有效截止日期:" + str(pExpire.value,encoding='gbk') + "\r\n"
self.id_dev.GetTXZHM(pTXZHM)
id_msg_str += "通行证号码:" + str(pTXZHM.value,encoding='gbk') + "\r\n"
self.id_dev.GetTXZQFCS(pTXZQFCS)
id_msg_str += "通行证签发次数:" + str(pTXZQFCS.value,encoding='gbk') + "\r\n"
else:
print("id card read failure.")
return (idcardType,)
img = self.id_dev.GetBmpFile(pBmpFile);
self.id_dev.EU_PosBeep(self.id_handle, 0x30);
return (ret,id_msg_str,img,id_image_path)
else:
print('PEU_Reader_ReadIDCard error.')
return (ret,)
def get_uid(self):
uid_pstr = c_char_p(b'/0'*20)
self.id_handle = self.id_dev.EU_Reader_Open(self.dev_name)
ret = self.id_dev.PEU_Reader_ID_ReadUID(self.id_handle,uid_pstr)
if ret == 0:
self.id_dev.EU_PosBeep(self.id_handle, 0x30);
uid_str = str(uid_pstr.value,encoding='utf-8')
return (ret,uid_str)
if __name__ == "__main__":
idcard = idreader()
uid=idcard.get_uid()
print('id card uid=')
print(uid)
id_msg = idcard.get_msg()
print('id card message:')
print(id_msg)
特别注意:
本Python方案用于规范支持的型号有:EST-100、EST-100GS、EST-100G、EST-100U、EST-200G、EST-J13X等系列身份证阅读器机型。
以下型号第二代身份证阅读器(读卡器)未经深度测试,不一定支持使用。
如:千景J15S、千景HD-900、华旭HX-FDX3S、神思SS628(100)、新中新DKQ-A16D、中控ID100、华视CVR-100UC、华视CVR-100UA、精伦IDR210、国腾GTICR100、普天CP IDMR02/TG/ZW、神盾ICR-100U、ICR-100M、昌茂CM008等等等……