{ "image_id": "7OO7N1dYiJjszvV38oKVpw==", "request_id": "1491569448,de5a441f-6c6f-4955-896c-37b8bb2d4197", "time_used": 915, "hands": [{ "gesture": { "unknown": 0, "heart_a": 99, "heart_b": 1, "heart_c": 0, "heart_d": 0, "ok": 0, "hand_open": 0, "thumb_up": 0, "thumb_down": 0, "rock": 0, "namaste": 0, "palm_up": 0, "fist": 0, "index_finger_up": 0, "double_finger_up": 0, "victory": 0, "big_v": 0, "phonecall": 0, "beg": 0, "thanks": 0 }, "hand_rectangle": { "width": 456, "top": 0, "height": 500, "left": 0 } }] }
<?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/humanbodypp/v1/gesture'; 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 , '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; } }