PC端输入漫长的身份证号码,想想还可以接受;
手机端输入。。。。
然后我们准备接入OCR,发现微信里也有,要不用用看,反正我没用,链接贴出来
https://mp.weixin.qq.com/wiki?t=resource/res_main&id=21516712284rHWMX
看到社区一堆吐槽,还要发邮件申请。。
看到百度云,腾讯云,阿里云。。都已经成熟,果断弃坑,转向百度云O(∩_∩)O哈哈~
看看百度云API:https://cloud.baidu.com/doc/OCR/OCR-API.html#.E8.BA.AB.E4.BB.BD.E8.AF.81.E8.AF.86.E5.88.AB
实战demo:https://www.cnblogs.com/zh-1721342390/p/9318619.html
上手步骤很简单:
1 从本地选取身份证图片/拍照身份证-
2 将图片转化为base64,ios去掉多余的头部信息data:image/png;base64, ;安卓不需要;
3 调用百度云获取图片信息的接口https://aip.baidubce.com/rest/2.0/ocr/v1/idcard
OK啦
请求示例
HTTP 方法:POST
请求URL: https://aip.baidubce.com/rest/2.0/ocr/v1/idcard
URL参数:
参数 | 值 |
---|---|
access_token | 通过API Key和Secret Key获取的access_token,参考“Access Token获取” |
Header如下:
参数 | 值 |
---|---|
Content-Type | application/x-www-form-urlencoded |
Body中放置请求参数,参数详情如下:
请求参数
参数 | 是否必选 | 类型 | 可选值范围 | 说明 |
---|---|---|---|---|
detect_direction | false | string | true、false | 是否检测图像旋转角度,默认不检测,即:false。朝向是指输入图像是正常方向、逆时针旋转90/180/270度。可选值包括: - true:检测旋转角度并矫正识别; - false:不检测旋转角度,针对摆放情况不可控制的情况建议本参数置为true。 |
id_card_side | true | string | front、back | front:身份证含照片的一面;back:身份证带国徽的一面 |
image | true | string | - | 图像数据,base64编码后进行urlencode,要求base64编码和urlencode后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式 |
detect_risk | false | string | true,false | 是否开启身份证风险类型(身份证复印件、临时身份证、身份证翻拍、修改过的身份证)功能,默认不开启,即:false。可选值:true-开启;false-不开启 |
请求代码示例
提示一:使用示例代码前,请记得替换其中的示例Token、图片地址或Base64信息。
提示二:部分语言依赖的类或库,请在代码注释中查看下载地址。
返回示例
{
"log_id": 2648325511,
"direction": 0,
"image_status": "normal",
"idcard_type": "normal",
"edit_tool": "Adobe Photoshop CS3 Windows",
"words_result": {
"住址": {
"location": {
"left": 267,
"top": 453,
"width": 459,
"height": 99
},
"words": "南京市江宁区弘景大道3889号"
},
"公民身份号码": {
"location": {
"left": 443,
"top": 681,
"width": 589,
"height": 45
},
"words": "330881199904173914"
},
"出生": {
"location": {
"left": 270,
"top": 355,
"width": 357,
"height": 45
},
"words": "19990417"
},
"姓名": {
"location": {
"left": 267,
"top": 176,
"width": 152,
"height": 50
},
"words": "伍云龙"
},
"性别": {
"location": {
"left": 269,
"top": 262,
"width": 33,
"height": 52
},
"words": "男"
},
"民族": {
"location": {
"left": 492,
"top": 279,
"width": 30,
"height": 37
},
"words": "汉"
}
},
"words_result_num": 6
}
好啦,是不是炒鸡简单