Python使用阿里API进行身份证识别

1. 作者介绍

孟莉苹,女,西安工程大学电子信息学院,2021级硕士研究生,张宏伟人工智能课题组
研究方向:机器视觉与人工智能
电子邮件:[email protected]

2. 身份证识别介绍

凭借领先的人工智能与知识图谱技术,对身份证正反面自动识别,并提取姓名、出生日期、身份证号、住址、性别、民族、发证机关等身份证实体信息。

3. 调用阿里智能云API

步骤一 :浏览器搜索阿里云,使用支付宝或者其他阿里APP扫码后用手机验证码登陆。
在这里插入图片描述

步骤二:登录后找到身份证识别OCR产品,并购买
在这里插入图片描述

步骤三:购买成功后点击管理控制台
在这里插入图片描述

步骤四:查看到身份证识别的AppCode等信息
在这里插入图片描述
步骤五:查看Python实现代码,并将代码中的appcode更换为自己的appcode
在这里插入图片描述
步骤六:查看请求参数,调用该API需要在代码中提供身份证号和姓名,无需上传身份证图片
在这里插入图片描述
步骤七:运行代码后,返回值有实名认证是否通过、身份证号、姓名、家庭住址及出生日期等
在这里插入图片描述

4. 代码解析

4.1 完整代码

# coding=UTF-8
import requests
host = 'https://idcert.market.alicloudapi.com'
path = '/idcard'
method = 'GET'
appcode = '你自己的AppCode'#开通服务后 买家中心-查看AppCode
querys = 'idCard=511126******064713&name=杨过'
bodys = {
    
    }
url = host + path + '?' + querys
header = {
    
    "Authorization":'APPCODE ' + appcode}
try:
    res = requests.get(url,headers=header)
except :
    print("URL错误")
    exit()
httpStatusCode = res.status_code

if(httpStatusCode == 200):
    print("正常请求计费(其他均不计费)")
    print(res.text)
else:
    httpReason = res.headers['X-Ca-Error-Message']
    if(httpStatusCode == 400 and httpReason == 'Invalid Param Location'):
        print("参数错误")
    elif(httpStatusCode == 400 and httpReason == 'Invalid AppCode'):
        print("AppCode错误")
    elif(httpStatusCode == 400 and httpReason == 'Invalid Url'):
        print("请求的 Method、Path 或者环境错误")
    elif(httpStatusCode == 403 and httpReason == 'Unauthorized'):
        print("服务未被授权(或URL和Path不正确)")
    elif(httpStatusCode == 403 and httpReason == 'Quota Exhausted'):
        print("套餐包次数用完")
    elif(httpStatusCode == 403 and httpReason == 'Api Market Subscription quota exhausted'):
        print("套餐包次数用完,请续购套餐")
    elif(httpStatusCode == 500 ):
        print("API网关错误")
    else:
        print("参数名错误 或 其他错误")
        print(httpStatusCode)
        print(httpReason)

4.2 实验结果

在这里插入图片描述

参考

1.直接跳转购买阿里云的身份证识别OCR链接:
https://market.aliyun.com/products/57000002/cmapi022049.html?spm=5176.shop.result.7.41a272026nu6Gi&innerSource=search#sku=yuncode1604900000

猜你喜欢

转载自blog.csdn.net/m0_37758063/article/details/123825323