C 身份證讀卡器開發

2021-09-24 22:47:49 字數 3491 閱讀 5324

實際開發中,如果需要讀取身份證資訊,就涉及到身份證讀卡器開發了,最近專案中剛好用到,藉此與大家分享下開發過程。

身份證讀卡器市面上有很多種,華旭、中控、華大等等,其開發原理大同小異,本次以華旭讀卡器為例。

//身份證資訊結構

public class idcardinfo

public string name

public string ***

public datetime birthday

public string nation

public string idnumber

public string address

public string department

public string effectdata

public string expire

public string imagepath

}//介面,因可能涉及不同裝置,固都繼承此介面

public inte***ce iidcardreader

//裝置烈性

public enum enumidreaderdevice

//裝置工廠

public sealed class devicefactory

else if (config == "3")

else if (config == "4")

iidcardreader result = null;

switch (_readerdevice)

return result;

}//裝置類

public class idcardreaderhx : iidcardreader

idcardinfo idcardinfo = (idcardinfo)idcardinfo.bytestostruct(array, typeof(idcardinfo));

string text = idcardinfo.id.trim() + ".wlt";

bool flag = writefile(array2, (int)puiphmsglen, text);

idcardinfo.imagepath = idcardinfo.id.trim() + ".bmp";

if (!file.exists(idcardinfo.imagepath))

idcardinfo dcardinfo = new idcardinfo();

dcardinfo.cardno = idcardinfo.id.trim();

dcardinfo.name = idcardinfo.name.trim();

dcardinfo.*** = idcardinfo.***.trim();

dcardinfo.birthday = datetime.parseexact(idcardinfo.birth.trim(), "yyyymmdd", cultureinfo.currentculture);

dcardinfo.nation = idcardinfo.nation.trim();

dcardinfo.idnumber = idcardinfo.id.trim();

dcardinfo.address = idcardinfo.address.trim();

dcardinfo.department = idcardinfo.issue.trim();

dcardinfo.effectdata = idcardinfo.exper_sta.trim();

dcardinfo.expire = idcardinfo.exper_end.trim();

dcardinfo.imagepath = idcardinfo.imagepath;

return dcardinfo;

}private static bool writefile(byte buf, int pucaddmsglen, string fname)

catch

}[dllimport("sdtapi_x32/sdtapi.dll", callingconvention = callingconvention.stdcall, charset = charset.unicode)]

private static extern int sdt_openport(int iport);

[dllimport("sdtapi_x32/sdtapi.dll", callingconvention = callingconvention.stdcall, charset = charset.unicode, entrypoint = "sdt_openport")]

private static extern int sdt_closeport(int iport);

[dllimport("sdtapi_x32/sdtapi.dll", callingconvention = callingconvention.stdcall, charset = charset.unicode)]

private static extern int sdt_startfindidcard(int iport, byte pucmanainfo, int iifopen);

[dllimport("sdtapi_x32/sdtapi.dll", callingconvention = callingconvention.stdcall, charset = charset.unicode)]

private static extern int sdt_selectidcard(int iport, byte pucmanamsg, int iifopen);

[dllimport("sdtapi_x32/sdtapi.dll", callingconvention = callingconvention.stdcall, charset = charset.unicode)]

private static extern int sdt_readbasemsg(int iport, byte pucchmsg, ref uint puichmsglen, byte pucphmsg, ref uint puiphmsglen, int iifopen);

[dllimport("sdtapi_x32/wltrs.dll", callingconvention = callingconvention.stdcall, charset = charset.unicode)]

private static extern int getbmp(byte wlt_file, int intf);

//最後專案中讀取身份證實際資訊

public idcardinfo readcardinfo()

idcardinfo cardinfo = null;

tyriidcardreader cardreader = devicefactory.createidcardreader();

if (cardreader == null)

cardinfo = iidcardreader.readinfo();

return cardinfo;

二代身份證讀卡器二次開發

目的 為了在自行開發的專案中使用 新中新二代身份證讀卡器 獲得二代身份證資訊,需要對現有讀卡器程式進行二次開發。準備 sdk 二代身份證sdk開發包.rar 示例 新中新二代證sdk開發包.rar dll 測試程式 c 讀卡器型號 dkq 116d 版本號使用方法 一 開發前先執行開發包中 dll ...

C 身份證識別(一) 身份證號定位

一 影象預處理 public static imagebyte binimg image byte img 二 身份證號區域提取 獲取輪廓 private static vectorofvectorofpoint getcontours imagebyte pic 篩選矩形 public stati...

VUE實現華視身份證閱讀器讀取身份證資訊

這是模板 直接放在之間就可以。title visible.sync open width 10 class mb8 1.5 type success icon el icon plus size mini click connect 連線 el button el col 1.5 type warn...