在web浏览器页面使用IC卡读卡器

在web浏览器中要嵌入IC卡读卡器,如果使用IE浏览器,那么只能使用OCX控件,不管这个OCX后缀是dll还是ocx。

然后在网页端 通过javascript或者vbscript脚本调用ocx的接口来读写IC卡数据。


以下代码打开USB端口

function OpenReader()
{
  if(document.ReaderTest.YW_USBHIDInitial()<=0)
  {
      document.getElementById("CardNo").value = "没有读卡器";
      return false;
   } 
  return true;
}


以下代码寻卡操作
function RequestCard()
{
   var i;
   var CardType;
   var vCardNo;
   var LenCardNo;
   

   if(OpenReader()==false)return;

   i = document.ReaderTest.YW_RequestCard(1,82);
   if(i<0)
   {
	document.getElementById("CardNo").value ="寻卡失败";
	return;
   }
   i = document.ReaderTest.YW_AntiCollide(1);
   if(i<0)
   {
	document.getElementById("CardNo").value ="寻卡失败";
	return;
   }

   
   LenCardNo = document.ReaderTest.OutData1Size;
   vCardNo    = document.ReaderTest.OutData1;
   document.getElementById("CardNo").value = document.ReaderTest.ConvertCardNo(vCardNo, 0);	
   i = document.ReaderTest.YW_CardSelect(1,LenCardNo,vCardNo);
   
   
}


以下代码读卡数据:

function ReadCard()
{
   var BlockID;
   var Key;
   RequestCard();
   BlockID = document.getElementById("BlockIDRead").value; 
   
   Key =document.ReaderTest.GetVariantFromHexStr(document.getElementById("KeyRead").value);
   i = document.ReaderTest.YW_KeyAuthorization(1,96,BlockID,Key);
   if(i<0)
   {
	document.getElementById("DataRead").value ="密钥认证错误";
	return;
   } 
   
   i = document.ReaderTest.YW_ReadaBlock(1,BlockID,16);
   if(i<0)
   {
	document.getElementById("DataRead").value ="读块错误";
	return;
   }  
   document.getElementById("DataRead").value = document.ReaderTest.GetHexStr(document.ReaderTest.OutData1); 
   document.ReaderTest.YW_Buzzer(1,5,5,1);
   CloseReader();
}

以下代码写卡数据:

function WriteCard()
{
   var BlockID;
   var Key;
   var Data;
   RequestCard();
   BlockID = document.getElementById("BlockIDWrite").value; 
   
   Key =document.ReaderTest.GetVariantFromHexStr(document.getElementById("KeyWrite").value);

   i = document.ReaderTest.YW_KeyAuthorization(1,96,BlockID,Key);
   if(i<0)
   {
	alert("密钥认证错误");
	return;
   }
    
   Data =document.ReaderTest.GetVariantFromHexStr(document.getElementById("DataWrite").value);
   i = document.ReaderTest.YW_WriteaBlock(1,BlockID,16,Data);
   if(i<0)
   {
	alert("写块错误");
	return;
   }  
   document.ReaderTest.YW_Buzzer(1,5,5,1);
   alert("写块成功");
   CloseReader();
}



©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页