身份证识别

[!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/2f9f9fff
  • status(String) -- 识别状态码:
    • normal(String) -- 识别正常
    • reversed_side(String) -- 身份证正反面颠倒
    • non_idcard(String) -- 上传的图片中不包含身份证
    • blurred(String) -- 身份证模糊
    • other_type_card(String) -- 其他类型证照
    • over_exposure(String) -- 身份证关键字段反光或过曝
    • over_dark(String) -- 身份证欠曝(亮度过低)
    • unknown(String) -- 未知状态
  • message(对象) -- 身份证识别数据,其属性包含以下一项或多项:
    • statusnormal的时候:
      • 正面识别成功数据:
        • 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"
}

results matching ""

    No results matching ""