人证核身服务 IVS-Python SDK:SDK demo 代码解析

时间:2024-11-04 16:58:02

SDK demo 代码解析

人证核身 标准版(三要素)

  • 方式一:使用身份证图片、人像图片进行校验
    try:
        request = DetectStandardByIdCardImageRequest()
        listReqDataByIdCardImageReqDataIvsStandardByIdCardImageRequestBodyData = [
            ReqDataByIdCardImage(
                idcard_image1="身份证人像面图像数据,使用base64编码",
                idcard_image2="身份证国徽面图像数据,使用base64编码",
                face_image="现场人像图像数据,使用base64编码,"
            )
        ]
        dataIvsStandardByIdCardImageRequestBodyData = IvsStandardByIdCardImageRequestBodyData(
            req_data=listReqDataByIdCardImageReqDataIvsStandardByIdCardImageRequestBodyData
        )
        metaMeta = Meta(
            uuid="唯一标识此次请求的ID,用户自定义,不超过64位。例如10eb0091-887f-4839-9929-cbc884f1e20e"
        )
        request.body = IvsStandardByIdCardImageRequestBody(
            data=dataIvsStandardByIdCardImageRequestBodyData,
            meta=metaMeta
        )
        response = client.detect_standard_by_id_card_image(request)
        print(response)
     except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
  • 方式二:使用身份证姓名、身份证号码文本,人像图片进行校验
    try:
        request = DetectStandardByNameAndIdRequest()
        listStandardReqDataByNameAndIdReqDataIvsStandardByNameAndIdRequestBodyData = [
            StandardReqDataByNameAndId(
                verification_name="被验证人的姓名",
                verification_id="被验证人的身份证号码",
                face_image="现场人像图像数据,使用base64编码"
            )
        ]
        dataIvsStandardByNameAndIdRequestBodyData = IvsStandardByNameAndIdRequestBodyData(
            req_data=listStandardReqDataByNameAndIdReqDataIvsStandardByNameAndIdRequestBodyData
        )
         metaMeta = Meta(
            uuid="唯一标识此次请求的ID,用户自定义,不超过64位。例如10eb0091-887f-4839-9929-cbc884f1e20e"
        )
        request.body = IvsStandardByNameAndIdRequestBody(
            data=dataIvsStandardByNameAndIdRequestBodyData,
            meta=metaMeta
        )
        response = client.detect_standard_by_name_and_id(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
  • 方式三:使用现场拍摄的人像视频数据,实现活体人证核身
    try:
        request = DetectStandardByVideoAndIdCardImageRequest()
        listReqDataData = [
            ReqDataByVideoAndIdCardImage(
                idcard_image1="身份证人像面图像数据,使用base64编码",
                idcard_image2="身份证国徽面图像数据,使用base64编码",
                video="现场拍摄人像视频数据,使用base64编码",
                actions="动作代码顺序列表"
            )
        ]
        databody = IvsStandardByVideoAndIdCardImageRequestBodyData(
            req_data=listReqDataData
        )
        metabody = Meta(
            uuid="唯一标识此次请求的ID,用户自定义,不超过64位。例如10eb0091-887f-4839-9929-cbc884f1e20e"
        )
        request.body = IvsStandardByVideoAndIdCardImageRequestBody(
            data=databody,
            meta=metabody
        )
        response = client.detect_standard_by_video_and_id_card_image(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)

人证核身证件版(二要素)

  • 方式一:使用身份证图片进行校验
    try:
        request = DetectExtentionByIdCardImageRequest()
        listExtentionReqDataByIdCardImageReqDataIvsExtentionByIdCardImageRequestBodyData = [
            ExtentionReqDataByIdCardImage(
                idcard_image1="身份证人像面图像数据,使用base64编码",
                idcard_image2="身份证国徽面图像数据,使用base64编码"
            )
        ]
        dataIvsExtentionByIdCardImageRequestBodyData = IvsExtentionByIdCardImageRequestBodyData(
            req_data=listExtentionReqDataByIdCardImageReqDataIvsExtentionByIdCardImageRequestBodyData
        )
        metaMeta = Meta(
            uuid="唯一标识此次请求的ID,用户自定义,不超过64位。例如10eb0091-887f-4839-9929-cbc884f1e20e"
        )
        request.body = IvsExtentionByIdCardImageRequestBody(
            data=dataIvsExtentionByIdCardImageRequestBodyData,
            meta=metaMeta
        )
        response = client.detect_extention_by_id_card_image(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
  • 方式二:使用身份证姓名、身份证号码文本进行校验
    try:
        request = DetectExtentionByNameAndIdRequest()
        listExtentionReqDataByNameAndIdReqDataIvsExtentionByNameAndIdRequestBodyData = [
            ExtentionReqDataByNameAndId(
                verification_name="被验证人的姓名",
                verification_id="被验证人的身份证号码"
            )
        ]
        dataIvsExtentionByNameAndIdRequestBodyData = IvsExtentionByNameAndIdRequestBodyData(
            req_data=listExtentionReqDataByNameAndIdReqDataIvsExtentionByNameAndIdRequestBodyData
        )
        metaMeta = Meta(
            uuid="唯一标识此次请求的ID,用户自定义,不超过64位。例如10eb0091-887f-4839-9929-cbc884f1e20e"
        )
        request.body = IvsExtentionByNameAndIdRequestBody(
            data=dataIvsExtentionByNameAndIdRequestBodyData,
            meta=metaMeta
        )
        response = client.detect_extention_by_name_and_id(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
support.huaweicloud.com/sdkreference-ivs/ivs_07_0003.html