{ "image_id": "wldLe1+kWD3eJTk8Al8nMg==", "request_id": "1529500780,9cfb3bf1-c7f8-435f-8eba-763fa1cfdeeb", "cards": { "0": { "name": "爱新觉罗··玄烨", "gender": "男", "id_card_number": "000003165405049842", "birthday": "1654-05-04", "race": "满", "address": "北b京市东城区景山前街4号紫禁城成乾乾清宫", "type": "1", "side": "front" } }, "time_used": "323" }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2019/3/15 17:50 */ //---------------------------------- // 小明API 识别身份证文字 调用类 //---------------------------------- class freeApi{ private $apiUrl = 'http://api.guaqb.cn/v1/AI/card.php'; /** * url拼接 * @return string */ private function handleUrl($params){ $o = ""; foreach ( $params as $k => $v ) { $o.= "$k=" . urlencode( $v ). "&" ; } $params = substr($o,0,-1); return $params; } /** * 获取结果 * @return array */ public function getResult(){ $params['url'] = 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1561460152459&di=240df29068c7a843e50d48933d8ba456&imgtype=0&src=http%3A%2F%2Fwww.deyang.gov.cn%2Fwcm.files%2Fupload%2FCMSdeyang%2F201412%2F201412040426023.jpg'; $params['key'] = 'you key'; $params['secret'] = 'you secret'; return $this->freeApiCurl($this->apiUrl.'?'.$this->handleUrl($params)); } /** * 请求接口返回内容 * @param string $url [请求的URL地址] * @param string $params [请求的参数] * @param int $ipost [是否采用POST形式] * @return string */ public function freeApiCurl($url,$params=false,$ispost=0){ $ch = curl_init(); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 ); curl_setopt( $ch, CURLOPT_USERAGENT , 'free-api' ); curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 ); curl_setopt( $ch, CURLOPT_TIMEOUT , 60); curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true ); if( $ispost ) { curl_setopt( $ch , CURLOPT_POST , true ); curl_setopt( $ch , CURLOPT_POSTFIELDS , $params ); curl_setopt( $ch , CURLOPT_URL , $url ); } else { if($params){ curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params ); }else{ curl_setopt( $ch , CURLOPT_URL , $url); } } $response = curl_exec( $ch ); if ($response === FALSE) { return false; } curl_close( $ch ); return $response; } } $api = new freeApi(); var_dump($api->getResult());