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;