识别身份证

/**
* 根据身份证照片获取信息
*/
public function idpositiveGetInfo()
{
$url = input('url')?:exit('00');
$openid = input('openid')?:exit('00');

$host = "https://12345678.market.alicloudapi.com";
$path = "/getapilist/ocr/idcard";
$method = "POST";
$appcode = "";
$headers = array();
array_push($headers, "Authorization:APPCODE " . $appcode);
//$url = 'uploads/20191125/5ddb7d5e04f904850.jpg';
//$url = 'uploads/20191125/5ddb99c429dc16893.jpg';
$querys = "url=https://mamimei.wicep.cn/".$url;
$bodys = "";
$url = $host . $path . "?" . $querys;

$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);
}
$data = json_decode(curl_exec($curl),true);
curl_close($curl);

if(!isset($data['status']) || $data['status']!='OK'){
$this->error('获取信息失败');
}
$info = $data['info'];
$key = ['name','sex','nation','year','month','day','address','number'];
$info_key = array_keys($info);
sort($info_key);
sort($key);

if($info_key != $key){
$this->error('拉取信息失败');
}

if(sort($info_key) != sort($key)) $this->error('获取信息失败2');
$this->success('ok',$info);

}
posted @ 2020-10-26 17:34  php毛宏历的博客  阅读(264)  评论(0编辑  收藏  举报