C#使用读卡器读取身份证信息(包含物理卡号)

news/2024/11/23 1:45:05/

说明:本人用的是精伦身份证阅读器idr210 免驱

摘要:目前市面上读取身份证技术已经很成熟了,大多数文章都介绍了读取身份证的详细信息,但是这些信息里并不包含身份证的物理卡号,所以本文讲解的重点在读取身份证的物理卡号,这也是博主在开发过程中踩到的一个坑

什么是物理卡号?

我们目前所用的所有电子卡,无论是身份证还是IC卡,甚至是银行卡,它都有一个自己的唯一标识,该标识就是物理卡号,精伦读卡器读出的身份证物理卡号是138EC00375381712这样的一个格式,下面就上代码。

需要接入精伦提供的库文件:

Dewlt.dll

JpgDll.dll

SavePhoto.dll

Sdtapi.dll

Sdtapi_bkup.dll

System.Web.Services.dll

WltRS.dll

以上库文件需要的下面留言

新建一个控制台应用程序,导入以上几个库文件,使用本代码即可运行

1、身份证信息Model类

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MyReadCard
{class IdCardMessageDto{/// <summary>/// 证件号/// </summary>public string Code { get; set; }/// <summary>/// 姓名/// </summary>public string Name { get; set; }/// <summary>/// 性别/// </summary>public string Gender { get; set; }/// <summary>/// 民族/// </summary>public string Folk { get; set; }/// <summary>/// 生日/// </summary>public string BirthDay { get; set; }/// <summary>/// 家庭地址/// </summary>public string Address { get; set; }/// <summary>/// 签发机关/// </summary>public string Agency { get; set; }/// <summary>/// 有效期起始日期/// </summary>public string ExpireStart { get; set; }/// <summary>/// 有效期截止日期/// </summary>public string ExpireEnd { get; set; }/// <summary>/// 照片/// </summary>public string photo { get; set; }/// <summary>/// 物理卡号/// </summary>public string IINSNDN { get; set; }}
}

该类是身份证信息model类,这个不用多说,IINSNDN这个字段就是物理卡号字段

2、读取身份证信息类

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using System.Threading.Tasks;namespace MyReadCard
{class ReadIdCardHelper{#region Api[DllImport("Sdtapi.dll")]private static extern int InitComm(int iPort);[DllImport("Sdtapi.dll")]private static extern int Authenticate();[DllImport("Sdtapi.dll")]private static extern int ReadBaseInfos(StringBuilder Name, StringBuilder Gender, StringBuilder Folk,StringBuilder BirthDay, StringBuilder Code, StringBuilder Address,StringBuilder Agency, StringBuilder ExpireStart, StringBuilder ExpireEnd);[DllImport("Sdtapi.dll")]private static extern int ReadBaseInfosPhoto(StringBuilder Name, StringBuilder Gender, StringBuilder Folk,StringBuilder BirthDay, StringBuilder Code, StringBuilder Address,StringBuilder Agency, StringBuilder ExpireStart, StringBuilder ExpireEnd, StringBuilder directory);[DllImport("Sdtapi.dll")]private static extern int ReadBaseInfosFPPhoto(StringBuilder Name, StringBuilder Gender, StringBuilder Folk,StringBuilder BirthDay, StringBuilder Code, StringBuilder Address,StringBuilder Agency, StringBuilder ExpireStart, StringBuilder ExpireEnd, StringBuilder directory, StringBuilder pucFPMsg, ref int puiFPMsgLen);[DllImport("Sdtapi.dll")]private static extern int Routon_DecideIDCardType();[DllImport("Sdtapi.dll")]private static extern int Routon_ReadAllForeignBaseInfos(StringBuilder EnName, StringBuilder Gender, StringBuilder Code, StringBuilder Nation, StringBuilder CnName, StringBuilder BirthDay, StringBuilder ExpireStart, StringBuilder ExpireEnd, StringBuilder CardVertion, StringBuilder Agency, StringBuilder CardType, StringBuilder FutureItem);[DllImport("Sdtapi.dll")]private static extern int Routon_ReadAllGATBaseInfos(StringBuilder Name, StringBuilder Gender, StringBuilder FutureItem1, StringBuilder BirthDay, StringBuilder Address, StringBuilder Code, StringBuilder Agency, StringBuilder ExpireStart, StringBuilder ExpireEnd, StringBuilder PassID, StringBuilder SignCnt, StringBuilder FutureItem2, StringBuilder CardType, StringBuilder FutureItem3);[DllImport("Sdtapi.dll")]private static extern int CloseComm();[DllImport("Sdtapi.dll")]private static extern int ReadBaseMsg(byte[] pMsg, ref int len);[DllImport("Sdtapi.dll")]private static extern int ReadBaseMsgW(byte[] pMsg, ref int len);[DllImport("Sdtapi.dll")]private static extern int Routon_IC_FindCard();[DllImport("Sdtapi.dll")]private static extern int Routon_IC_HL_ReadCardSN(StringBuilder SN);[DllImport("Sdtapi.dll")]private static extern int Routon_RepeatRead(bool isRepeat);[DllImport("Sdtapi.dll")]private static extern int Routon_ReadIINSNDN(StringBuilder IINS);[DllImport("Sdtapi.dll")]private static extern int ReadIINSNDN(StringBuilder IINS);#endregionpublic static string IdCardInfoData = "";static public void readCard(ref IdCardMessageDto idCardMessage){IdCardInfoData = "";Routon_RepeatRead(true);//打开端口int intOpenRet = InitComm(1001);if (intOpenRet != 1){return ;}//卡认证int intReadRet = Authenticate();if (intReadRet != 1){CloseComm();return ;}int cardType = Routon_DecideIDCardType();if (cardType == 100)//身份证{StringBuilder Name = new StringBuilder(31);StringBuilder Gender = new StringBuilder(3);StringBuilder Folk = new StringBuilder(10);StringBuilder BirthDay = new StringBuilder(9);StringBuilder Code = new StringBuilder(19);StringBuilder Address = new StringBuilder(71);StringBuilder Agency = new StringBuilder(31);StringBuilder ExpireStart = new StringBuilder(9);StringBuilder ExpireEnd = new StringBuilder(9);StringBuilder CardId = new StringBuilder(16);StringBuilder directory = new StringBuilder(100);StringBuilder pucFPMsg = new StringBuilder(1024);StringBuilder IINS = new StringBuilder(16);int intReadBaseInfosRet = ReadBaseInfos(Name, Gender, Folk, BirthDay, Code, Address, Agency, ExpireStart, ExpireEnd);if (intReadBaseInfosRet != 1){CloseComm();return ;}int intReadIINS = ReadIINSNDN(IINS);if (intReadIINS != 1){CloseComm();return ;}idCardMessage = new IdCardMessageDto();idCardMessage.Code = Code.ToString().Trim();idCardMessage.Name = Name.ToString().Trim();idCardMessage.Gender = Gender.ToString().Trim();idCardMessage.Folk = Folk.ToString().Trim();idCardMessage.BirthDay = BirthDay.ToString().Trim();idCardMessage.Address = Address.ToString().Trim();idCardMessage.Agency = Agency.ToString().Trim();idCardMessage.ExpireStart = ExpireStart.ToString().Trim();idCardMessage.ExpireEnd = ExpireEnd.ToString().Trim();idCardMessage.IINSNDN = IINS.ToString().Trim();idCardMessage.photo = System.IO.Directory.GetCurrentDirectory() + "\\photo.bmp";IdCardInfoData = JsonConvert.SerializeObject(idCardMessage);}}}
}

   [DllImport("Sdtapi.dll")]
   private static extern int ReadIINSNDN(StringBuilder IINS);   这里就是调用精伦dll库里读取物理卡号的方法

 int intReadIINS = ReadIINSNDN(IINS);  将读取到的物理卡号存储到IINS里
  if (intReadIINS != 1)
  {
         CloseComm();
          return ;
     }

读取到物理卡号 intReadIINS 的值就为1

3、Program调用类

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;namespace MyReadCard
{class Program{public static string IdCardInfoData = "";static void Main(string[] args){IdCardMessageDto idCardMessage = null;           ReadIdCardHelper.readCard(ref idCardMessage);IdCardInfoData = ReadIdCardHelper.IdCardInfoData;//var data = JsonConvert.DeserializeObject<IdCardMessageDto>(IdCardInfoData);Console.WriteLine(IdCardInfoData);}}
}


http://www.ppmy.cn/news/655934.html

相关文章

.net core 3.1精伦身份证读卡器IDR210-2(部标版)二次开发

业务需求 在学员录入的时候添加一个读取身份证填充对应信息的功能&#xff0c;但遇到如下问题&#xff1a; 官方提供的demo读取身份证使用了com组件和activeX控件的技术&#xff0c;并且只支持IE&#xff0c;我们的前端项目没有兼容IE技术选型选择了使用.net core 3.1,但网上…

身份证读卡器 护照阅读器,如何能做到读取多证件呢?

关联词&#xff1a;护照阅读器 护照识别仪 护照扫描仪 护照扫描机 电子护照阅读器 电子护照阅器一体机 护照批量录入 护照录入 护照识别 护照管理、证件识读仪、护照阅读机、护照读取机、护照识别一体机 护照阅读机原理护照阅读机品牌哪个好——电子护照&#xff0c;全称是携带…

新中新二代身份证读卡器DKQ-A16D C# Demo 无法运行问题

116D-A16D阅读器发行盘中的C# Demo 无法直接运行&#xff0c;但是其他Demo可正常运行。怀疑代码有问题&#xff0c;有幸看到了https://blog.csdn.net/yaogh/article/details/53419392 这位仁兄的帖子&#xff0c;根据其分析&#xff0c;发现确实就是权限的问题&#xff0c;所以…

德卡T10读卡器 读取身份证号码和身份证UID

这个简单的测试项目,界面上有个timer控件,设计的是3秒执行一下读取身份证的动作,目前想到的是这种循环方式,德卡T10这个机子,身份证放上去,不会自动去执行读取的操作。 1.界面 2.界面的代码 Form1.cs 如下 1 using System;2

新中新二代身份证读卡Syn_ReadBaseMsg方法

新中新二代身份证读卡器dkq-a16d&#xff0c;在C#中读卡开发时&#xff0c;参考随机附带的C#参考代码&#xff0c;能够读取成功&#xff0c;但读几次程序就莫名其妙的关掉了&#xff0c;有时连错误都捕捉不到&#xff0c;搞了很长时间也没搞定&#xff0c;后来以为会不会是win7…

解决no main manifest attribute, in XXX.jar

解决no main manifest attribute, in XXX.jar 1. 问题描述1.1 前言1.2 问题描述 2. 问题原因3. 解决问题3.1 修改pom文件3.2 重新启动3.3 再次查看META-INF/MANIFEST.MF3.4 小结 1. 问题描述 1.1 前言 创建一个简单的maven项目&#xff0c;pom配置如下&#xff1a; 1.2 问题…

【算法题】动态规划中级阶段之不同路径、最小路径和

动态规划中级阶段 前言一、不同路径1.1、思路1.2、代码实现 二、不同路径 II2.1、思路2.2、代码实现 三、最小路径和3.1、思路3.3、代码实现 总结 前言 动态规划&#xff08;Dynamic Programming&#xff0c;简称 DP&#xff09;是一种解决多阶段决策过程最优化问题的方法。它…

脑洞大的日本人,做了一个AI智能观音讲佛经!

据报道&#xff0c;日前&#xff0c;日本高台寺展示了智能机器人观音 Minder&#xff0c;旨在向现代人简单易懂的阐明佛教的教义。 据了解&#xff0c;Minder 由大阪大学教授石黑浩等人协助研发&#xff0c;研发费用为 1 亿日元&#xff08;约 600 万人民币&#xff09;。外形…