身份证识别
[!TIP|labelVisibility:hidden|iconVisibility:hidden] navigator.bdidcard.recognizeIDCard(success, error,options)
支持平台:
- Android
- iOS
参数说明
参数 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 是 | 成功回调函数 |
error | Function | 是 | 失败回调函数 |
options | Object | 是 | 数据对象 |
success
函数会返回一个json字符串,识别数据扫描结果信息:
result
(对象) -- 身份证识别返回的所有数据,数据参考:https://ai.baidu.com/docs#/OCR-API/2f9f9fffstatus
(String) -- 识别状态码:normal
(String) -- 识别正常reversed_side
(String) -- 身份证正反面颠倒non_idcard
(String) -- 上传的图片中不包含身份证blurred
(String) -- 身份证模糊other_type_card
(String) -- 其他类型证照over_exposure
(String) -- 身份证关键字段反光或过曝over_dark
(String) -- 身份证欠曝(亮度过低)unknown
(String) -- 未知状态
message
(对象) -- 身份证识别数据,其属性包含以下一项或多项:- 当
status
是normal
的时候:- 正面识别成功数据:
name
(String) -- 姓名birth
(String) -- 出生idCard
(String) -- 公民身份号码gender
(String) -- 性别address
(String) -- 住址nation
(String) -- 民族imagePath
(String) -- 扫描的图片存储路径
- 反面识别成功数据:
organization
(String) -- 签发机关issueDate
(String) -- 签发日期invalidDate
(String) -- 失效日期imagePath
(String) -- 扫描的图片存储路径
- 正面识别成功数据:
- 当
status
是除了normal
的时候,识别数据:imagePath
(String) -- 扫描的图片存储路径
- 当
error
函数会返回一个字符串,扫描错误的相关信息,错误码参考https://ai.baidu.com/docs#/OCR-API/58fd45dd
options
参数为一个对象,其属性包含以下一项或多项:
idType
(整形 / 必须) -- 身份证类型,0:正面,1:反面imgPath
(整形/ 可选) -- 扫描的图片存储路径,0:相册,1:项目路径,默认相册imgType
(整形/ 可选)扫描的图片类型,0:.jpg格式,1:.png格式,默认jpg
示例代码
// 引用js
<script src='supconit://hcmobile.js'></script>
<script>
// 监听’deviceready‘事件
document.addEventListener('deviceready', onDeviceReady, false)
function onDeviceReady(){
// 身份证认证
navigator.bdidcard.recognizeIDCard(function (success) {
alert(success);
},function (error) {
alert(error);
},{'idType':0,'imgPath':1,'imgType':0});
}
</script>
响应示例代码:
{
"result": {
"log_id": 2491284932850934000,
"words_result_num": 6,
"image_status": "normal",
"words_result": {
"姓名": {
"words": "小明",
"location": {
"top": 72,
"width": 40,
"left": 144,
"height": 15
}
},
"出生": {
"words": "19800831",
"location": {
"top": 124,
"width": 102,
"left": 139,
"height": 14
}
},
"公民身份号码": {
"words": "38008*****",
"location": {
"top": 219,
"width": 178,
"left": 188,
"height": 17
}
},
"性别": {
"words": "男",
"location": {
"top": 101,
"width": 10,
"left": 139,
"height": 12
}
},
"住址": {
"words": "浙江省****",
"location": {
"top": 151,
"width": 131,
"left": 138,
"height": 31
}
},
"民族": {
"words": "汉",
"location": {
"top": 101,
"width": 8,
"left": 202,
"height": 10
}
}
},
"idcard_number_type": 1
},
"message": {
"gender": "男",
"nation": "汉",
"idCard": "38008*****",
"address": "浙江省****",
"birth": "19800831",
"imagePath": "cdvfile://localhost/cache/1578453359000.jpg",
"name": "小明"
},
"status": "normal"
}