php接入百度AI 文字识别api

1.ceshi.php

access_token();
//定义参数并去请求api 
$url = 'https://aip.baidubce.com/rest/2.0/ocr/v1/general?access_token=' . $access_token;
$img = file_get_contents('1.png');
$img = base64_encode($img);
$bodys = array(
        "image" => $img
);
$data = json_decode(request_post($url, $bodys));//解码json数据
//重定义数据
$arr = array();
foreach ($data->words_result as $k=>&$v){
    $arr[]=$v->words;
}
//转换成字符串
var_dump(json_encode($arr));




2.curl.php

_request($url,true,'POST',$post_data);
        $res = json_decode($res, true);
        return $res['access_token'];
    }
}
?>

你可能感兴趣的:(php接入百度AI 文字识别api)