以腈纶电子的读卡器为例
下载控件IDCardReader.ocx并注册
cd /d "%~dp0"
regsvr32 IDCardReader.ocx
CLS</P>
样例
<body style="text-align: center">
<form id="form1" runat="server">
<OBJECT classid="clsid:10946843-7507-44FE-ACE8-2B3483D179B7"
id="CVR_IDCard" name="CVR_IDCard" width="0" height="0" >
</OBJECT>
<script language="javascript" type ="text/javascript">
function ClearForm() {
document.all['Name'].value = "";
document.all['Sex'].value = "";
document.all['Nation'].value = "";
document.all['Born'].value = "";
document.all['Address'].value = "";
document.all['CardNo'].value = "";
document.all['IssuedAt'].value = "";
document.all['EffectedDate'].value = "";
document.all['ExpiredDate'].value = "";
document.all['SAMID'].value = "";
document.all['pic'].src = "";
document.all['Picture'].value = "";
document.all['PictureLen'].value = "";
return true;
}
function Button1_onclick() {
var CVR_IDCard = document.getElementById("CVR_IDCard");
var strReadResult = CVR_IDCard.ReadCard();
if(strReadResult == "0")
{
ClearForm();
document.all['Name'].value = CVR_IDCard.Name; document.all['Sex'].value = CVR_IDCard.Sex;
document.all['Nation'].value = CVR_IDCard.Nation;
document.all['Born'].value = CVR_IDCard.Born;
document.all['Address'].value = CVR_IDCard.Address;
document.all['CardNo'].value = CVR_IDCard.CardNo;
document.all['IssuedAt'].value = CVR_IDCard.IssuedAt;
document.all['EffectedDate'].value = CVR_IDCard.EffectedDate;
document.all['ExpiredDate'].value = CVR_IDCard.ExpiredDate;
document.all['SAMID'].value = CVR_IDCard.SAMID;
document.all['pic'].src = CVR_IDCard.Pic;
document.all['Picture'].value = CVR_IDCard.Picture;
document.all['PictureLen'].value = CVR_IDCard.PictureLen
}
else
{
alert('重试' );
}
}
function Button3_onclick() {
var t1;
var returns;
var IdrControl1 = document.getElementById("IdrControl1");
t1 = IDCardReadJL(IdrControl1);
if (t1.Name != null)
{
//returns = t1.Name;
document.all['Name'].value = t1.Name;
document.all['Sex'].value = t1.Sex;
document.all['Nation'].value = t1.Nation;
document.all['Born'].value = t1.Birth;
document.all['Address'].value = t1.Address;
document.all['CardNo'].value = t1.CardNo;
document.all['IssuedAt'].value = t1.Police;
document.all['EffectedDate'].value = t1.ValidDateFrom;
document.all['ExpiredDate'].value = t1.ValidDateTo;
document.all['SAMID'].value = t1.SAMID;
document.all['pic'].src = t1.PhotoPath;
document.all['Picture'].value = t1.PhotoBase64Info;
document.all['PictureLen'].value = t1.PictureLen
}
t1=null;
}
function IDCardReadJL(CardReaderID){
var obj = CardReaderID;//document.getElementById(CardReader1);
//注意:第一个参数为对应的设备端口,USB型为1001,串口型为1至16
var rst;
var photoPath="c:\\cardPhoto\\"+Math.floor(Math.random()*100000000)+".bmp";
rst = obj.ReadCard("1001",photoPath);
if (rst==1){
var t = new Object;
//获取各项信息
t.Name =obj.GetName();
t.Sex =obj.GetSex();
t.Nation =obj.GetFolk();
t.Address=obj.GetAddress();
t.CardNo=obj.GetCode();
t.Birth =obj.GetBirthYear()+'-'+obj.GetBirthMonth()+'-'+obj.GetBirthDay();
t.Police = obj.GetAgency() ;
var strValidDate = obj.GetValid();
//t.ValidDate = obj.GetValid();
t.ValidDateFrom=strValidDate.split("-")[0].replace(".","-").replace(".","-");
t.ValidDateTo=strValidDate.split("-")[1].replace(".","-").replace(".","-");
t.PhotoBase64Info=obj.GetPhotobuf();
t.PhotoPath = photoPath;
obj = null;
return t;
}
else
{
alert("未能获取读卡器实例,请检查\r\n1.是否已正确安装读卡器\r\n2.是否将身份证放入读卡器");
return GetEmpty();
}
}
//返回空的数据
function GetEmpty()
{
var t = new Object;
t.Name ="";
t.Sex ="";
t.Nation ="";
t.Address="";
t.CardNo="";
t.Birth ="";
t.Police ="";
t.ValidDateFrom="";
t.ValidDateTo="";
t.PhotoBase64Info="";
t.PhotoPath = "";
return t;
}
function ReadCardInfo()
{
var t1;
var returns;
var IdrControl1 = document.getElementById("IdrControl1");
t1 = IDCardReadJL(IdrControl1);
returns = t1.Name;
alert(returns);
t1=null;
/*
其中:IDCardReadJL 精伦读卡器调用方法名,IdrControl1为控件名称
返回值:
t1.Name 姓名
t1.CardNo 身份证号码
t1.Sex 性别(格式:男)
t1.Nation 民族(格式:汉)
t1.Birth 出生日志(格式:1900-01-01)
t1.Address 地址
t1.Police 发证机关
t1.ValidDateFrom 身份证有效开始时间
t1.ValidDateTo 身份证有效结束时间
t1.PhotoPath 本地生产的图片路径
t1.PhotoBase64Info 图片的base64编码
*/
}
</script>
</script>
<table style="width: 638px; height: 273px; border-top-style: groove; border-right-style: groove; border-left-style: groove; background-color: transparent; border-bottom-style: groove;">
<tr>
<td style="width: 98px">
姓名:</td>
<td style="text-align: left" colspan="3">
<input id="Text1" type="text" style="width: 155px" name="Name" /></td>
<td style="width: 138px; text-align: left;" rowspan="3">
<img src="" style="width: 91px; height: 108px" name="pic"/></td>
</tr>
<tr>
<td style="width: 98px">
性别:</td>
<td style="width: 80px">
<input id="Text2" type="text" name="Sex" style="width: 154px" /></td>
<td style="width: 58px">
民族:</td>
<td style="width: 59px">
<input id="Text3" type="text" name="Nation" style="width: 94px" /></td>
</tr>
<tr>
<td style="width: 98px">
出生日期:</td>
<td style="text-align: left;" colspan="3">
<input id="Text4" type="text" style="width: 151px" name="Born" /></td>
</tr>
<tr>
<td style="width: 98px">
地址:</td>
<td colspan="4" style="text-align: left">
<input id="Text5" style="width: 505px" type="text" name="Address" /></td>
</tr>
<tr>
<td style="width: 98px">
身份号码:</td>
<td colspan="4" style="text-align: left">
<input id="Text6" style="width: 506px" type="text" name="CardNo" /></td>
</tr>
<tr>
<td style="width: 98px">
签发机关:</td>
<td colspan="4" style="text-align: left">
<input id="Text7" style="width: 505px" type="text" name="IssuedAt" /></td>
</tr>
<tr>
<td style="width: 98px">
有效期限:</td>
<td colspan="4" style="text-align: left">
<input id="Text8" style="width: 163px" type="text" name="EffectedDate" />至<input id="Text10" style="width: 163px" type="text" name="ExpiredDate" /></td>
</tr>
<tr>
<td style="width: 98px; text-align: left;">
模块号码:</td>
<td colspan="4" style="text-align: left">
<input id="Text9" style="width: 506px" type="text" name="SAMID" /></td>
</tr>
<tr>
<td style="width: 98px; text-align: left; height: 136px;">
照片编码:</td>
<td colspan="4" style="text-align: left; height: 136px;">
<textarea id="TextArea1" name="Picture" style="width: 509px; height: 115px"></textarea></td>
</tr>
<tr><object classid="clsid:5EB842AE-5C49-4FD8-8CE9-77D4AF9FD4FF" id="IdrControl1" width="1" height="1"></object>
<td style="width: 98px; text-align: left">
编码长度:</td>
<td colspan="4" style="text-align: left">
<input id="Text11" style="width: 508px" type="text" name="PictureLen"/></td>
</tr>
</table>
</form>
<input id="Button1" type="button" value="读 卡" οnclick="return Button1_onclick()" />
<input id="Button3" type="button" value="jl读 卡" οnclick="return Button3_onclick()" />
<input id="Button3" type="button" value="关 于" οnclick="return Button3_onclick()" />
</body>
</html>