IDCardReader API
安装
npm install @cutos/core
npm install @cutos/devices
引入依赖
import {CoreAPI} from '@cutos/core';
import {DeviceIDCardReader} from '@cutos/devices';
DeviceIDCardReader
构造函数, 创建身份证实例
var devIDCardReader = new DeviceIDCardReader();
DeviceIDCardReader.init
身份证读卡器初始化
devIDCardReader.init(callback);
- callback: 回调函数
举例:
devIDCardReader.init((result, error) => {
if (!error) {
console.log('onDeviceCreate', result)
} else {
console.log(error)
}
});
- 返回结果示例:
Driver device-id-card-reader loaded
DeviceIDCardReader.connect
连接身份证读卡器
devIDCardReader.connect(callback);
- callback: 回调函数
举例:
devIDCardReader.connect((result) => {
if (result.status) {
console.log('connect success:', result)
} else {
console.log('connect failed:', result.msg)
}
});
DeviceIDCardReader.disconnect
断开身份证读卡器
devIDCardReader.disconnect();
DeviceIDCardReader.startRead
读卡器开始寻卡
devIDCardReader.startRead([image], callback);
- image: 可选参数,是否读取身份证照片,默认false。true为读取,false不读取。
- callback: 回调函数
举例:
devIDCardReader.startRead(result => console.log(result))
- 返回结果示例:
{
"status": true,
"msg": "reading"
}
DeviceIDCardReader.readDeviceInfo
读取身份证读卡器设备信息
devIDCardReader.readDeviceInfo(callback);
- callback: 回调函数
举例:
devIDCardReader.readDeviceInfo(result => {
console.log('device info:', result)
})
- 返回结果示例:
{
"status": true,
"msg": {
"SAMID": "5-3-20220810-11478877-3979136230"
}
}
DeviceIDCardReader.onData
接收身份证信息
devIDCardReader.onData(callback)
- callback: 回调函数
举例:
devIDCardReader.onData((data) => {
console.log('data', data)
})
- 返回结果示例:
{
"code": 110111201607101234,
"name": "思普",
"sex": "男",
"birthday": 20160710,
"address": "北京市西城区裕民路18号北环中心1705",
"nation": "中国",
"department": "北京市西城区",
"startDate": 20160710,
"endDate": 20260710,
"certType": "身份证"
}