diff --git a/README.md b/README.md index 4fed07b..c60f2ce 100644 --- a/README.md +++ b/README.md @@ -1,40 +1,444 @@ # TencentYoutuyun-person-face-service -php sdk for [腾讯优图云人脸服务](http://open.youtu.qq.com/) -## 安装(使用composer获取或者直接下载源码集成) +php sdk for [腾讯优图开放平台](http://open.youtu.qq.com) + +## 安装(直接下载源码集成) -### 使用composer获取 -php composer.phar require TencentYoutuyun/php-sdk -调用请参考示例1 -### 直接下载源码集成 从github下载源码装入到您的程序中,并加载include.php -调用请参考示例2 -## 修改配置 -修改TencentYoutuyun/Conf.php内的appid等信息为您的配置 +## 名词 + + - `AppId` 平台添加应用后分配的AppId + - `SecretId` 平台添加应用后分配的SecretId + - `SecretKey` 平台添加应用后分配的SecretKey + - `签名` 接口鉴权凭证,由`AppId`、`SecretId`、`SecretKey`等生成,详见 + + + +## 使用示例 + +##### 引入SDK +``` +require('./include.php'); +use TencentYoutuyun\Youtu; +use TencentYoutuyun\Conf; +use TencentYoutuyun\Auth; +``` +##### 设置APP 鉴权信息 +``` +$appid='your appid'; +$secretId='your secretId '; +$secretKey='your secretKey'; +$userid='your qq'; +``` -## 人脸对比示例1(使用composer安装后生成的autoload) -```php - 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/detectface'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'mode' => $isbigface + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @brief detectfaceurl + * @param url 图片url + * @param isbigface 是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function detectfaceurl($url, $isbigface) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/detectface'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + 'mode' => $isbigface + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @brief faceshape + * @param image_path 待检测的路径 + * @param isbigface 是否大脸模式 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function faceshape($image_path, $isbigface) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/faceshape'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'mode' => $isbigface + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief faceshapeurl + * @param url 图片url + * @param isbigface 是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function faceshapeurl($url, $isbigface) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/faceshape'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + 'mode' => $isbigface + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @brief facecompare + * @param image_path_a 待比对的A图片数据 + * @param image_path_b 待比对的B图片数据 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function facecompare($image_path_a, $image_path_b) { + + $real_image_path_a = realpath($image_path_a); + $real_image_path_b = realpath($image_path_b); + if (!file_exists($real_image_path_a)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path_a.' not exists', 'data' => array()); + } + + if (!file_exists($real_image_path_b)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path_b.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/facecompare'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data_a = file_get_contents($real_image_path_a); + $image_data_b = file_get_contents($real_image_path_b); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'imageA' => base64_encode($image_data_a), + 'imageB' => base64_encode($image_data_b) + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief facecompareurl + * @param urlA 待比对的A图片url + * @param urlB 待比对的B图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function facecompareurl($urlA, $urlB) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/facecompare'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'urlA' => $urlA, + 'urlB' => $urlB + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + + + /** + * @brief faceverify + * @param person_id 待验证的人脸id + * @param image_path 待验证的图片路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function faceverify($image_path,$person_id) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/faceverify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'person_id' =>$person_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief faceverifyurl + * @param person_id 待验证的人脸id + * @param url 待验证的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function faceverifyurl($url,$person_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/faceverify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + 'person_id' =>$person_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + + /** + * @brief faceidentify + * @param group_id 识别的组id + * @param image_path 待识别的图片路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function faceidentify($image_path,$group_id) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/faceidentify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'group_id' =>$group_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief faceidentifyurl + * @param group_id 识别的组id + * @param group_ids 个体存放的组id,可以指定多个组id,用户指定 + * @param url 待识别的图片的url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function faceidentifyurl($url,$group_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/faceidentify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + 'group_id' =>$group_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief multifaceidentify + * @param group_id 识别的组id + * @param group_ids 个体存放的组id,可以指定多个组id,用户指定 + * @param image_path 待识别的图片路径 + * @param topn 候选人脸数量,一般使用默认值5 + * @param min_size 人脸检测最小尺寸,一般使用默认值40 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function multifaceidentify($image_path,$group_id, array $group_ids, $topn=5, $min_size=40) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/multifaceidentify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'group_id' =>$group_id, + 'group_ids' =>$group_ids, + 'topn' =>$topn, + 'min_size' =>$min_size + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief multifaceidentifyurl + * @param group_id 识别的组id + * @param group_ids 个体存放的组id,可以指定多个组id,用户指定 + * @param url 待识别的图片的url + * @param topn 候选人脸数量,一般使用默认值5 + * @param min_size 人脸检测最小尺寸,一般使用默认值40 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function multifaceidentifyurl($url,$group_id, array $group_ids, $topn=5, $min_size=40) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/multifaceidentify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + 'group_id' =>$group_id, + 'group_ids' =>$group_ids, + 'topn' =>$topn, + 'min_size' =>$min_size + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief newperson + * @param person_id 新建的个体id,用户指定,需要保证app_id下的唯一性 + * @param person_name 个体名字 + * @param group_ids 新建的个体存放的组id,可以指定多个组id,用户指定(组默认创建) + * @param image_path 包含个体人脸的图片数据 + * @param person_tag 备注信息,用户自解释字段 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function newperson($image_path, $person_id, array $group_ids, $person_name='', $person_tag='') { + $real_image_path = realpath($image_path); + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/newperson'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'person_id' =>$person_id, + 'group_ids' =>$group_ids, + 'person_name' =>$person_name, + 'tag' => $person_tag + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief newpersonurl + * @param person_id 新建的个体id,用户指定,需要保证app_id下的唯一性 + * @param person_name 个体名字 + * @param group_ids 新建的个体存放的组id,可以指定多个组id,用户指定(组默认创建) + * @param url 包含个体人脸的图片url + * @param person_tag 备注信息,用户自解释字段 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function newpersonurl($url, $person_id, array $group_ids, $person_name='', $person_tag='') { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/newperson'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + 'person_id' =>$person_id, + 'group_ids' =>$group_ids, + 'person_name' =>$person_name, + 'tag' => $person_tag + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief delperson + * @param person_id 待删除的个体id + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + + public static function delperson($person_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/delperson'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'person_id' =>$person_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + + /** + * @brief addface + * @param person_id 新增人脸的个体身份id + * @param image_path_arr 待增加的包含人脸的图片数据,可加入多张(包体大小<2m) + * @param facetag 人脸备注信息,用户自解释字段 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function addface($person_id,array $image_path_arr, $facetag='') { + $image_data_arr=array(); + foreach($image_path_arr as $one_path){ + if (!file_exists($one_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$one_path.' not exists', 'data' => array()); + } + $image_data=file_get_contents($one_path); + array_push($image_data_arr,base64_encode($image_data)); + } + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/addface'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'images' => $image_data_arr, + 'person_id' =>$person_id, + 'tag' => $facetag + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief addfaceurl + * @param person_id 新增人脸的个体身份id + * @param url_arr 待增加的包含人脸的图片url,可加入多张(包体大小<2m) + * @param facetag 人脸备注信息,用户自解释字段 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function addfaceurl($person_id,array $url_arr, $facetag='') { + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/addface'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'urls' => $url_arr, + 'person_id' =>$person_id, + 'tag' => $facetag + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + + /** + * @brief delface + * @param person_id 待删除人脸的个体身份id + * @param face_id_arr 待删除的人脸id + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function delface($person_id,array $face_id_arr) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/delface'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'face_ids' => $face_id_arr, + 'person_id' =>$person_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + + /** + * @brief setinfo + * @param person_id 待设置的个体身份id + * @param person_name 新设置的个体名字 + * @param person_tag 新设置的人备注信息 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function setinfo($person_name,$person_id, $person_tag) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/setinfo'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'person_name' => $person_name, + 'person_id' =>$person_id, + 'tag' => $person_tag + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + + /** + * @brief getinfo + * @param person_id 待查询的个体身份id + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function getinfo($person_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/getinfo'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'person_id' =>$person_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief getgroupids + * @param rsp 返回的组列表查询结果,JSON字符串,字段参见API文档 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function getgroupids() { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/getgroupids'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief getpersonids + * @param group_id 待查询的组id + * @param rsp 返回的个体列表查询结果,JSON字符串,字段参见API文档 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function getpersonids($group_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/getpersonids'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'group_id' =>$group_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief getfaceids + * @param person_id 待查询的个体id + * @param rsp 返回的人脸列表查询结果,JSON字符串,字段参见API文档 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function getfaceids($person_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/getfaceids'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'person_id' =>$person_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @brief getfaceinfo + * @param face_id 待查询的人脸id + * @param rsp 返回的人脸信息查询结果,JSON字符串,字段参见API文档 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function getfaceinfo($face_id) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/api/getfaceinfo'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'face_id' =>$face_id, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + ), + ); + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function fuzzydetect($image_path) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/fuzzydetect'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $url 图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function fuzzydetecturl($url) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/fuzzydetect'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function fooddetect($image_path) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/fooddetect'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $url 图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function fooddetecturl($url) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/fooddetect'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function imagetag($image_path) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imagetag'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $url 图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function imagetagurl($url) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imagetag'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function imageporn($image_path) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageporn'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $url 图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function imagepornurl($url) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageporn'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * imageterrorism 暴恐图片识别 + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function imageterrorism($image_path) { + + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageterrorism'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * imageterrorismurl 暴恐图片识别 + * @param $url 图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function imageterrorismurl($url) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageterrorism'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * carclassify 车辆属性识别 + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function carclassify($image_path) { - public static function DetectFace($image_path) { + $real_image_path = realpath($image_path); - $image_path = realpath($image_path); - - if (!file_exists($image_path)) + if (!file_exists($real_image_path)) { return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/detectface'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/carapi/carclassify'; + $sign = Auth::appSign($expired, Conf::$USER_ID); - $image_data = file_get_contents($image_path); + $image_data = file_get_contents($real_image_path); $post_data = array( - "app_id" => Conf::APPID, - "image" => base64_encode($image_data) + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), ); $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * carclassifyurl 车辆属性识别 + * @param $url 图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function carclassifyurl($url) { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageterrorism'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, 'url' => $url, + ); + + $req = array( + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; } - public static function FaceShape($image_path) { + /** + * @param $url 图片url + * @param $card_type 身份证照片类型,0 表示身份证正面, 1表示身份证反面 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function idcardocr($image_path, $card_type = 0, $seq = '') { - $image_path = realpath($image_path); - - if (!file_exists($image_path)) + $real_image_path = realpath($image_path); + + if (!file_exists($real_image_path)) { return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/faceshape'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/idcardocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data), + 'seq' => $seq, + 'card_type' => $card_type, + ); + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + /** + * @param $url 图片url + * @param $card_type 身份证照片类型,0 表示身份证正面, 1表示身份证反面 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function idcardocrurl($url, $card_type, $seq = '') { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/idcardocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); - $image_data = file_get_contents($image_path); $post_data = array( - "app_id" => Conf::APPID, - "image" => base64_encode($image_data) + 'app_id' => Conf::$APPID, + 'url' => $url, + 'seq' => $seq, + 'card_type' => $card_type, ); $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + + /** + * @param $url 图片url + * @param $retimage 是否返回名片图像 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function namecardocrurl($url, $retimage = 1, $seq = '') + { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/namecardocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, 'url' => $url, + 'seq' => $seq, + 'retimage'=> (bool)$retimage + ); + + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + + return $ret; + } + + public static function livegetfour($seq = '') + { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/openliveapi/livegetfour'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'seq' => $seq + ); + + + $req = array( + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } + public static function livedetectfour($validate_data,$video_path,$card_path,$compare_card=false,$seq = '') + { - public static function FaceCompare($image_path_a, $image_path_b) { + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/openliveapi/livedetectfour'; + $sign = Auth::appSign($expired, Conf::$USER_ID); - $image_path_a = realpath($image_path_a); - $image_path_b = realpath($image_path_b); - if (!file_exists($image_path_a)) + $real_video_path = realpath($video_path); + if (!file_exists($real_video_path)) { - return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path_a.' not exists', 'data' => array()); + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$video_path.' not exists', 'data' => array()); } - if (!file_exists($image_path_b)) + $video_data = file_get_contents($real_video_path); + + if($compare_card) { - return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path_b.' not exists', 'data' => array()); + $real_card_path = realpath($card_path); + if (!file_exists($real_card_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$card_path.' not exists', 'data' => array()); + } + + $card_data = file_get_contents($real_card_path); + $post_data = array( + 'app_id' => Conf::$APPID, + 'validate_data' => $validate_data, + 'compare_flag' => true, + 'video' => base64_encode($video_data), + 'card' => base64_encode($card_data), + 'seq' => $seq + ); + } + else + { + $post_data = array( + 'app_id' => Conf::$APPID, + 'validate_data' => $validate_data, + 'compare_flag' => false, + 'video' => base64_encode($video_data), + 'seq' => $seq + ); + } + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); } + return $ret; + } + + public static function idcardlivedetectfour($idcard_number,$idcard_name,$validate_data,$video_path,$seq = '') + { $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/facecompare'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/openliveapi/idcardlivedetectfour'; + $sign = Auth::appSign($expired, Conf::$USER_ID); - $image_data_a = file_get_contents($image_path_a); - $image_data_b = file_get_contents($image_path_b); + $real_video_path = realpath($video_path); + if (!file_exists($real_video_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$video_path.' not exists', 'data' => array()); + } + + $video_data = file_get_contents($real_video_path); $post_data = array( - "app_id" => Conf::APPID, - "imageA" => base64_encode($image_data_a), - "imageB" => base64_encode($image_data_b) + 'app_id' => Conf::$APPID, + 'idcard_number' => $idcard_number, + 'idcard_name' => $idcard_name, + 'validate_data' => $validate_data, + 'video' => base64_encode($video_data), + 'seq' => $seq ); + $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function FaceVerify($image_path,$person_id) { + public static function idcardfacecompare($idcard_number,$idcard_name,$image_path,$seq = '') + { - $image_path = realpath($image_path); - - if (!file_exists($image_path)) + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/openliveapi/idcardfacecompare'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $real_image_path = realpath($image_path); + if (!file_exists($real_image_path)) { return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } + $image_data = file_get_contents($real_image_path); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'idcard_number' => $idcard_number, + 'idcard_name' => $idcard_name, + 'image' => base64_encode($image_data), + 'seq' => $seq + ); + + + $req = array( + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + $rsp = Http::send($req); + + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + public static function validateidcard($idcard_number,$idcard_name,$seq = '') + { + $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/faceverify'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/openliveapi/validateidcard'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + - $image_data = file_get_contents($image_path); $post_data = array( - "app_id" => Conf::APPID, - "image" => base64_encode($image_data), - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'idcard_number' => $idcard_number, + 'idcard_name' => $idcard_name, + 'seq' => $seq ); + $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function FaceIdentify($image_path,$group_id) { + /** + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function generalocr($image_path, $seq='') { - $image_path = realpath($image_path); - - if (!file_exists($image_path)) + $real_image_path = realpath($image_path); + if(!file_exists($real_image_path)) { - return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/faceidentify'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/generalocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); - $image_data = file_get_contents($image_path); $post_data = array( - "app_id" => Conf::APPID, - "image" => base64_encode($image_data), - "group_id" =>$group_id, + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data) ); $req = array( - 'url' => $url, + 'url' => $postUrl, + 'method' => 'post', + 'timeout' => 10, + 'data' => json_encode($post_data), + 'header' => array( + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', + ), + ); + + $rsp = Http::send($req); + $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } + return $ret; + } + + /** + * @param $url 待检测的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function generalocrurl($url, $seq='') { + + $expired = time() + self::EXPIRED_SECONDS; + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/generalocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $post_data = array( + 'app_id' => Conf::$APPID, + 'url' => $url + ); + + $req = array( + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function NewPerson($image_path, $person_id,array $group_ids) { - $image_path = realpath($image_path); - if (!file_exists($image_path)) + /** + * @param $image_path 待检测的路径 + * @param $card_type 图片类型:行驶证/驾驶证 0/1 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function driverlicenseocr($image_path, $card_type, $seq='') { + + $real_image_path = realpath($image_path); + if(!file_exists($real_image_path)) { - return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/newperson'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/driverlicenseocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); - $image_data = file_get_contents($image_path); $post_data = array( - "app_id" => Conf::APPID, - "image" => base64_encode($image_data), - "person_id" =>$person_id, - "group_ids" =>$group_ids + 'app_id' => Conf::$APPID, + 'type' => $card_type, + 'image' => base64_encode($image_data) ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - - public static function DelPerson($person_id) { + + /** + * @param $url 待检测的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function driverlicenseocrurl($url, $card_type, $seq='') { $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/delperson'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/driverlicenseocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); $post_data = array( - "app_id" => Conf::APPID, - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'type' => $card_type, + 'url' => $url ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function AddFace($person_id,array $image_path_arr) { - $image_data_arr=array(); - foreach($image_path_arr as $one_path){ - $image_path = realpath($one_path); - if (!file_exists($image_path)) - { - return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$one_path.' not exists', 'data' => array()); - } - $image_data=file_get_contents($image_path); - array_push($image_data_arr,base64_encode($image_data)); + /** + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function bcocr($image_path, $seq='') { + + $real_image_path = realpath($image_path); + if(!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); } + $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/addface'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/bcocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); $post_data = array( - "app_id" => Conf::APPID, - "images" => $image_data_arr, - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data) ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function DelFace($person_id,array $face_id_arr) { + /** + * @param $url 待检测的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function bcocrurl($url, $seq='') { $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/delface'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . '/youtu/ocrapi/bcocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); $post_data = array( - "app_id" => Conf::APPID, - "face_ids" => $face_id_arr, - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'url' => $url ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function SetInfo($person_name,$person_id) { + /** + * creditcardocr 银行卡OCR识别 + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function creditcardocr($image_path, $seq='') { + + $real_image_path = realpath($image_path); + if(!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/setinfo'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/creditcardocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); $post_data = array( - "app_id" => Conf::APPID, - "person_name" => $person_name, - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data) ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function GetInfo($person_id) { + /** + * creditcardocrurl 银行卡OCR识别 + * @param $url 待检测的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function creditcardocrurl($url, $seq='') { $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/getinfo'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/creditcardocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); $post_data = array( - "app_id" => Conf::APPID, - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'url' => $url ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function GetGroupIds() { + /** + * bizlicenseocr 营业执照OCR识别 + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function bizlicenseocr($image_path, $seq='') { + + $real_image_path = realpath($image_path); + if(!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/getgroupids'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/bizlicenseocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); $post_data = array( - "app_id" => Conf::APPID + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data) ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function GetPersonIds($group_id) { + /** + * bizlicenseocrurl 营业执照OCR识别 + * @param $url 待检测的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function bizlicenseocrurl($url, $seq='') { $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/getpersonids'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/bizlicenseocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); $post_data = array( - "app_id" => Conf::APPID, - "group_id" =>$group_id, + 'app_id' => Conf::$APPID, + 'url' => $url ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function GetFaceIds($person_id) { + /** + * plateocr 车牌OCR识别 + * @param $image_path 待检测的路径 + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function plateocr($image_path, $seq='') { + + $real_image_path = realpath($image_path); + if(!file_exists($real_image_path)) + { + return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); + } $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/getfaceids'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/plateocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); + + $image_data = file_get_contents($real_image_path); $post_data = array( - "app_id" => Conf::APPID, - "person_id" =>$person_id, + 'app_id' => Conf::$APPID, + 'image' => base64_encode($image_data) ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } - public static function GetFaceInfo($face_id) { + /** + * plateocrurl 车牌OCR识别 + * @param $url 待检测的图片url + * @return 返回的结果,JSON字符串,字段参见API文档 + */ + public static function plateocrurl($url, $seq='') { $expired = time() + self::EXPIRED_SECONDS; - $url = Conf::API_YOUTU_END_POINT . 'youtu/api/getfaceinfo'; - $sign = Auth::appSign($expired,self::USER_ID); + $postUrl = Conf::$END_POINT . 'youtu/ocrapi/plateocr'; + $sign = Auth::appSign($expired, Conf::$USER_ID); $post_data = array( - "app_id" => Conf::APPID, - "face_id" =>$face_id, + 'app_id' => Conf::$APPID, + 'url' => $url ); $req = array( - 'url' => $url, + 'url' => $postUrl, 'method' => 'post', 'timeout' => 10, 'data' => json_encode($post_data), 'header' => array( - 'Authorization: '.$sign, + 'Authorization:'.$sign, + 'Content-Type:text/json', + 'Expect: ', ), ); + $rsp = Http::send($req); $ret = json_decode($rsp, true); + + if(!$ret){ + return self::getStatusText(); + } return $ret; } } - - diff --git a/sample.php b/sample.php index c2e59fc..3650a44 100644 --- a/sample.php +++ b/sample.php @@ -2,22 +2,81 @@ require('./include.php'); use TencentYoutuyun\Youtu; +use TencentYoutuyun\Conf; -#$uploadRet = YouTu::DetectFace('you_path.jpg'); -#$uploadRet = YouTu::NewPerson('you_path.jpg','123456',array('test_groupid','test_groupid2','test_groupid3')); -#$uploadRet = YouTu::FaceVerify('you_path.jpg','123456'); -#$uploadRet = YouTu::FaceIdentify('you_path.jpg','test_groupid'); -#$uploadRet = YouTu::NewPerson('you_path.jpg','123456',array('test_groupid','test_groupid2','test_groupid3')); -#$uploadRet = YouTu::DelPerson('123456'); -#$uploadRet = YouTu::AddFace('123456',array('you_path.jpg')); -#$uploadRet = YouTu::DelFace('123456',array('1027423607359340543')); -#$uploadRet = YouTu::SetInfo('name_groupid','123456'); -#$uploadRet = YouTu::GetInfo('123456'); -#$uploadRet = YouTu::GetGroupIds(); -#$uploadRet = YouTu::GetPersonIds('test_groupid'); -#$uploadRet = YouTu::GetFaceIds('123456'); -#$uploadRet = YouTu::GetFaceInfo('1027425345818656767'); -$uploadRet = YouTu::FaceCompare('you_path_one.jpg', 'you_path_two.jpg'); +// 设置APP 鉴权信息 请在http://open.youtu.qq.com 创建应用 + +$appid=''; +$secretId=''; +$secretKey=''; +$userid=''; + + +Conf::setAppInfo($appid, $secretId, $secretKey, $userid,conf::API_YOUTU_END_POINT ); + + +// 人脸检测 调用列子 +//$uploadRet = YouTu::detectface('a.jpg', 1); +//var_dump($uploadRet); + + +// 人脸定位 调用demo +//$uploadRet = YouTu::faceshape('a.jpg', 1); +//var_dump($uploadRet); + +//黄图识别 +//$uploadRet = YouTu::imageporn('test.jpg', 1); +//var_dump($uploadRet); +//$uploadRet = YouTu::imagepornurl('http://open.youtu.qq.com/content/img/product/face/face_05.jpg', 1); +//var_dump($uploadRet); + +//身份证ocr + +//$uploadRet = YouTu::idcardocr('test.jpg', 1); +//var_dump($uploadRet); +//$uploadRet = YouTu::idcardocrurl('http://open.youtu.qq.com/content/img/product/face/face_05.jpg', 1); +//var_dump($uploadRet); + +//名片 +// $uploadRet = YouTu::namecardocr('test.jpg', 1); +// var_dump($uploadRet); +$uploadRet = YouTu::namecardocrurl('http://open.youtu.qq.com/content/img/product/face/face_05.jpg', 1); +var_dump($uploadRet); + +// $uploadRet = YouTu::plateocr('plate.jpg'); +// var_dump($uploadRet); +$uploadRet = YouTu::plateocrurl('http://open.youtu.qq.com/app/img/experience/char_general/ocr_license_1.jpg'); +var_dump($uploadRet); + +// $uploadRet = YouTu::bizlicenseocr('biz.jpg'); +// var_dump($uploadRet); +$uploadRet = YouTu::bizlicenseocrurl('http://open.youtu.qq.com/app/img/experience/char_general/ocr_yyzz_01.jpg'); +var_dump($uploadRet); + +// $uploadRet = YouTu::creditcardocr('credit.jpg'); +// var_dump($uploadRet); + +$uploadRet = YouTu::creditcardocrurl('http://open.youtu.qq.com/app/img/experience/char_general/ocr_card_1.jpg'); +var_dump($uploadRet); + +// $uploadRet = YouTu::carclassify('car.jpg'); +// var_dump($uploadRet); + +$uploadRet = YouTu::carclassifyurl('http://open.youtu.qq.com/app/img/experience/car/car_01.jpg'); var_dump($uploadRet); -?> \ No newline at end of file + +// $uploadRet = YouTu::imageterrorism('terror.jpg'); +// var_dump($uploadRet); + +$uploadRet = YouTu::imageterrorismurl('http://open.youtu.qq.com/app/img/experience/terror/img_terror01.jpg'); +var_dump($uploadRet); + +$group_ids = array(); +// $uploadRet = YouTu::multifaceidentify('terror.jpg', "test", $group_ids, 5, 40); +// var_dump($uploadRet); + +$uploadRet = YouTu::multifaceidentifyurl('http://open.youtu.qq.com/app/img/experience/face_img/face_13.jpg', "test", $group_ids, 5, 40); +var_dump($uploadRet); + +?> diff --git a/test.jpg b/test.jpg new file mode 100644 index 0000000..d74bd18 Binary files /dev/null and b/test.jpg differ