阿里接口平台--印刷字识别_身份证识别API接口phpdemo使用

来源:互联网 发布:手机cpu实时数据 编辑:程序博客网 时间:2024/04/29 15:25

一.打开阿里云官网



二.找到API市场的印刷文字识别_身份证识别



三.注册账号,花1分钱购买使用



四.记下appcode,我使用的是php演示接口请求

<?php    $host = "https://dm-51.data.aliyun.com";    $path = "/rest/160601/ocr/ocr_idcard.json";    $method = "POST";    $appcode = "06a76442d3da4685bdd6cb7b0e4f3";//此处是你购买后系统提供的code    $headers = array();    array_push($headers, "Authorization:APPCODE " . $appcode);    //根据API的要求,定义相对应的Content-Type    array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");$base_mage = base64_encode(file_get_contents('sfz.jpg'));//sfz.jpg为身份证图片路径,此处默认在同级目录    $querys = "";    $bodys = "{    \"inputs\": [        {            \"image\": {                \"dataType\": 50,                \"dataValue\": \"$base_mage\"            },            \"configure\": {                \"dataType\": 50,                \"dataValue\": \"{\\\"side\\\":\\\"face\\\"}\"            }        }    ]}";    $url = $host . $path;    $curl = curl_init();    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);    curl_setopt($curl, CURLOPT_URL, $url);    curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);    curl_setopt($curl, CURLOPT_FAILONERROR, false);    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);    curl_setopt($curl, CURLOPT_HEADER, true);    if (1 == strpos("$".$host, "https://"))    {        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);    }    curl_setopt($curl, CURLOPT_POSTFIELDS, $bodys);$res = curl_exec($curl);echo "<pre>";    print_r($res);?>

五.运行程序在浏览器查看结果



六.一些细节

1,正反面识别,要改动请求参数中的face

{    "inputs": [        {            "image": {                "dataType": 50,                "dataValue": "图片二进制数据的base64编码"                },            "configure": {                "dataType": 50,                "dataValue": "{\"side\":\"face\"}"  #身份证正反面类型:face/back            }        }    ]}

2,结果说明

正面返回结果:{    "outputs": [    {        "outputLabel": "ocr_id",        "outputMulti": {},        "outputValue": {            "dataType": 50,            "dataValue": "{                \"address\"    : \"浙江省杭州市余杭区文一西路969号\",   #地址信息                \"config_str\" : \"{\\\"side\\\":\\\"face\\\"}\",                #配置信息,同输入configure                \"face_rect\":{                    \"angle\": -90,                    \"center\":{                        \"x\" : 952,                        \"y\" : 325.5                    },                    \"size\":{                        \"height\":181.99,                        \"width\":164.99                        }                },                          #人脸位置,center表示人脸矩形中心坐标,size表示人脸矩形长宽,angle表示矩形顺时针旋转的度数。                \"name\" : \"张三\",                                  #姓名                \"nationality\": \"汉\", #民族                 \"num\" : \"1234567890\",                             #身份证号                \"sex\" : \"男\",                                     #性别                \"birth\" : \"20000101\",                             #出生日期                \"nationality\" : \"汉\",                             #民族                \"success\" : true                                  #识别结果,true表示成功,false表示失败            }"        }    }]}反面返回结果:{    "outputs": [    {        "outputLabel": "ocr_id",        "outputMulti": {},        "outputValue": {            "dataType": 50,            "dataValue": "{                \"config_str\" :                 \"{\\\"side\\\":\\\"back\\\"}\",#配置信息,同输入configure                \"start_date\" : \"19700101\",       #有效期起始时间                \"end_date\" : \"19800101\",         #有效期结束时间                \"issue\" : \"杭州市公安局\",         #签发机关                \"success\" : true                   #识别结果,true表示成功,false表示失败            }"        }    }]}


阅读全文
0 0
原创粉丝点击