zoukankan      html  css  js  c++  java
  • 关于阿里云图片识别接口的demo

    服务器处理过程

    $host = "https://dm-53.data.aliyun.com";
    $path = "/rest/160601/ocr/ocr_vehicle.json";
    $method = "POST";
    $appcode = "你自己申请的appcode";

    $headers = array();
    array_push($headers, "Authorization:APPCODE " . $appcode);
    //根据API的要求,定义相对应的Content-Type
    array_push($headers, "Content-Type".":"."application/json; charset=UTF-8");
    // array_push($headers,"Expect".":"."100-continue");
    array_push($headers,"Expect:");
    $querys = "";
    $bodys = "{
    \"inputs\":[
    {
    \"image\":{
    \"dataType\":50,
    \"dataValue\":\"".$base64."\"
    }
    }
    ]
    }";
    $url = $host . $path;
    // var_dump($headers);exit;
    $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);
    // curl_setopt($curl, CURLOPT_HTTPHEADER, array( '"Expect":"100-continue"'));
    curl_setopt($curl, CURLOPT_HTTPHEADER, array( 'Expect:' ) );

    if (1 == strpos("$".$host, "https://"))
    {
    curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
    curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
    }
    if(!curl_errno($curl)){
    $info = curl_getinfo($curl);
    echo "<pre>";
    // var_dump($info);
    echo "</pre>";
    // echo "<pre>";
    // $rtn=json_decode($rtn,true);
    // echo $rtn;
    // echo "</pre>";
    } else {
    echo 'Curl error: ' . curl_error($curl);
    }

    返回数据的处理

    $response=curl_exec($curl);
    $res=substr($str,strpos($str,"dataValue")+13);
    // $own=substr($str,strpos($str,"owner"));
    $a=substr($res,0,strrpos($res,"}")-4);
    $b=stripslashes($a);
    $pl=strpos($b,"plate_num");

    $ow=strpos($b,"owner");
    $len=$pl-$ow;
    $own=mb_substr($b,strpos($b,"owner")+2,$len-17);
    $c=json_decode($b,TRUE);

  • 相关阅读:
    sql查询
    PHP常用的设计模式
    PHP内存管理和垃圾回收机制
    记一次面试
    获取py文件函数名及动态调用
    正确解决 mysql 导出文件 分隔符 问题
    解决ValueError: cannot convert float NaN to integer
    Python ---接口返回值中文编码问题
    pandas python 读取大文件
    【neo4J】后台关闭后,前端还能打开视图
  • 原文地址:https://www.cnblogs.com/liliuguang/p/7222117.html
Copyright © 2011-2022 走看看