程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> .NET網頁編程 >> ASP.NET >> 關於ASP.NET >> ASP.NET程序讀取二代身份證

ASP.NET程序讀取二代身份證

編輯:關於ASP.NET

一般來說winform應用程序解決這個問題起來時很容易的,web應用程序就麻煩一點了。

這裡我說說我的解決思路:

一、你必要有聯機型居民身份證閱讀器一個(帶驅動光盤),這裡我用的是精倫電子公司的 iDR200,並有這個閱讀器的開發接口說明。

二、新建一個winform控件項目ReadCardControl,添加一個主類ReadCard

1、聲明dll入口

[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 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("kernel32.dll")]
         private static extern int Beep(int dwFreq, int  dwDuration);//用來大吼一聲

2、讀卡方法

private string[] arrys = null;//聲明用來保存身份證信息的數組
         public void OnTimer()
         {
             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);
             //int len = 0;
             //string[] temp;
             char[] param = { '\0' };
             byte[] pMsg = new byte[256];
             string[] baseinfo = new string[9];

             //打開端口
             int intOpenRet = InitComm(1001);
             if (intOpenRet != 1)
             {
                 //SetText("閱讀機具未連接", lblMsg);
                 return;
             }
             //卡認證
             int intReadRet = Authenticate();
             if (intReadRet != 1)
             {
                 //SetText("卡認證失敗", lblMsg);
                 CloseComm();
                 return;
             }
             //ReadBaseInfos(推薦使用)
             int intReadBaseInfosRet = ReadBaseInfos(Name, Gender,  Folk, BirthDay, Code, Address, Agency, ExpireStart, ExpireEnd);
             if (intReadBaseInfosRet != 1)
             {
                 //SetText("讀卡失敗", lblMsg);
                 CloseComm();
                 return;
             }
             Beep(2047, 200);
             arrys = new string[10];
             arrys[0] = Code.ToString().Trim();
             arrys[1] = Name.ToString().Trim();
             arrys[2] = Gender.ToString().Trim();
             arrys[3] = Folk.ToString().Trim();
             arrys[4] = BirthDay.ToString().Trim();
             arrys[5] = Address.ToString().Trim();
             arrys[6] = Agency.ToString().Trim();
             arrys[7] = ExpireStart.ToString().Trim();
             arrys[8] = ExpireEnd.ToString().Trim();
             arrys[9] = System.IO.Directory.GetCurrentDirectory() +  "\\photo.bmp";
             //SetText("讀卡成功", lblMsg);
             //SetText("證件號碼:" + Code.ToString(), label1);
             //SetText("姓名:" + Name.ToString(), label2);
             //SetText("性別:" + Gender.ToString(), label3);
             //SetText("民族:" + Folk.ToString(), label4);
             //SetText("出生日期:" + BirthDay.ToString(),  label5);
             //SetText("地址:" + Address.ToString(), label6);
             //SetText("簽發機關:" + Agency.ToString(), label7);
             //SetText("簽發時間:" + ExpireStart.ToString(),  label8);
             //SetText("有效截止時間:" + ExpireEnd.ToString(),  label9);
             SetImage("photo.bmp", pictureBox1);
             CloseComm();
         }

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved