baseISSOnline.js
8.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
function createISSonlineDevice(setting)
{
var ISSOnline = "ZKIDROnline";
var browserFlag = getBrowserType() || "";
//刷卡信息返回默认方法
if(typeof setting.Methods == "object")
{
if(typeof setting.Methods.showMessage != "function")
{
setting.Methods.showMessage = function(type,message)
{
$("#cert_message").text(message);
$("#cert_message_type").text(msgType[type]);
}
}
//检查驱动安装默认方法
if(typeof setting.Methods.checkWebServer != "function")
{
setting.Methods.checkWebServer = function(myDevice)
{
var ISSVersion = function(){};
ZK.extend(ISSVersion, Device, {
message : "",
url : "/info",
interfaceResult :
{
0:{mean:"成功",message:"二代身份证读取成功!",type:"success",notShow:true}
},
dealDeviceData:function(result){
var existVersion = result.data.server_version;//2.7.1
var curVersion = "${application['fpDriver.version']}";//3.5.2
var existVersionArr = existVersion.split(".");
var curVersionArr = curVersion.split(".");
var isLast = true;
var len = existVersionArr.length;
for(var i=len;i>0;i--)
{
var existVersionTemp = parseInt(existVersionArr[i-1]);
var curVersionTemp = parseInt(curVersionArr[i-1]);
if(existVersionTemp<curVersionTemp)
{
isLast = false;
}
else if(existVersionTemp>curVersionTemp)
{
isLast = true;
}
else
{
//等于 忽略
}
}
//if(result.data.server_version >= "${application['fpDriver.version']}")
if(isLast)
{
if(typeof setting.Methods.detectSuccess == "function")
{
setting.Methods.detectSuccess();
}
if(typeof myDevice == "object")
{
//连接设备,处理返回信息
setTimeout(function(){
myDevice.accessDevice();
},100);
}
}
else
{
if(typeof setting.Methods.detectWarning == "function")
{
setting.Methods.detectWarning();
}
if(typeof myDevice == "object")
{
//连接设备,处理返回信息
setTimeout(function(){
myDevice.accessDevice();
},100);
}
else
{
if(typeof setting.Methods.notInstall == "function")
{
setting.Methods.notInstall();
}
}
}
},
installDrive:function(){
if(typeof setting.Methods.detectError == "function")
{
setting.Methods.detectError();
}
if(typeof myDevice == "object")
{
closeMessage();
//驱动未安装
setting.Methods.downloadDrive();
}
else
{
if(typeof setting.Methods.notInstall == "function")
{
setting.Methods.notInstall();
}
}
return false;
}
});
var version = new ISSVersion();
version.accessDevice();
}
}
//下载驱动默认方法
if(typeof setting.Methods.downloadDrive != "function")
{
setting.Methods.downloadDrive = function()
{
messageBox({messageType: "confirm", text: "请安装相关硬件驱动!点击确定下载驱动。",
callback: function(result){
if(result)
{
window.location.href = "middleware/ZKIDROnline.exe";
}
closeMessage();
}});
}
}
}
/**
* 设备
*/
var Device = function()
{
message : ""
};
var buttonNames = {"Cert":"","Scanner":"","Barcode":""};
if(typeof setting.Cert == "object")
{
buttonNames.Cert = setting.Cert.select;
//身份证阅读器
var Cert = function(){};
ZK.extend(Cert, Device, {
//提示信息
message : "请将二代身份证放到读卡区域...",
//服务url
url : "/ScanReadIdCardInfo?OP-DEV=1&CMD-URL=4&common=1" + "&random=" + getRandomNum(),
//接口返回值
interfaceResult :
{
0:{mean:"成功",message:"二代身份证读取成功!",type:"success"},
1:{mean:"端口打开失败",message:"未检测到二代身份证阅读器!",type:"warning"},
2:{mean:"数据传输超时",message:"未检测到二代身份证阅读器!",type:"error"},
10:{mean:"没有找到卡",message:"未读取到身份证,请重新刷卡!",type:"warning"},
11:{mean:"读卡操作失败",message:"未检测到二代身份证阅读器!",type:"error"},
20:{mean:"自检失败",message:"二代身份证读取失败!",type:"error"},
30:{mean:"其他错误",message:"二代身份证读取失败!",type:"error"},
40:{mean:"相片解码失败",message:"二代身份证读取失败!",type:"error"},
100:{mean:"超时",message:"未读取到身份证,请重新刷卡!",type:"warning"},
200:{mean:"GetBase64PhotoData",message:"二代身份证读取失败!",type:"error"}
},
dealDeviceData:setting.Cert.callBack
});
}
//工厂
var DeviceFactory =
{
createDevice : function(button){
var device;
switch(button){
case "Cert":
device = new Cert();
break;
case "Scanner":
device = new Scanner();
break;
case "Barcode":
default:
device = new BarcodeScanner();
break;
}
return device;
}
}
//设备工厂
Device.prototype.createDevice = function(button)
{
return DeviceFactory.createDevice(button);
};
//信息显示
Device.prototype.setMessage = function()
{
setting.Methods.showMessage(msgType.loading,this.message);
};
//处理硬件返回值
Device.prototype.dealDeviceInfo = function(result)
{
if(result === null||result.ret===null)
{
setting.Methods.showMessage("error","设备连接异常");
return;
}
//信息提示
var info = this.interfaceResult[result.ret];
if(info == undefined)
{
setting.Methods.showMessage("error","设备连接异常");
return;
}
if(info.notShow == undefined)
{
setting.Methods.showMessage(info.type,info.message);
}
//处理数据
if("success" === info.type)
{
this.dealDeviceData(result);
}
}
//html5使用ajax方式访问服务
Device.prototype.ajaxAccess = function(url)
{
var result = null;
var parent = this;
$.ajax({
type : "GET",
url : issOnlineUrl + url,
dataType : "text",
async:true,
timeout:10000,
success : function(data)
{
data = data.replace(/\\/g,"/");
result = JSON.parse(data);
parent.dealDeviceInfo(result);
},
error : function(XMLHttpRequest, textStatus, errorThrown)
{
console.info(errorThrown+"url:"+url);
if(textStatus == "timeout" && url != "/info")
{
setting.Methods.showMessage("warning","未读取到身份证,请重新刷卡!");
}
else if(typeof parent.installDrive == "function")
{
if(parent.installDrive())
{
setting.Methods.showMessage("error","设备连接异常");
}
}
else
{
setting.Methods.showMessage("error","设备连接异常");
}
},
});
}
//IE8、IE9访问服务
Device.prototype.xDomainAccess = function(url)
{
var parent = this;
var xDomainRequest = new XDomainRequest();
if (xDomainRequest)
{
xDomainRequest.timeout=10000;
xDomainRequest.open('GET', issOnlineUrl + url);
xDomainRequest.onload = function()
{
var resultData = xDomainRequest.responseText;
resultData = resultData.replace(/\\/g,"/");
var obj = JSON.parse(resultData);
parent.dealDeviceInfo(obj);
};
xDomainRequest.onerror = function()
{
//用完后,将对象置为空
xDomainRequest = null;
setting.Methods.showMessage("error","设备连接异常");
};
xDomainRequest.ontimeout = function()
{
//用完后,将对象置为空
xDomainRequest = null;
setting.Methods.showMessage("error","设备连接异常");
};
xDomainRequest.send();
}
}
//驱动检测
Device.prototype.installDrive = function()
{
return true;
}
//设备通信,得到硬件返回的数据
Device.prototype.accessDevice = function()
{
$("#iss").css("width","25%");
if(browserFlag == "html5")
{
this.ajaxAccess(this.url);
}
else if(browserFlag == "simple")
{
this.xDomainAccess(this.url);
}
else
{
if(window.console)
{
console.error("browserFlag is missing");
}
}
};
$.each(buttonNames, function(key, value){
if(value)
{
$(document).off("click",value);
$(document).on("click",value,function(e){
$(value).blur();
//创建设备
var device = new Device();
var myDevice = device.createDevice(key);
//显示提示信息
myDevice.setMessage();
setting.Methods.checkWebServer(myDevice);
});
}
});
setting.Methods.checkWebServer();
}