{ "second": [{ "license_number": { "content": "342221199505035555", "confidence": 99.95 }, "confidence": 99.978, "name": { "content": "郭敏", "confidence": 99.992 }, "file_number": { "content": "500200660530", "confidence": 99.993 } }], "request_id": "1520565741,6fbba005-0de7-4784-9f63-3e8dcc55ca4e", "time_used": 2497, "main": [{ "confidence": 99.904, "valid_from": { "content": "", "confidence": 0 }, "name": { "content": "郭敏", "confidence": 99.742 }, "gender": { "content": "女", "confidence": 99.164 }, "address": { "content": "重庆市渝北区宝圣大道555号", "confidence": 95.756 }, "issued_by": { "content": "重庆市公安局交通管理局", "confidence": 99.398 }, "issue_date": { "content": "20141225", "confidence": 99.987 }, "birthday": { "content": "19950503", "confidence": 93.881 }, "valid_for": { "content": "", "confidence": 0 }, "version": { "content": 2, "confidence": 0 }, "license_number": { "content": "342221199505035555", "confidence": 99.983 }, "nationality": { "content": "我们", "confidence": 100 }, "valid_date": { "content": "20141225至20201225", "confidence": 99.954 }, "class": { "content": "C1", "confidence": 99.996 } }] }
<?php /** * Created by PhpStorm. * User: FZS * Time: 2020/11/02 21:53 */ //---------------------------------- // 驾照正反面识别 调用类 //---------------------------------- class freeApi { private $apiKey = false; private $apiSecret = false; private $apiUrl = 'https://api-cn.faceplusplus.com/cardpp/v2/ocrdriverlicense'; public function __construct($apikey,$apiSecret){ $this->apiKey = $apikey; $this->apiSecret = $apiSecret; } /** * 将JSON内容转为数据,并返回 * @param string $content [内容] * @return array */ public function returnArray($content){ return json_decode($content,true); } /** * 获取结果 * @return array */ public function getResult(){ $params = [ "api_key" => $this->apiKey, "api_secret" => $this->apiSecret, "image_url" => "", ]; $params = http_build_query($params); return $this->returnArray($this->freeApiCurl($this->apiUrl,$params,1)); } /** * 请求接口返回内容 * @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_SSL_VERIFYHOST , false ); curl_setopt( $ch , CURLOPT_SSL_VERIFYPEER , false ); curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' ); 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; } }