PHP识别营业执照图片(调用阿里云市场接口),涵数来源:梦行云软件

function get_business_info($img_path,$appcode){ //识别营业执照图片

$r=array('state'=>'fail','msg'=>'图片不存在',);

if(!is_file($img_path)){return $r;}

$info=getimagesize($img_path);

if($info[0]>$info[1]){$type='buslicense';}else{$type='businesslicense';}

//var_dump($type);

//$type='businesslicense 竖 or buslicense 横';

$host = "https://bnesslic.market.alicloudapi.com";

    $path = "/".$type;

    $method = "POST";

    $headers = array();

    array_push($headers, "Authorization:APPCODE " . $appcode);

    //根据API的要求,定义相对应的Content-Type

    array_push($headers, "Content-Type".":"."application/x-www-form-urlencoded; charset=UTF-8");

    $querys = "";

$bodys = 'image='.imgToBase64($img_path).'';

    $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);

    $out_put = curl_exec($curl);

$t=explode('{"code"', $out_put);

    $v='{"code"'.$t[1];

$r=json_decode($v,1);

if($r['code']!=1){$r['state']='fail';return $r;}

if(isset($r['result']['社会信用代码']['words']) && $r['result']['社会信用代码']['words']!='无'){$r['result']['统一社会信用代码']['words']=$r['result']['社会信用代码']['words'];}

if(isset($r['result']['证件编号']['words']) && $r['result']['证件编号']['words']!='无'){$r['result']['统一社会信用代码']['words']=$r['result']['证件编号']['words'];}

if(!isset($r['result']['统一社会信用代码'])){$r['state']='fail';return $r;}

if(@$r['result']['统一社会信用代码']['words']=='' || @$r['result']['统一社会信用代码']['words']=='无'){$r['state']='fail';return $r;}

$msg=$r['msg'];

$r=$r['result'];

$r=format_business_info($r);

$r['state']='success';

$r['msg']=$msg;

return $r;

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

友情链接更多精彩内容