首页 前端知识 护照阅读器_护照阅读机_护照读卡器WEB网页浏览器SDK开发包,支持Vue、React、Node.js、jQuery、Electron等开发

护照阅读器_护照阅读机_护照读卡器WEB网页浏览器SDK开发包,支持Vue、React、Node.js、jQuery、Electron等开发

2025-02-28 12:02:32 前端知识 前端哥 93 602 我要收藏

护照阅读器采用的是USB接口,虚拟串口,打开读卡服务会自动选择护照阅读器的串口设备号。

EST-100PR护照阅读器无需SDK,主动读卡,持续往串口推送读卡数据,原则上只要监听串口数据即可。

然后打开前端的testDemo.html即可收到护照阅读器的读卡数据。


护照信息结果示例:
{
  "Nationality": "CHN",
  "PersonalNumber": "POCHNSHENG<<LI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\nEN83066886CHN8808084F3411285MKKCMAPG<<<<A948\n",
  "birthDate": "880808",
  "countryCode": "CHN",
  "enName": "SHENG,LI",
  "endTime": "341128",
  "idType": "PO",
  "idnum": "EN8306688",
  "name": "盛丽",
  "nationality": "CHN",
  "personalNumber": "POCHNSHENG<<LI<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\nEN83066886CHN8808084F3411285MKKCMAPG<<<<A948\n",
  "signingTimes": null,
  "sex": "F",
  "picture1": "/9j/4AAQSkZJRgABAQACEKSD/9k=",
  "other1":"",
  "other2":"",
  "rCode": "0",
  "fun": "EidlinkResult",
  "errMsg": ""
}

港澳通行证信息示例:
{
  "Nationality": "CHN",
  "PersonalNumber": "CSCF72068888<2907147<1508082<2\nNFMFNEP<MBNFZHANG<<ZELIN<<<<<<\nFAAC161144<<<<<<<<<<<<<<<<<<<<\n",
  "birthDate": "150808",
  "countryCode": "CHN",
  "enName": "FAAC161144,",
  "endTime": "290714",
  "idType": "CS",
  "idnum": "CF7206888",
  "name": "张泽琳",
  "nationality": "CHN",
  "personalNumber": "CSCF72068888<2907147<1508082<2\nNFMFNEP<MBNFZHANG<<ZELIN<<<<<<\nFAAC161144<<<<<<<<<<<<<<<<<<<<\n",
  "signingTimes": null,
  "sex": "F",
  "picture1": "/9j/4AAQ...Yz//2Q==",
  "other1":"",
  "other2":"",
  "rCode": "0",
  "fun": "EidlinkResult",
  "errMsg": ""
}

台湾通行证信息示例:
{
  "Nationality": "CHN",
  "PersonalNumber": "CDL195088885<3412019<8808084<2\nMKKCMAP<<<<<SHENG<<LI<<<<<<<<<\nFAAB16<<43<<<<<<<<<<<<<<<<<<<<\n",
  "birthDate": "880808",
  "countryCode": "CHN",
  "enName": "FAAB16,43",
  "endTime": "341201",
  "idType": "CD",
  "idnum": "L19508888",
  "name": "盛丽",
  "nationality": "CHN",
  "personalNumber": "CDL195088885<3412019<8808084<2\nMKKCMAP<<<<<SHENG<<LI<<<<<<<<<\nFAAB16<<43<<<<<<<<<<<<<<<<<<<<\n",
  "signingTimes": null,
  "sex": "F",
  "picture1": "/9j/4AAQSkZ...pCEKSD/9k=",
  "other1":"",
  "other2":"",
  "rCode": "0",
  "fun": "EidlinkResult",
  "errMsg": ""
}

以下是JS代码,可集成到Vue、React、Node.js、jQuery、Electron、Uniapp、JSP、PHP、ASP、ASPX、JS、HTML等语言进行二次开发。


var socket;
function openReader() {
	var host = "ws://127.0.0.1:33777"; //客户端电脑本地IP,非服务器IP,无需修改
	if(socket == null){
		socket = new WebSocket(host);
	}else{
		resultMsg("已初始化.");
	}
	try {
		socket.onopen = function () {
			resultMsg("初始化成功."); //可以注释
			getVersion(); //可以注释:控件版本号
		};
		socket.onclose = function () {
			resultMsg("读卡服务已经断开.");
		};
		socket.onerror = function(){
			resultMsg("请检查控件是否正常安装,下载地址:...");
		};
		socket.onmessage = function (msg) {
			if (typeof msg.data == "string") {
				var msgM=msg.data+"";
				var msgJson = JSON.parse(msgM);
				//resultMsg(msgM);        
				switch(msgJson.fun) {

					case "EST_GetVersion":
							resultMsg("版本号:"+msgJson.errMsg);
					break;

/*				
stage:设备当前读取状态
	readStart:读取开始
	readEnd:读取结束
type:读取类型
	IDInfo:身份证
	PassPort:护照
*/
					case "PCSign"://该类型是读取护照或身份证的流程信息
						if (msgJson.rCode == "0") {
						    if (msgJson.type == "IDInfo") {
								//身份证
								if (msgJson.stage == "readStart") {
									resultMsg("身份证 正在读取,请不要移动...");
								}
								else{
									resultMsg("身份证 读取结束...");
								}								
						    }
							else if(msgJson.type == "PassPort"){
								//护照
								if (msgJson.stage == "readStart") {
									resultMsg("护照 正在读取,请不要移动...");
								}
								else{
									resultMsg("护照 读取结束...");
								}							
							}
						}
						else {
							resultMsg(msgJson.errMsg);
						}
						break;
					
					case "EidlinkResult"://该类型是实际读取到芯片的数据
						if (msgJson.rCode == "0") {
							document.getElementById("Nationality").value = msgJson.Nationality;//国家代码
							document.getElementById("PersonalNumber").value = msgJson.PersonalNumber;//护照号码
							document.getElementById("birthDate").value = msgJson.birthDate;//出生日期
							document.getElementById("countryCode").value = msgJson.countryCode;//国家代码,同Nationality
							document.getElementById("enName").value = msgJson.enName;//英文名字
							document.getElementById("endTime").value = msgJson.endTime;//证件有效时间
							document.getElementById("idType").value = msgJson.idType;//证件类型
							document.getElementById("idnum").value = msgJson.idnum;//证件号码
							document.getElementById("name").value = msgJson.name;//名字
							document.getElementById("nationality").value = msgJson.nationality;//国家代码,同Nationality
							document.getElementById("personalNumber").value = msgJson.personalNumber;//护照号码,同PersonalNumber
							document.getElementById("signingTimes").value = msgJson.signingTimes;//签发日期 *该字段大多国内外护照都不存在
							document.getElementById("sex").value = msgJson.sex;//性别
							document.getElementById("other").value = msgJson.other1;//备用信息,目前为空
							//照片数据
							document.getElementById("picture1").src = "data:image/jpeg;base64,"+msgJson.picture1;//图片,base64编码
							//resultMsg(msgJson.errMsg);
						}
						else {
							resultMsg(msgJson.errMsg);
						}
						break;

					case "CameraData"://该类型是OCR识别到的MRZ信息或二维码信息
						if (msgJson.rCode == "0") {
						    if (msgJson.type == "QRCode") {
								//二维码数据
								resultMsg("获取到二维码数据:"+msgJson.datas);
								//resultMsg(msgJson.datas);
						    }
							else{
								//MRZ数据,一般是无芯片的纸质护照
								resultMsg("MRZ数据:"+msgJson.datas);
								//resultMsg(msgJson.datas);							
							}
						}
						else {
							resultMsg(msgJson.errMsg);
						}
						break;

					default:
						break;
				}
			}
			else{
				alert("连接异常,请检查是否成功安装控件.");
			}
		};
	}
	catch (ex) {
		alert("连接异常,请检查是否成功安装控件.");
	}
}

//提示信息
function resultMsg(msg) {
   document.getElementById("text_result").value += "\r\n" + msg;
}

//清空文本框信息
function clearinput()
{
	var obj=document.getElementsByName("text_ID");
	for(var i=0;i<obj.length;i++)
	{
		obj[i].value = "";
	}
	document.getElementById("picture1").src = "";
}

//控件版本号
function getVersion() {        
	socket.send("EST_GetVersion#");
}


//关闭soket
function closeSocket() {
	try {
		if(socket != null){
			socket.close();
			socket = null;
		}
	}
	catch (ex) {
	}
};

// 默认页面打开,就自动打开设备
window.onload=openReader();    

WEB控件下载,请点击头部:护照阅读器_护照阅读机_护照读卡器WEB网页浏览器SDK开发包.zip

转载请注明出处或者链接地址:https://www.qianduange.cn//article/21894.html
评论
会员中心 联系我 留言建议 回顶部
复制成功!