├── LICENSE ├── README.md ├── TencentYoutuyun ├── Auth.php ├── Conf.php ├── Http.php └── Youtu.php ├── composer.json ├── include.php ├── sample.php └── test.jpg /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2015 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # TencentYoutuyun-person-face-service 2 | 3 | php sdk for [腾讯优图开放平台](http://open.youtu.qq.com) 4 | 5 | ## 安装(直接下载源码集成) 6 | 7 | 8 | 从github下载源码装入到您的程序中,并加载include.php 9 | 10 | ## 名词 11 | 12 | - `AppId` 平台添加应用后分配的AppId 13 | - `SecretId` 平台添加应用后分配的SecretId 14 | - `SecretKey` 平台添加应用后分配的SecretKey 15 | - `签名` 接口鉴权凭证,由`AppId`、`SecretId`、`SecretKey`等生成,详见 16 | 17 | 18 | 19 | ## 使用示例 20 | 21 | ##### 引入SDK 22 | ``` 23 | require('./include.php'); 24 | use TencentYoutuyun\Youtu; 25 | use TencentYoutuyun\Conf; 26 | use TencentYoutuyun\Auth; 27 | ``` 28 | ##### 设置APP 鉴权信息 29 | ``` 30 | $appid='your appid'; 31 | $secretId='your secretId '; 32 | $secretKey='your secretKey'; 33 | $userid='your qq'; 34 | ``` 35 | 36 | ##### 根据你使用的平台选择一种初始化方式 37 | 38 | 39 | * 优图开放平台初始化 40 | ``` 41 | Conf::setAppInfo($appid, $secretId, $secretKey, $userid,conf::API_YOUTU_END_POINT); 42 | ``` 43 | * 优图开放平台核身服务初始化(**核身服务目前仅支持核身专有接口,需要联系商务开通**) 44 | ``` 45 | Conf::setAppInfo($appid, $secretId, $secretKey, $userid,conf::API_YOUTU_CHARGE_END_POINT); 46 | ``` 47 | * 腾讯云初始化 48 | ``` 49 | Conf::setAppInfo($appid, $secretId, $secretKey, $userid,conf::API_TENCENTYUN_END_POINT); 50 | ``` 51 | * 人脸检测接口调用示例 52 | ``` 53 | $uploadRet = YouTu::detectface('test.jpg', 1); 54 | var_dump($uploadRet); 55 | ``` 56 | 57 | 58 | 59 | ### `鉴权` 60 | 61 | 接口调用时 计算签名鉴权相关逻辑。 62 | 63 | * `Auth::appSign($expired, $userid)` 64 | 65 | 获取签名,依赖`conf`中的配置项。 66 | 67 | - 参数 68 | - `expired` 过期时间,UNIX时间戳, 计算的签名在过期时间之前有效. 69 | - `userid` 业务中的用户标识,填写用户QQ号即可 70 | - 返回值: 签名 71 | 72 | - 其它 73 | 74 | - `auth.AUTH_PARAMS_ERROR` 参数错误常量(-1) 75 | - `auth.AUTH_SECRET_ID_KEY_ERROR` 密钥ID或者密钥KEY错误常量(-2) 76 | 77 | 78 | *** 79 | ##### Api分为开放平台API和核身API,**核身API访问权限需要联系商务开通**;开放平台API访问域名为https://api.youtu.qq.com/, 核身API访问域名为https://vip-api.youtu.qq.com/ 80 | *** 81 | 82 | ### `核身API介绍` 83 | 优图开放平台相关核身API封装,均为同步函数,**需要联系商务开通** 84 | *** 85 | * `YouTu::livegetfour() ` 86 | 87 | 获取四字唇语 88 | 89 | - 参数 90 | - `$image_path` 无 91 | 92 | 93 | * `YouTu::livedetectfour($validate_data,$video_path,$card_path,$compare_card=false,$seq = '') ` 94 | 95 | 带数据源四字人脸核身 96 | 97 | - 参数 98 | - `$validate_data` livegetfour获取的四字唇语 99 | - `$video_path` 视频的路径 100 | - `$card_path` 对比照片的路径 101 | - `$compare_card` 视频与照片是否进行对比,true 对比 false不对比 102 | 103 | 104 | * `YouTu::idcardlivedetectfour($idcard_number,$idcard_name,$validate_data,$video_path,$seq = '') ` 105 | 106 | 不带数据源四字人脸核身 107 | 108 | - 参数 109 | - `$idcard_number` 身份证号码 110 | - `$idcard_name` 身份证姓名 111 | - `$validate_data` livegetfour获取的四字唇语 112 | - `$video_path` 视频的路径 113 | 114 | 115 | 116 | * `YouTu::idcardfacecompare($idcard_number,$idcard_name,$image_path,$seq = '') ` 117 | 118 | 不带数据源人脸对比 119 | 120 | - 参数 121 | - `$idcard_number` 身份证号码 122 | - `$idcard_name` 身份证姓名 123 | - `$image_path` 照片的路径 124 | 125 | 126 | * `YouTu::validateidcard($idcard_number,$idcard_name,$seq = '') ` 127 | 128 | 验证身份证信息的有效性 129 | 130 | - 参数 131 | - `$idcard_number` 身份证号码 132 | - `$idcard_name` 身份证姓名 133 | 134 | 135 | * `YouTu::idcardocr($image_path, $card_type, $seq = '') ` 136 | * `YouTu::idcardocrurl($url, $card_type, $seq = '') ` 137 | 138 | 身份证OCR识别 139 | 140 | - 参数 141 | - `$image_path` 待检测图片路径 142 | - `$url`待检测图片的url 143 | - `$card_type` 0 代表输入图像是身份证正面, 1代表输入是身份证反面 144 | 145 | 146 | * `YouTu::facecompare($image_path_a, $image_path_b)` 147 | * `YouTu::facecompareurl($urlA, $urlB)` 148 | 149 | 人脸对比,计算两个Face的相似性以及五官相似度。 150 | 151 | - 参数 152 | - `$image_path_a` 第一张待检测图片路径 153 | - `$image_path_b` 第二张待检测图片路径 154 | - `$urlA` 第一张图片url 155 | - `$urlB` 第二张图片url 156 | 157 | 158 | *** 159 | ### `开放平台API介绍` 160 | 161 | 优图开放平台相关API封装,均为同步函数 162 | 163 | **** 164 | 165 | * `YouTu::detectface($image_path, $isbigface)` 166 | * `YouTu::detectfaceurl($url, $isbigface)` 167 | 168 | 人脸检测,检测给定图片(Image)中的所有人脸(Face)的位置和相应的面部属性。位置包括(x, y, w, h),面部属性包括性别(gender)、年龄(age) 169 | 表情(expression)、眼镜(glass)和姿态(pitch,roll,yaw)。 170 | 171 | - 参数 172 | - `$image_path` 待检测图片路径 173 | - `$url` 待检测图片的url 174 | - `$isbigface` 是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式 175 | 176 | 177 | 178 | * `YouTu::faceshape($image_path, $isbigface)` 179 | * `YouTu::faceshapeurl($url, $isbigface)` 180 | 181 | 人脸定位,检测给定图片中人脸的五官。对请求图片进行人脸配准,计算构成人脸轮廓的88个点, 182 | 包括眉毛(左右各8点)、眼睛(左右各8点)、鼻子(13点)、嘴巴(22点)、脸型轮廓(21点) 183 | 184 | - 参数 185 | - `$image_path` 待检测图片路径 186 | - `$url` 待检测图片的url 187 | - `$isbigface` 是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式 188 | 189 | 190 | * `YouTu::facecompare($image_path_a, $image_path_b)` 191 | * `YouTu::facecompareurl($urlA, $urlB)` 192 | 193 | 人脸对比,计算两个Face的相似性以及五官相似度。 194 | 195 | - 参数 196 | - `$image_path_a` 第一张待检测图片路径 197 | - `$image_path_b` 第二张待检测图片路径 198 | - `$urlA` 第一张图片url 199 | - `$urlB` 第二张图片url 200 | 201 | 202 | * `YouTu::faceverify($image_path, $person_id)` 203 | * `YouTu::faceverifyurl($url,$person_id)` 204 | 205 | 人脸验证,给定一个Face和一个Person,返回是否是同一个人的判断以及置信度。 206 | 207 | - 参数 208 | - `$image_path` 待检测图片路径 209 | - `$url` 待检测图片的url 210 | - `$person_id` 待验证的Person 211 | 212 | 213 | * `YouTu::faceidentify($image_path, $group_id)` 214 | * `YouTu::faceidentifyurl($url,$group_id)` 215 | 人脸识别,对于一个待识别的人脸图片,在一个Group中识别出最相似的Top5 Person作为其身份返回,返回的Top5中按照相似度从大到小排列。 216 | 217 | - 参数 218 | - `$image_path` 待检测图片路径 219 | - `$url` 待检测图片的url 220 | - `$group_id` 需要识别的人 所在的组 221 | 222 | * `YouTu::multifaceidentify($image_path,$group_id, array $group_ids, $topn=5, $min_size=40)` 223 | * `YouTu::multifaceidentifyurl($url, $group_id, array $group_ids, $topn=5, $min_size=40)` 224 | 上传人脸图片,进行多人脸检索。 225 | - 参数 226 | - `$image_path` 待检测图片路径 227 | - `$url` 待检测图片的url 228 | - `$group_id` 需要识别的人 所在的组 229 | - `$group_ids` 需要识别的人 所在的组的列表(数组) 230 | - `$topn` 候选人脸数量,一般使用默认值5 231 | - `$min_size` 人脸检测最小尺寸,一般使用默认值40 232 | 233 | 234 | * `YouTu::newperson($image_path, $person_id, array $group_ids, $person_name="", $person_tag="")` 235 | * `YouTu::newpersonurl($url, $person_id, array $group_ids, $person_name="", $person_tag="")` 236 | 237 | 个体创建,创建一个Person,并将Person放置到$group_ids指定的组当中。 238 | 239 | - 参数 240 | - `$image_path` 待检测图片路径 241 | - `$url` 待检测图片的url 242 | - `$person_id` 个体id 243 | - `$person_name` 个体的名字 244 | - `$group_ids` 要加入的组的列表(数组) 245 | - `$person_name` 个体名称 246 | - `$person_tag` 备注信息,用户自解释字段 247 | 248 | * `YouTu::delperson($person_id)` 249 | 250 | 删除一个Person 251 | 252 | - 参数 253 | - `$person_id` 个体Person 254 | 255 | 256 | * `YouTu::addface($person_id, $images, $facetag)` 257 | * `YouTu::addfaceurl($person_id, $url_arr, $facetag="")` 258 | 259 | 添加人脸,在创建一个Person后, 增加person下面的人脸, 可以用于后面的比对。 260 | 261 | - 参数 262 | - `$person_id` 个体Person 263 | - `$images` 待检测图片路径(数组) 264 | - `$url_arr` 图片url(数组) 265 | - `$facetag` 人脸自定义标签 266 | 267 | 268 | * `YouTu::delface($person_id, $face_ids)` 269 | 270 | 删除人脸,删除一个person下的face,包括特征,属性和face_id。 271 | 272 | - 参数 273 | - `$person_id` 个体Person 274 | - `$face_ids` 要删除的faceId列表(数组) 275 | 276 | * `YouTu::setinfo($person_name, $person_id, $tag)` 277 | 278 | 设置Person的信息 279 | 280 | - 参数 281 | - `$person_name` 个体Person的name 282 | - `$person_id` 个体Person 283 | - `$tag` 个体Person的tag, 用户自解释字段 284 | 285 | * `YouTu::getinfo($person_id)` 286 | 287 | 获取一个Person的信息,包括name、id、$tag、相关的face以及groups等信息。 288 | 289 | - 参数 290 | - `$person_id` 个体Person 291 | 292 | * `YouTu::getgroupids()` 293 | 294 | 获取一个AppId下所有group列表 295 | 296 | - 返回值 297 | - 返回的结果,JSON字符串,字段参见API文档 298 | 299 | * `YouTu::getpersonIds($group_id)` 300 | 301 | 获取一个组Group中所有person列表 302 | 303 | - 参数 304 | - `$group_id` 组 305 | 306 | * `YouTu::getfaceIds($person_id)` 307 | 308 | 获取一个组person中所有face列表 309 | 310 | - 参数 311 | - `$person_id` 个体Person 312 | 313 | * `YouTu::getfaceinfo($face_id)` 314 | 315 | 获取一个face的相关特征信息 316 | 317 | - 参数 318 | - `$face_id` 需要获取的faceid 319 | 320 | 321 | * `YouTu::fuzzydetect($image_path)` 322 | * `YouTu::fuzzydetecturl($url)` 323 | 324 | 判断一个图像的模糊程度 325 | 326 | - 参数 327 | - `$image_path` 待检测图片路径 328 | - `$url` 待检测图片的url 329 | 330 | 331 | * `YouTu::fooddetect($image_path)` 332 | * `YouTu::fooddetecturl($url)` 333 | 334 | 识别一个图像是否为美食图像 335 | 336 | - 参数 337 | - `$image_path` 待检测图片路径 338 | - `$url` 待检测图片的url 339 | 340 | 341 | * `YouTu::imagetag($image_path)` 342 | * `YouTu::imagetagurl($url)` 343 | 344 | 识别一个图像的标签信息,对图像分类 345 | 346 | - 参数 347 | - `$image_path` 待检测图片路径 348 | - `$url` 待检测图片的url 349 | 350 | * `YouTu::imageporn($image_path)` 351 | * `YouTu::imagepornurl($url)` 352 | 353 | 色情图像检测 354 | - 参数 355 | - `$image_path` 待检测图片路径 356 | - `$url`待检测图片的url 357 | 358 | * `YouTu::imageterrorism($image_path)` 359 | * `YouTu::imageterrorismurl($url)` 360 | 361 | 暴恐图片识别 362 | - 参数 363 | - `$image_path` 待检测图片路径 364 | - `$url`待检测图片的url 365 | 366 | * `YouTu::carclassify($image_path)` 367 | * `YouTu::carclassifyurl($url)` 368 | 369 | 车辆属性识别 370 | - 参数 371 | - `$image_path` 待检测图片路径 372 | - `$url`待检测图片的url 373 | 374 | * `YouTu::idcardocr($image_path, $card_type, $seq = '') ` 375 | * `YouTu::idcardocrurl($url, $card_type, $seq = '') ` 376 | 377 | 身份证ocr识别 378 | 379 | - 参数 380 | - `$image_path` 待检测图片路径 381 | - `$url`待检测图片的url 382 | - `$retimage` 0代表不需要返回识别后图像, 1代表需要返回识别后图像 383 | 384 | 385 | * `YouTu::generalocr($image_path, $seq = '') ` 386 | * `YouTu::generalocrurl($url, $seq = '') ` 387 | 388 | 通用OCR识别 389 | 390 | - 参数 391 | - `$image_path` 待检测图片路径 392 | - `$url`待检测图片的url 393 | 394 | 395 | * `YouTu::bcocr($image_path, $seq = '') ` 396 | * `YouTu::bcocrurl($url, $seq = '') ` 397 | 398 | 名片OCR识别 399 | 400 | - 参数 401 | - `$image_path` 待检测图片路径 402 | - `$url`待检测图片的url 403 | 404 | 405 | * `YouTu::driverlicenseocr($image_path, $card_type, $seq = '') ` 406 | * `YouTu::driverlicenseocrurl($url, $card_type, $seq = '') ` 407 | 408 | 行驶证&驾驶证OCR识别 409 | 410 | - 参数 411 | - `$image_path` 待检测图片路径 412 | - `$url`待检测图片的url 413 | - `$card_type` 0 代表输入图像是行驶证, 1代表输入图像是驾驶证 414 | 415 | * `YouTu::plateocr($image_path, $seq = '') ` 416 | * `YouTu::plateocrurl($url, $seq = '') ` 417 | 418 | 车牌OCR识别 419 | 420 | - 参数 421 | - `$image_path` 待检测图片路径 422 | - `$url`待检测图片的url 423 | 424 | * `YouTu::creditcardocr($image_path, $seq = '') ` 425 | * `YouTu::creditcardocrurl($url, $seq = '') ` 426 | 427 | 银行卡OCR识别 428 | 429 | - 参数 430 | - `$image_path` 待检测图片路径 431 | - `$url`待检测图片的url 432 | 433 | * `YouTu::bizlicenseocr($image_path, $seq = '') ` 434 | * `YouTu::bizlicenseocrurl($url, $seq = '') ` 435 | 436 | 营业执照OCR识别 437 | 438 | - 参数 439 | - `$image_path` 待检测图片路径 440 | - `$url`待检测图片的url 441 | 442 | ####更多详情和文档说明参见 443 | * [腾讯优图开放平台](http://open.youtu.qq.com) 444 | 445 | -------------------------------------------------------------------------------- /TencentYoutuyun/Auth.php: -------------------------------------------------------------------------------- 1 | 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 87 | } 88 | 89 | $expired = time() + self::EXPIRED_SECONDS; 90 | $postUrl = Conf::$END_POINT . 'youtu/api/detectface'; 91 | $sign = Auth::appSign($expired, Conf::$USER_ID); 92 | 93 | $image_data = file_get_contents($real_image_path); 94 | $post_data = array( 95 | 'app_id' => Conf::$APPID, 96 | 'image' => base64_encode($image_data), 97 | 'mode' => $isbigface 98 | ); 99 | 100 | $req = array( 101 | 'url' => $postUrl, 102 | 'method' => 'post', 103 | 'timeout' => 10, 104 | 'data' => json_encode($post_data), 105 | 'header' => array( 106 | 'Authorization:'.$sign, 107 | 'Content-Type:text/json', 108 | 'Expect: ', 109 | ), 110 | ); 111 | $rsp = Http::send($req); 112 | 113 | $ret = json_decode($rsp, true); 114 | 115 | if(!$ret){ 116 | return self::getStatusText(); 117 | } 118 | 119 | return $ret; 120 | } 121 | 122 | /** 123 | * @brief detectfaceurl 124 | * @param url 图片url 125 | * @param isbigface 是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式 126 | * @return 返回的结果,JSON字符串,字段参见API文档 127 | */ 128 | public static function detectfaceurl($url, $isbigface) { 129 | 130 | $expired = time() + self::EXPIRED_SECONDS; 131 | $postUrl = Conf::$END_POINT . 'youtu/api/detectface'; 132 | $sign = Auth::appSign($expired, Conf::$USER_ID); 133 | 134 | $post_data = array( 135 | 'app_id' => Conf::$APPID, 136 | 'url' => $url, 137 | 'mode' => $isbigface 138 | ); 139 | 140 | $req = array( 141 | 'url' => $postUrl, 142 | 'method' => 'post', 143 | 'timeout' => 10, 144 | 'data' => json_encode($post_data), 145 | 'header' => array( 146 | 'Authorization:'.$sign, 147 | 'Content-Type:text/json', 148 | 'Expect: ', 149 | ), 150 | ); 151 | $rsp = Http::send($req); 152 | 153 | $ret = json_decode($rsp, true); 154 | 155 | if(!$ret){ 156 | return self::getStatusText(); 157 | } 158 | 159 | return $ret; 160 | } 161 | 162 | /** 163 | * @brief faceshape 164 | * @param image_path 待检测的路径 165 | * @param isbigface 是否大脸模式 166 | * @return 返回的结果,JSON字符串,字段参见API文档 167 | */ 168 | public static function faceshape($image_path, $isbigface) { 169 | 170 | $real_image_path = realpath($image_path); 171 | 172 | if (!file_exists($real_image_path)) 173 | { 174 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 175 | } 176 | 177 | $expired = time() + self::EXPIRED_SECONDS; 178 | $postUrl = Conf::$END_POINT . 'youtu/api/faceshape'; 179 | $sign = Auth::appSign($expired, Conf::$USER_ID); 180 | 181 | $image_data = file_get_contents($real_image_path); 182 | $post_data = array( 183 | 'app_id' => Conf::$APPID, 184 | 'image' => base64_encode($image_data), 185 | 'mode' => $isbigface 186 | ); 187 | 188 | $req = array( 189 | 'url' => $postUrl, 190 | 'method' => 'post', 191 | 'timeout' => 10, 192 | 'data' => json_encode($post_data), 193 | 'header' => array( 194 | 'Authorization:'.$sign, 195 | 'Content-Type:text/json', 196 | 'Expect: ', 197 | ), 198 | ); 199 | $rsp = Http::send($req); 200 | 201 | $ret = json_decode($rsp, true); 202 | 203 | if(!$ret){ 204 | return self::getStatusText(); 205 | } 206 | return $ret; 207 | } 208 | 209 | /** 210 | * @brief faceshapeurl 211 | * @param url 图片url 212 | * @param isbigface 是否大脸模式 0表示检测所有人脸, 1表示只检测照片最大人脸 适合单人照模式 213 | * @return 返回的结果,JSON字符串,字段参见API文档 214 | */ 215 | public static function faceshapeurl($url, $isbigface) { 216 | 217 | $expired = time() + self::EXPIRED_SECONDS; 218 | $postUrl = Conf::$END_POINT . 'youtu/api/faceshape'; 219 | $sign = Auth::appSign($expired, Conf::$USER_ID); 220 | 221 | $post_data = array( 222 | 'app_id' => Conf::$APPID, 223 | 'url' => $url, 224 | 'mode' => $isbigface 225 | ); 226 | 227 | $req = array( 228 | 'url' => $postUrl, 229 | 'method' => 'post', 230 | 'timeout' => 10, 231 | 'data' => json_encode($post_data), 232 | 'header' => array( 233 | 'Authorization:'.$sign, 234 | 'Content-Type:text/json', 235 | 'Expect: ', 236 | ), 237 | ); 238 | $rsp = Http::send($req); 239 | 240 | $ret = json_decode($rsp, true); 241 | 242 | if(!$ret){ 243 | return self::getStatusText(); 244 | } 245 | 246 | return $ret; 247 | } 248 | 249 | /** 250 | * @brief facecompare 251 | * @param image_path_a 待比对的A图片数据 252 | * @param image_path_b 待比对的B图片数据 253 | * @return 返回的结果,JSON字符串,字段参见API文档 254 | */ 255 | public static function facecompare($image_path_a, $image_path_b) { 256 | 257 | $real_image_path_a = realpath($image_path_a); 258 | $real_image_path_b = realpath($image_path_b); 259 | if (!file_exists($real_image_path_a)) 260 | { 261 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path_a.' not exists', 'data' => array()); 262 | } 263 | 264 | if (!file_exists($real_image_path_b)) 265 | { 266 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path_b.' not exists', 'data' => array()); 267 | } 268 | 269 | $expired = time() + self::EXPIRED_SECONDS; 270 | $postUrl = Conf::$END_POINT . 'youtu/api/facecompare'; 271 | $sign = Auth::appSign($expired, Conf::$USER_ID); 272 | 273 | $image_data_a = file_get_contents($real_image_path_a); 274 | $image_data_b = file_get_contents($real_image_path_b); 275 | 276 | $post_data = array( 277 | 'app_id' => Conf::$APPID, 278 | 'imageA' => base64_encode($image_data_a), 279 | 'imageB' => base64_encode($image_data_b) 280 | ); 281 | 282 | $req = array( 283 | 'url' => $postUrl, 284 | 'method' => 'post', 285 | 'timeout' => 10, 286 | 'data' => json_encode($post_data), 287 | 'header' => array( 288 | 'Authorization:'.$sign, 289 | 'Content-Type:text/json', 290 | 'Expect: ', 291 | ), 292 | ); 293 | $rsp = Http::send($req); 294 | $ret = json_decode($rsp, true); 295 | 296 | if(!$ret){ 297 | return self::getStatusText(); 298 | } 299 | return $ret; 300 | } 301 | 302 | /** 303 | * @brief facecompareurl 304 | * @param urlA 待比对的A图片url 305 | * @param urlB 待比对的B图片url 306 | * @return 返回的结果,JSON字符串,字段参见API文档 307 | */ 308 | public static function facecompareurl($urlA, $urlB) { 309 | 310 | $expired = time() + self::EXPIRED_SECONDS; 311 | $postUrl = Conf::$END_POINT . 'youtu/api/facecompare'; 312 | $sign = Auth::appSign($expired, Conf::$USER_ID); 313 | 314 | $post_data = array( 315 | 'app_id' => Conf::$APPID, 316 | 'urlA' => $urlA, 317 | 'urlB' => $urlB 318 | ); 319 | 320 | $req = array( 321 | 'url' => $postUrl, 322 | 'method' => 'post', 323 | 'timeout' => 10, 324 | 'data' => json_encode($post_data), 325 | 'header' => array( 326 | 'Authorization:'.$sign, 327 | 'Content-Type:text/json', 328 | 'Expect: ', 329 | ), 330 | ); 331 | $rsp = Http::send($req); 332 | $ret = json_decode($rsp, true); 333 | 334 | if(!$ret){ 335 | return self::getStatusText(); 336 | } 337 | return $ret; 338 | } 339 | 340 | 341 | 342 | /** 343 | * @brief faceverify 344 | * @param person_id 待验证的人脸id 345 | * @param image_path 待验证的图片路径 346 | * @return 返回的结果,JSON字符串,字段参见API文档 347 | */ 348 | public static function faceverify($image_path,$person_id) { 349 | 350 | $real_image_path = realpath($image_path); 351 | 352 | if (!file_exists($real_image_path)) 353 | { 354 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 355 | } 356 | 357 | $expired = time() + self::EXPIRED_SECONDS; 358 | $postUrl = Conf::$END_POINT . 'youtu/api/faceverify'; 359 | $sign = Auth::appSign($expired, Conf::$USER_ID); 360 | 361 | $image_data = file_get_contents($real_image_path); 362 | $post_data = array( 363 | 'app_id' => Conf::$APPID, 364 | 'image' => base64_encode($image_data), 365 | 'person_id' =>$person_id, 366 | ); 367 | 368 | $req = array( 369 | 'url' => $postUrl, 370 | 'method' => 'post', 371 | 'timeout' => 10, 372 | 'data' => json_encode($post_data), 373 | 'header' => array( 374 | 'Authorization:'.$sign, 375 | 'Content-Type:text/json', 376 | ), 377 | ); 378 | $rsp = Http::send($req); 379 | $ret = json_decode($rsp, true); 380 | 381 | if(!$ret){ 382 | return self::getStatusText(); 383 | } 384 | return $ret; 385 | } 386 | 387 | /** 388 | * @brief faceverifyurl 389 | * @param person_id 待验证的人脸id 390 | * @param url 待验证的图片url 391 | * @return 返回的结果,JSON字符串,字段参见API文档 392 | */ 393 | public static function faceverifyurl($url,$person_id) { 394 | 395 | $expired = time() + self::EXPIRED_SECONDS; 396 | $postUrl = Conf::$END_POINT . 'youtu/api/faceverify'; 397 | $sign = Auth::appSign($expired, Conf::$USER_ID); 398 | 399 | $post_data = array( 400 | 'app_id' => Conf::$APPID, 401 | 'url' => $url, 402 | 'person_id' =>$person_id, 403 | ); 404 | 405 | $req = array( 406 | 'url' => $postUrl, 407 | 'method' => 'post', 408 | 'timeout' => 10, 409 | 'data' => json_encode($post_data), 410 | 'header' => array( 411 | 'Authorization:'.$sign, 412 | 'Content-Type:text/json', 413 | ), 414 | ); 415 | $rsp = Http::send($req); 416 | $ret = json_decode($rsp, true); 417 | 418 | if(!$ret){ 419 | return self::getStatusText(); 420 | } 421 | return $ret; 422 | } 423 | 424 | 425 | /** 426 | * @brief faceidentify 427 | * @param group_id 识别的组id 428 | * @param image_path 待识别的图片路径 429 | * @return 返回的结果,JSON字符串,字段参见API文档 430 | */ 431 | 432 | public static function faceidentify($image_path,$group_id) { 433 | 434 | $real_image_path = realpath($image_path); 435 | 436 | if (!file_exists($real_image_path)) 437 | { 438 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 439 | } 440 | 441 | $expired = time() + self::EXPIRED_SECONDS; 442 | $postUrl = Conf::$END_POINT . 'youtu/api/faceidentify'; 443 | $sign = Auth::appSign($expired, Conf::$USER_ID); 444 | 445 | $image_data = file_get_contents($real_image_path); 446 | $post_data = array( 447 | 'app_id' => Conf::$APPID, 448 | 'image' => base64_encode($image_data), 449 | 'group_id' =>$group_id, 450 | ); 451 | 452 | $req = array( 453 | 'url' => $postUrl, 454 | 'method' => 'post', 455 | 'timeout' => 10, 456 | 'data' => json_encode($post_data), 457 | 'header' => array( 458 | 'Authorization:'.$sign, 459 | 'Content-Type:text/json', 460 | ), 461 | ); 462 | $rsp = Http::send($req); 463 | $ret = json_decode($rsp, true); 464 | 465 | if(!$ret){ 466 | return self::getStatusText(); 467 | } 468 | return $ret; 469 | } 470 | 471 | /** 472 | * @brief faceidentifyurl 473 | * @param group_id 识别的组id 474 | * @param group_ids 个体存放的组id,可以指定多个组id,用户指定 475 | * @param url 待识别的图片的url 476 | * @return 返回的结果,JSON字符串,字段参见API文档 477 | */ 478 | 479 | public static function faceidentifyurl($url,$group_id) { 480 | 481 | $expired = time() + self::EXPIRED_SECONDS; 482 | $postUrl = Conf::$END_POINT . 'youtu/api/faceidentify'; 483 | $sign = Auth::appSign($expired, Conf::$USER_ID); 484 | 485 | $post_data = array( 486 | 'app_id' => Conf::$APPID, 487 | 'url' => $url, 488 | 'group_id' =>$group_id, 489 | ); 490 | 491 | $req = array( 492 | 'url' => $postUrl, 493 | 'method' => 'post', 494 | 'timeout' => 10, 495 | 'data' => json_encode($post_data), 496 | 'header' => array( 497 | 'Authorization:'.$sign, 498 | 'Content-Type:text/json', 499 | ), 500 | ); 501 | $rsp = Http::send($req); 502 | $ret = json_decode($rsp, true); 503 | 504 | if(!$ret){ 505 | return self::getStatusText(); 506 | } 507 | return $ret; 508 | } 509 | 510 | /** 511 | * @brief multifaceidentify 512 | * @param group_id 识别的组id 513 | * @param group_ids 个体存放的组id,可以指定多个组id,用户指定 514 | * @param image_path 待识别的图片路径 515 | * @param topn 候选人脸数量,一般使用默认值5 516 | * @param min_size 人脸检测最小尺寸,一般使用默认值40 517 | * @return 返回的结果,JSON字符串,字段参见API文档 518 | */ 519 | 520 | public static function multifaceidentify($image_path,$group_id, array $group_ids, $topn=5, $min_size=40) { 521 | 522 | $real_image_path = realpath($image_path); 523 | 524 | if (!file_exists($real_image_path)) 525 | { 526 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 527 | } 528 | 529 | $expired = time() + self::EXPIRED_SECONDS; 530 | $postUrl = Conf::$END_POINT . 'youtu/api/multifaceidentify'; 531 | $sign = Auth::appSign($expired, Conf::$USER_ID); 532 | 533 | $image_data = file_get_contents($real_image_path); 534 | $post_data = array( 535 | 'app_id' => Conf::$APPID, 536 | 'image' => base64_encode($image_data), 537 | 'group_id' =>$group_id, 538 | 'group_ids' =>$group_ids, 539 | 'topn' =>$topn, 540 | 'min_size' =>$min_size 541 | ); 542 | 543 | $req = array( 544 | 'url' => $postUrl, 545 | 'method' => 'post', 546 | 'timeout' => 10, 547 | 'data' => json_encode($post_data), 548 | 'header' => array( 549 | 'Authorization:'.$sign, 550 | 'Content-Type:text/json', 551 | ), 552 | ); 553 | $rsp = Http::send($req); 554 | $ret = json_decode($rsp, true); 555 | 556 | if(!$ret){ 557 | return self::getStatusText(); 558 | } 559 | return $ret; 560 | } 561 | 562 | /** 563 | * @brief multifaceidentifyurl 564 | * @param group_id 识别的组id 565 | * @param group_ids 个体存放的组id,可以指定多个组id,用户指定 566 | * @param url 待识别的图片的url 567 | * @param topn 候选人脸数量,一般使用默认值5 568 | * @param min_size 人脸检测最小尺寸,一般使用默认值40 569 | * @return 返回的结果,JSON字符串,字段参见API文档 570 | */ 571 | 572 | public static function multifaceidentifyurl($url,$group_id, array $group_ids, $topn=5, $min_size=40) { 573 | 574 | $expired = time() + self::EXPIRED_SECONDS; 575 | $postUrl = Conf::$END_POINT . 'youtu/api/multifaceidentify'; 576 | $sign = Auth::appSign($expired, Conf::$USER_ID); 577 | 578 | $post_data = array( 579 | 'app_id' => Conf::$APPID, 580 | 'url' => $url, 581 | 'group_id' =>$group_id, 582 | 'group_ids' =>$group_ids, 583 | 'topn' =>$topn, 584 | 'min_size' =>$min_size 585 | ); 586 | 587 | $req = array( 588 | 'url' => $postUrl, 589 | 'method' => 'post', 590 | 'timeout' => 10, 591 | 'data' => json_encode($post_data), 592 | 'header' => array( 593 | 'Authorization:'.$sign, 594 | 'Content-Type:text/json', 595 | ), 596 | ); 597 | $rsp = Http::send($req); 598 | $ret = json_decode($rsp, true); 599 | 600 | if(!$ret){ 601 | return self::getStatusText(); 602 | } 603 | return $ret; 604 | } 605 | 606 | /** 607 | * @brief newperson 608 | * @param person_id 新建的个体id,用户指定,需要保证app_id下的唯一性 609 | * @param person_name 个体名字 610 | * @param group_ids 新建的个体存放的组id,可以指定多个组id,用户指定(组默认创建) 611 | * @param image_path 包含个体人脸的图片数据 612 | * @param person_tag 备注信息,用户自解释字段 613 | * @return 返回的结果,JSON字符串,字段参见API文档 614 | */ 615 | 616 | public static function newperson($image_path, $person_id, array $group_ids, $person_name='', $person_tag='') { 617 | $real_image_path = realpath($image_path); 618 | if (!file_exists($real_image_path)) 619 | { 620 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 621 | } 622 | 623 | $expired = time() + self::EXPIRED_SECONDS; 624 | $postUrl = Conf::$END_POINT . 'youtu/api/newperson'; 625 | $sign = Auth::appSign($expired, Conf::$USER_ID); 626 | 627 | $image_data = file_get_contents($real_image_path); 628 | 629 | $post_data = array( 630 | 'app_id' => Conf::$APPID, 631 | 'image' => base64_encode($image_data), 632 | 'person_id' =>$person_id, 633 | 'group_ids' =>$group_ids, 634 | 'person_name' =>$person_name, 635 | 'tag' => $person_tag 636 | ); 637 | 638 | $req = array( 639 | 'url' => $postUrl, 640 | 'method' => 'post', 641 | 'timeout' => 10, 642 | 'data' => json_encode($post_data), 643 | 'header' => array( 644 | 'Authorization:'.$sign, 645 | 'Content-Type:text/json', 646 | ), 647 | ); 648 | $rsp = Http::send($req); 649 | $ret = json_decode($rsp, true); 650 | 651 | if(!$ret){ 652 | return self::getStatusText(); 653 | } 654 | return $ret; 655 | } 656 | 657 | /** 658 | * @brief newpersonurl 659 | * @param person_id 新建的个体id,用户指定,需要保证app_id下的唯一性 660 | * @param person_name 个体名字 661 | * @param group_ids 新建的个体存放的组id,可以指定多个组id,用户指定(组默认创建) 662 | * @param url 包含个体人脸的图片url 663 | * @param person_tag 备注信息,用户自解释字段 664 | * @return 返回的结果,JSON字符串,字段参见API文档 665 | */ 666 | 667 | public static function newpersonurl($url, $person_id, array $group_ids, $person_name='', $person_tag='') { 668 | 669 | $expired = time() + self::EXPIRED_SECONDS; 670 | $postUrl = Conf::$END_POINT . 'youtu/api/newperson'; 671 | $sign = Auth::appSign($expired, Conf::$USER_ID); 672 | 673 | $post_data = array( 674 | 'app_id' => Conf::$APPID, 675 | 'url' => $url, 676 | 'person_id' =>$person_id, 677 | 'group_ids' =>$group_ids, 678 | 'person_name' =>$person_name, 679 | 'tag' => $person_tag 680 | ); 681 | 682 | $req = array( 683 | 'url' => $postUrl, 684 | 'method' => 'post', 685 | 'timeout' => 10, 686 | 'data' => json_encode($post_data), 687 | 'header' => array( 688 | 'Authorization:'.$sign, 689 | 'Content-Type:text/json', 690 | ), 691 | ); 692 | $rsp = Http::send($req); 693 | $ret = json_decode($rsp, true); 694 | 695 | if(!$ret){ 696 | return self::getStatusText(); 697 | } 698 | return $ret; 699 | } 700 | 701 | /** 702 | * @brief delperson 703 | * @param person_id 待删除的个体id 704 | * @return 返回的结果,JSON字符串,字段参见API文档 705 | */ 706 | 707 | public static function delperson($person_id) { 708 | 709 | $expired = time() + self::EXPIRED_SECONDS; 710 | $postUrl = Conf::$END_POINT . 'youtu/api/delperson'; 711 | $sign = Auth::appSign($expired, Conf::$USER_ID); 712 | 713 | $post_data = array( 714 | 'app_id' => Conf::$APPID, 715 | 'person_id' =>$person_id, 716 | ); 717 | 718 | $req = array( 719 | 'url' => $postUrl, 720 | 'method' => 'post', 721 | 'timeout' => 10, 722 | 'data' => json_encode($post_data), 723 | 'header' => array( 724 | 'Authorization:'.$sign, 725 | 'Content-Type:text/json', 726 | ), 727 | ); 728 | $rsp = Http::send($req); 729 | $ret = json_decode($rsp, true); 730 | 731 | if(!$ret){ 732 | return self::getStatusText(); 733 | } 734 | return $ret; 735 | } 736 | 737 | 738 | /** 739 | * @brief addface 740 | * @param person_id 新增人脸的个体身份id 741 | * @param image_path_arr 待增加的包含人脸的图片数据,可加入多张(包体大小<2m) 742 | * @param facetag 人脸备注信息,用户自解释字段 743 | * @return 返回的结果,JSON字符串,字段参见API文档 744 | */ 745 | public static function addface($person_id,array $image_path_arr, $facetag='') { 746 | $image_data_arr=array(); 747 | foreach($image_path_arr as $one_path){ 748 | if (!file_exists($one_path)) 749 | { 750 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$one_path.' not exists', 'data' => array()); 751 | } 752 | $image_data=file_get_contents($one_path); 753 | array_push($image_data_arr,base64_encode($image_data)); 754 | } 755 | $expired = time() + self::EXPIRED_SECONDS; 756 | $postUrl = Conf::$END_POINT . 'youtu/api/addface'; 757 | $sign = Auth::appSign($expired, Conf::$USER_ID); 758 | 759 | $post_data = array( 760 | 'app_id' => Conf::$APPID, 761 | 'images' => $image_data_arr, 762 | 'person_id' =>$person_id, 763 | 'tag' => $facetag 764 | ); 765 | 766 | $req = array( 767 | 'url' => $postUrl, 768 | 'method' => 'post', 769 | 'timeout' => 10, 770 | 'data' => json_encode($post_data), 771 | 'header' => array( 772 | 'Authorization:'.$sign, 773 | 'Content-Type:text/json', 774 | ), 775 | ); 776 | $rsp = Http::send($req); 777 | $ret = json_decode($rsp, true); 778 | 779 | if(!$ret){ 780 | return self::getStatusText(); 781 | } 782 | return $ret; 783 | } 784 | 785 | /** 786 | * @brief addfaceurl 787 | * @param person_id 新增人脸的个体身份id 788 | * @param url_arr 待增加的包含人脸的图片url,可加入多张(包体大小<2m) 789 | * @param facetag 人脸备注信息,用户自解释字段 790 | * @return 返回的结果,JSON字符串,字段参见API文档 791 | */ 792 | public static function addfaceurl($person_id,array $url_arr, $facetag='') { 793 | $expired = time() + self::EXPIRED_SECONDS; 794 | $postUrl = Conf::$END_POINT . 'youtu/api/addface'; 795 | $sign = Auth::appSign($expired, Conf::$USER_ID); 796 | 797 | $post_data = array( 798 | 'app_id' => Conf::$APPID, 799 | 'urls' => $url_arr, 800 | 'person_id' =>$person_id, 801 | 'tag' => $facetag 802 | ); 803 | 804 | $req = array( 805 | 'url' => $postUrl, 806 | 'method' => 'post', 807 | 'timeout' => 10, 808 | 'data' => json_encode($post_data), 809 | 'header' => array( 810 | 'Authorization:'.$sign, 811 | 'Content-Type:text/json', 812 | ), 813 | ); 814 | $rsp = Http::send($req); 815 | $ret = json_decode($rsp, true); 816 | 817 | if(!$ret){ 818 | return self::getStatusText(); 819 | } 820 | return $ret; 821 | } 822 | 823 | 824 | /** 825 | * @brief delface 826 | * @param person_id 待删除人脸的个体身份id 827 | * @param face_id_arr 待删除的人脸id 828 | * @return 返回的结果,JSON字符串,字段参见API文档 829 | */ 830 | public static function delface($person_id,array $face_id_arr) { 831 | 832 | $expired = time() + self::EXPIRED_SECONDS; 833 | $postUrl = Conf::$END_POINT . 'youtu/api/delface'; 834 | $sign = Auth::appSign($expired, Conf::$USER_ID); 835 | 836 | $post_data = array( 837 | 'app_id' => Conf::$APPID, 838 | 'face_ids' => $face_id_arr, 839 | 'person_id' =>$person_id, 840 | ); 841 | 842 | $req = array( 843 | 'url' => $postUrl, 844 | 'method' => 'post', 845 | 'timeout' => 10, 846 | 'data' => json_encode($post_data), 847 | 'header' => array( 848 | 'Authorization:'.$sign, 849 | 'Content-Type:text/json', 850 | ), 851 | ); 852 | $rsp = Http::send($req); 853 | $ret = json_decode($rsp, true); 854 | 855 | if(!$ret){ 856 | return self::getStatusText(); 857 | } 858 | return $ret; 859 | } 860 | 861 | 862 | /** 863 | * @brief setinfo 864 | * @param person_id 待设置的个体身份id 865 | * @param person_name 新设置的个体名字 866 | * @param person_tag 新设置的人备注信息 867 | * @return 返回的结果,JSON字符串,字段参见API文档 868 | */ 869 | public static function setinfo($person_name,$person_id, $person_tag) { 870 | 871 | $expired = time() + self::EXPIRED_SECONDS; 872 | $postUrl = Conf::$END_POINT . 'youtu/api/setinfo'; 873 | $sign = Auth::appSign($expired, Conf::$USER_ID); 874 | 875 | $post_data = array( 876 | 'app_id' => Conf::$APPID, 877 | 'person_name' => $person_name, 878 | 'person_id' =>$person_id, 879 | 'tag' => $person_tag 880 | ); 881 | 882 | $req = array( 883 | 'url' => $postUrl, 884 | 'method' => 'post', 885 | 'timeout' => 10, 886 | 'data' => json_encode($post_data), 887 | 'header' => array( 888 | 'Authorization:'.$sign, 889 | 'Content-Type:text/json', 890 | ), 891 | ); 892 | $rsp = Http::send($req); 893 | $ret = json_decode($rsp, true); 894 | 895 | if(!$ret){ 896 | return self::getStatusText(); 897 | } 898 | return $ret; 899 | } 900 | 901 | 902 | /** 903 | * @brief getinfo 904 | * @param person_id 待查询的个体身份id 905 | * @return 返回的结果,JSON字符串,字段参见API文档 906 | */ 907 | public static function getinfo($person_id) { 908 | 909 | $expired = time() + self::EXPIRED_SECONDS; 910 | $postUrl = Conf::$END_POINT . 'youtu/api/getinfo'; 911 | $sign = Auth::appSign($expired, Conf::$USER_ID); 912 | 913 | $post_data = array( 914 | 'app_id' => Conf::$APPID, 915 | 'person_id' =>$person_id, 916 | ); 917 | 918 | $req = array( 919 | 'url' => $postUrl, 920 | 'method' => 'post', 921 | 'timeout' => 10, 922 | 'data' => json_encode($post_data), 923 | 'header' => array( 924 | 'Authorization:'.$sign, 925 | 'Content-Type:text/json', 926 | ), 927 | ); 928 | $rsp = Http::send($req); 929 | $ret = json_decode($rsp, true); 930 | 931 | if(!$ret){ 932 | return self::getStatusText(); 933 | } 934 | return $ret; 935 | } 936 | 937 | /** 938 | * @brief getgroupids 939 | * @param rsp 返回的组列表查询结果,JSON字符串,字段参见API文档 940 | * @return 返回的结果,JSON字符串,字段参见API文档 941 | */ 942 | public static function getgroupids() { 943 | 944 | $expired = time() + self::EXPIRED_SECONDS; 945 | $postUrl = Conf::$END_POINT . 'youtu/api/getgroupids'; 946 | $sign = Auth::appSign($expired, Conf::$USER_ID); 947 | 948 | $post_data = array( 949 | 'app_id' => Conf::$APPID 950 | ); 951 | 952 | $req = array( 953 | 'url' => $postUrl, 954 | 'method' => 'post', 955 | 'timeout' => 10, 956 | 'data' => json_encode($post_data), 957 | 'header' => array( 958 | 'Authorization:'.$sign, 959 | 'Content-Type:text/json', 960 | ), 961 | ); 962 | $rsp = Http::send($req); 963 | $ret = json_decode($rsp, true); 964 | 965 | if(!$ret){ 966 | return self::getStatusText(); 967 | } 968 | return $ret; 969 | } 970 | 971 | /** 972 | * @brief getpersonids 973 | * @param group_id 待查询的组id 974 | * @param rsp 返回的个体列表查询结果,JSON字符串,字段参见API文档 975 | * @return 返回的结果,JSON字符串,字段参见API文档 976 | */ 977 | public static function getpersonids($group_id) { 978 | 979 | $expired = time() + self::EXPIRED_SECONDS; 980 | $postUrl = Conf::$END_POINT . 'youtu/api/getpersonids'; 981 | $sign = Auth::appSign($expired, Conf::$USER_ID); 982 | 983 | $post_data = array( 984 | 'app_id' => Conf::$APPID, 985 | 'group_id' =>$group_id, 986 | ); 987 | 988 | $req = array( 989 | 'url' => $postUrl, 990 | 'method' => 'post', 991 | 'timeout' => 10, 992 | 'data' => json_encode($post_data), 993 | 'header' => array( 994 | 'Authorization:'.$sign, 995 | 'Content-Type:text/json', 996 | ), 997 | ); 998 | $rsp = Http::send($req); 999 | $ret = json_decode($rsp, true); 1000 | 1001 | if(!$ret){ 1002 | return self::getStatusText(); 1003 | } 1004 | return $ret; 1005 | } 1006 | 1007 | /** 1008 | * @brief getfaceids 1009 | * @param person_id 待查询的个体id 1010 | * @param rsp 返回的人脸列表查询结果,JSON字符串,字段参见API文档 1011 | * @return 返回的结果,JSON字符串,字段参见API文档 1012 | */ 1013 | public static function getfaceids($person_id) { 1014 | 1015 | $expired = time() + self::EXPIRED_SECONDS; 1016 | $postUrl = Conf::$END_POINT . 'youtu/api/getfaceids'; 1017 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1018 | 1019 | $post_data = array( 1020 | 'app_id' => Conf::$APPID, 1021 | 'person_id' =>$person_id, 1022 | ); 1023 | 1024 | $req = array( 1025 | 'url' => $postUrl, 1026 | 'method' => 'post', 1027 | 'timeout' => 10, 1028 | 'data' => json_encode($post_data), 1029 | 'header' => array( 1030 | 'Authorization:'.$sign, 1031 | 'Content-Type:text/json', 1032 | ), 1033 | ); 1034 | $rsp = Http::send($req); 1035 | $ret = json_decode($rsp, true); 1036 | 1037 | if(!$ret){ 1038 | return self::getStatusText(); 1039 | } 1040 | return $ret; 1041 | } 1042 | 1043 | /** 1044 | * @brief getfaceinfo 1045 | * @param face_id 待查询的人脸id 1046 | * @param rsp 返回的人脸信息查询结果,JSON字符串,字段参见API文档 1047 | * @return 返回的结果,JSON字符串,字段参见API文档 1048 | */ 1049 | public static function getfaceinfo($face_id) { 1050 | 1051 | $expired = time() + self::EXPIRED_SECONDS; 1052 | $postUrl = Conf::$END_POINT . 'youtu/api/getfaceinfo'; 1053 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1054 | 1055 | $post_data = array( 1056 | 'app_id' => Conf::$APPID, 1057 | 'face_id' =>$face_id, 1058 | ); 1059 | 1060 | $req = array( 1061 | 'url' => $postUrl, 1062 | 'method' => 'post', 1063 | 'timeout' => 10, 1064 | 'data' => json_encode($post_data), 1065 | 'header' => array( 1066 | 'Authorization:'.$sign, 1067 | 'Content-Type:text/json', 1068 | ), 1069 | ); 1070 | $rsp = Http::send($req); 1071 | $ret = json_decode($rsp, true); 1072 | 1073 | if(!$ret){ 1074 | return self::getStatusText(); 1075 | } 1076 | return $ret; 1077 | } 1078 | 1079 | /** 1080 | * @param $image_path 待检测的路径 1081 | * @return 返回的结果,JSON字符串,字段参见API文档 1082 | */ 1083 | public static function fuzzydetect($image_path) { 1084 | 1085 | $real_image_path = realpath($image_path); 1086 | 1087 | if (!file_exists($real_image_path)) 1088 | { 1089 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1090 | } 1091 | 1092 | $expired = time() + self::EXPIRED_SECONDS; 1093 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/fuzzydetect'; 1094 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1095 | 1096 | $image_data = file_get_contents($real_image_path); 1097 | $post_data = array( 1098 | 'app_id' => Conf::$APPID, 1099 | 'image' => base64_encode($image_data), 1100 | ); 1101 | 1102 | $req = array( 1103 | 'url' => $postUrl, 1104 | 'method' => 'post', 1105 | 'timeout' => 10, 1106 | 'data' => json_encode($post_data), 1107 | 'header' => array( 1108 | 'Authorization:'.$sign, 1109 | 'Content-Type:text/json', 1110 | 'Expect: ', 1111 | ), 1112 | ); 1113 | $rsp = Http::send($req); 1114 | 1115 | $ret = json_decode($rsp, true); 1116 | 1117 | if(!$ret){ 1118 | return self::getStatusText(); 1119 | } 1120 | 1121 | if(!$ret){ 1122 | return self::getStatusText(); 1123 | } 1124 | 1125 | return $ret; 1126 | } 1127 | 1128 | /** 1129 | * @param $url 图片url 1130 | * @return 返回的结果,JSON字符串,字段参见API文档 1131 | */ 1132 | public static function fuzzydetecturl($url) { 1133 | 1134 | $expired = time() + self::EXPIRED_SECONDS; 1135 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/fuzzydetect'; 1136 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1137 | 1138 | $post_data = array( 1139 | 'app_id' => Conf::$APPID, 1140 | 'url' => $url, 1141 | ); 1142 | 1143 | $req = array( 1144 | 'url' => $postUrl, 1145 | 'method' => 'post', 1146 | 'timeout' => 10, 1147 | 'data' => json_encode($post_data), 1148 | 'header' => array( 1149 | 'Authorization:'.$sign, 1150 | 'Content-Type:text/json', 1151 | 'Expect: ', 1152 | ), 1153 | ); 1154 | $rsp = Http::send($req); 1155 | 1156 | $ret = json_decode($rsp, true); 1157 | 1158 | if(!$ret){ 1159 | return self::getStatusText(); 1160 | } 1161 | 1162 | return $ret; 1163 | } 1164 | 1165 | /** 1166 | * @param $image_path 待检测的路径 1167 | * @return 返回的结果,JSON字符串,字段参见API文档 1168 | */ 1169 | public static function fooddetect($image_path) { 1170 | 1171 | $real_image_path = realpath($image_path); 1172 | 1173 | if (!file_exists($real_image_path)) 1174 | { 1175 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1176 | } 1177 | 1178 | $expired = time() + self::EXPIRED_SECONDS; 1179 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/fooddetect'; 1180 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1181 | 1182 | $image_data = file_get_contents($real_image_path); 1183 | $post_data = array( 1184 | 'app_id' => Conf::$APPID, 1185 | 'image' => base64_encode($image_data), 1186 | ); 1187 | 1188 | $req = array( 1189 | 'url' => $postUrl, 1190 | 'method' => 'post', 1191 | 'timeout' => 10, 1192 | 'data' => json_encode($post_data), 1193 | 'header' => array( 1194 | 'Authorization:'.$sign, 1195 | 'Content-Type:text/json', 1196 | 'Expect: ', 1197 | ), 1198 | ); 1199 | $rsp = Http::send($req); 1200 | 1201 | $ret = json_decode($rsp, true); 1202 | 1203 | if(!$ret){ 1204 | return self::getStatusText(); 1205 | } 1206 | 1207 | return $ret; 1208 | } 1209 | 1210 | /** 1211 | * @param $url 图片url 1212 | * @return 返回的结果,JSON字符串,字段参见API文档 1213 | */ 1214 | public static function fooddetecturl($url) { 1215 | 1216 | $expired = time() + self::EXPIRED_SECONDS; 1217 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/fooddetect'; 1218 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1219 | 1220 | $post_data = array( 1221 | 'app_id' => Conf::$APPID, 1222 | 'url' => $url, 1223 | ); 1224 | 1225 | $req = array( 1226 | 'url' => $postUrl, 1227 | 'method' => 'post', 1228 | 'timeout' => 10, 1229 | 'data' => json_encode($post_data), 1230 | 'header' => array( 1231 | 'Authorization:'.$sign, 1232 | 'Content-Type:text/json', 1233 | 'Expect: ', 1234 | ), 1235 | ); 1236 | $rsp = Http::send($req); 1237 | 1238 | $ret = json_decode($rsp, true); 1239 | 1240 | if(!$ret){ 1241 | return self::getStatusText(); 1242 | } 1243 | 1244 | return $ret; 1245 | } 1246 | 1247 | /** 1248 | * @param $image_path 待检测的路径 1249 | * @return 返回的结果,JSON字符串,字段参见API文档 1250 | */ 1251 | public static function imagetag($image_path) { 1252 | 1253 | $real_image_path = realpath($image_path); 1254 | 1255 | if (!file_exists($real_image_path)) 1256 | { 1257 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1258 | } 1259 | 1260 | $expired = time() + self::EXPIRED_SECONDS; 1261 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imagetag'; 1262 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1263 | 1264 | $image_data = file_get_contents($real_image_path); 1265 | $post_data = array( 1266 | 'app_id' => Conf::$APPID, 1267 | 'image' => base64_encode($image_data), 1268 | ); 1269 | 1270 | $req = array( 1271 | 'url' => $postUrl, 1272 | 'method' => 'post', 1273 | 'timeout' => 10, 1274 | 'data' => json_encode($post_data), 1275 | 'header' => array( 1276 | 'Authorization:'.$sign, 1277 | 'Content-Type:text/json', 1278 | 'Expect: ', 1279 | ), 1280 | ); 1281 | $rsp = Http::send($req); 1282 | 1283 | $ret = json_decode($rsp, true); 1284 | 1285 | if(!$ret){ 1286 | return self::getStatusText(); 1287 | } 1288 | 1289 | return $ret; 1290 | } 1291 | 1292 | /** 1293 | * @param $url 图片url 1294 | * @return 返回的结果,JSON字符串,字段参见API文档 1295 | */ 1296 | public static function imagetagurl($url) { 1297 | 1298 | $expired = time() + self::EXPIRED_SECONDS; 1299 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imagetag'; 1300 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1301 | 1302 | $post_data = array( 1303 | 'app_id' => Conf::$APPID, 1304 | 'url' => $url, 1305 | ); 1306 | 1307 | $req = array( 1308 | 'url' => $postUrl, 1309 | 'method' => 'post', 1310 | 'timeout' => 10, 1311 | 'data' => json_encode($post_data), 1312 | 'header' => array( 1313 | 'Authorization:'.$sign, 1314 | 'Content-Type:text/json', 1315 | 'Expect: ', 1316 | ), 1317 | ); 1318 | $rsp = Http::send($req); 1319 | 1320 | $ret = json_decode($rsp, true); 1321 | 1322 | if(!$ret){ 1323 | return self::getStatusText(); 1324 | } 1325 | 1326 | return $ret; 1327 | } 1328 | 1329 | /** 1330 | * @param $image_path 待检测的路径 1331 | * @return 返回的结果,JSON字符串,字段参见API文档 1332 | */ 1333 | public static function imageporn($image_path) { 1334 | 1335 | $real_image_path = realpath($image_path); 1336 | 1337 | if (!file_exists($real_image_path)) 1338 | { 1339 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1340 | } 1341 | 1342 | $expired = time() + self::EXPIRED_SECONDS; 1343 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageporn'; 1344 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1345 | 1346 | $image_data = file_get_contents($real_image_path); 1347 | $post_data = array( 1348 | 'app_id' => Conf::$APPID, 1349 | 'image' => base64_encode($image_data), 1350 | ); 1351 | 1352 | $req = array( 1353 | 'url' => $postUrl, 1354 | 'method' => 'post', 1355 | 'timeout' => 10, 1356 | 'data' => json_encode($post_data), 1357 | 'header' => array( 1358 | 'Authorization:'.$sign, 1359 | 'Content-Type:text/json', 1360 | 'Expect: ', 1361 | ), 1362 | ); 1363 | $rsp = Http::send($req); 1364 | 1365 | $ret = json_decode($rsp, true); 1366 | 1367 | if(!$ret){ 1368 | return self::getStatusText(); 1369 | } 1370 | 1371 | return $ret; 1372 | } 1373 | 1374 | /** 1375 | * @param $url 图片url 1376 | * @return 返回的结果,JSON字符串,字段参见API文档 1377 | */ 1378 | public static function imagepornurl($url) { 1379 | 1380 | $expired = time() + self::EXPIRED_SECONDS; 1381 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageporn'; 1382 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1383 | 1384 | $post_data = array( 1385 | 'app_id' => Conf::$APPID, 1386 | 'url' => $url, 1387 | ); 1388 | 1389 | $req = array( 1390 | 'url' => $postUrl, 1391 | 'method' => 'post', 1392 | 'timeout' => 10, 1393 | 'data' => json_encode($post_data), 1394 | 'header' => array( 1395 | 'Authorization:'.$sign, 1396 | 'Content-Type:text/json', 1397 | 'Expect: ', 1398 | ), 1399 | ); 1400 | $rsp = Http::send($req); 1401 | 1402 | $ret = json_decode($rsp, true); 1403 | 1404 | if(!$ret){ 1405 | return self::getStatusText(); 1406 | } 1407 | 1408 | return $ret; 1409 | } 1410 | 1411 | /** 1412 | * imageterrorism 暴恐图片识别 1413 | * @param $image_path 待检测的路径 1414 | * @return 返回的结果,JSON字符串,字段参见API文档 1415 | */ 1416 | public static function imageterrorism($image_path) { 1417 | 1418 | $real_image_path = realpath($image_path); 1419 | 1420 | if (!file_exists($real_image_path)) 1421 | { 1422 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1423 | } 1424 | 1425 | $expired = time() + self::EXPIRED_SECONDS; 1426 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageterrorism'; 1427 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1428 | 1429 | $image_data = file_get_contents($real_image_path); 1430 | $post_data = array( 1431 | 'app_id' => Conf::$APPID, 1432 | 'image' => base64_encode($image_data), 1433 | ); 1434 | 1435 | $req = array( 1436 | 'url' => $postUrl, 1437 | 'method' => 'post', 1438 | 'timeout' => 10, 1439 | 'data' => json_encode($post_data), 1440 | 'header' => array( 1441 | 'Authorization:'.$sign, 1442 | 'Content-Type:text/json', 1443 | 'Expect: ', 1444 | ), 1445 | ); 1446 | $rsp = Http::send($req); 1447 | 1448 | $ret = json_decode($rsp, true); 1449 | 1450 | if(!$ret){ 1451 | return self::getStatusText(); 1452 | } 1453 | 1454 | return $ret; 1455 | } 1456 | 1457 | /** 1458 | * imageterrorismurl 暴恐图片识别 1459 | * @param $url 图片url 1460 | * @return 返回的结果,JSON字符串,字段参见API文档 1461 | */ 1462 | public static function imageterrorismurl($url) { 1463 | 1464 | $expired = time() + self::EXPIRED_SECONDS; 1465 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageterrorism'; 1466 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1467 | 1468 | $post_data = array( 1469 | 'app_id' => Conf::$APPID, 1470 | 'url' => $url, 1471 | ); 1472 | 1473 | $req = array( 1474 | 'url' => $postUrl, 1475 | 'method' => 'post', 1476 | 'timeout' => 10, 1477 | 'data' => json_encode($post_data), 1478 | 'header' => array( 1479 | 'Authorization:'.$sign, 1480 | 'Content-Type:text/json', 1481 | 'Expect: ', 1482 | ), 1483 | ); 1484 | $rsp = Http::send($req); 1485 | 1486 | $ret = json_decode($rsp, true); 1487 | 1488 | if(!$ret){ 1489 | return self::getStatusText(); 1490 | } 1491 | 1492 | return $ret; 1493 | } 1494 | 1495 | /** 1496 | * carclassify 车辆属性识别 1497 | * @param $image_path 待检测的路径 1498 | * @return 返回的结果,JSON字符串,字段参见API文档 1499 | */ 1500 | public static function carclassify($image_path) { 1501 | 1502 | $real_image_path = realpath($image_path); 1503 | 1504 | if (!file_exists($real_image_path)) 1505 | { 1506 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1507 | } 1508 | 1509 | $expired = time() + self::EXPIRED_SECONDS; 1510 | $postUrl = Conf::$END_POINT . 'youtu/carapi/carclassify'; 1511 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1512 | 1513 | $image_data = file_get_contents($real_image_path); 1514 | $post_data = array( 1515 | 'app_id' => Conf::$APPID, 1516 | 'image' => base64_encode($image_data), 1517 | ); 1518 | 1519 | $req = array( 1520 | 'url' => $postUrl, 1521 | 'method' => 'post', 1522 | 'timeout' => 10, 1523 | 'data' => json_encode($post_data), 1524 | 'header' => array( 1525 | 'Authorization:'.$sign, 1526 | 'Content-Type:text/json', 1527 | 'Expect: ', 1528 | ), 1529 | ); 1530 | $rsp = Http::send($req); 1531 | 1532 | $ret = json_decode($rsp, true); 1533 | 1534 | if(!$ret){ 1535 | return self::getStatusText(); 1536 | } 1537 | 1538 | return $ret; 1539 | } 1540 | 1541 | /** 1542 | * carclassifyurl 车辆属性识别 1543 | * @param $url 图片url 1544 | * @return 返回的结果,JSON字符串,字段参见API文档 1545 | */ 1546 | public static function carclassifyurl($url) { 1547 | 1548 | $expired = time() + self::EXPIRED_SECONDS; 1549 | $postUrl = Conf::$END_POINT . 'youtu/imageapi/imageterrorism'; 1550 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1551 | 1552 | $post_data = array( 1553 | 'app_id' => Conf::$APPID, 1554 | 'url' => $url, 1555 | ); 1556 | 1557 | $req = array( 1558 | 'url' => $postUrl, 1559 | 'method' => 'post', 1560 | 'timeout' => 10, 1561 | 'data' => json_encode($post_data), 1562 | 'header' => array( 1563 | 'Authorization:'.$sign, 1564 | 'Content-Type:text/json', 1565 | 'Expect: ', 1566 | ), 1567 | ); 1568 | $rsp = Http::send($req); 1569 | 1570 | $ret = json_decode($rsp, true); 1571 | 1572 | if(!$ret){ 1573 | return self::getStatusText(); 1574 | } 1575 | 1576 | return $ret; 1577 | } 1578 | 1579 | /** 1580 | * @param $url 图片url 1581 | * @param $card_type 身份证照片类型,0 表示身份证正面, 1表示身份证反面 1582 | * @return 返回的结果,JSON字符串,字段参见API文档 1583 | */ 1584 | public static function idcardocr($image_path, $card_type = 0, $seq = '') { 1585 | 1586 | $real_image_path = realpath($image_path); 1587 | 1588 | if (!file_exists($real_image_path)) 1589 | { 1590 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1591 | } 1592 | 1593 | $expired = time() + self::EXPIRED_SECONDS; 1594 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/idcardocr'; 1595 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1596 | 1597 | $image_data = file_get_contents($real_image_path); 1598 | $post_data = array( 1599 | 'app_id' => Conf::$APPID, 1600 | 'image' => base64_encode($image_data), 1601 | 'seq' => $seq, 1602 | 'card_type' => $card_type, 1603 | ); 1604 | 1605 | $req = array( 1606 | 'url' => $postUrl, 1607 | 'method' => 'post', 1608 | 'timeout' => 10, 1609 | 'data' => json_encode($post_data), 1610 | 'header' => array( 1611 | 'Authorization:'.$sign, 1612 | 'Content-Type:text/json', 1613 | 'Expect: ', 1614 | ), 1615 | ); 1616 | $rsp = Http::send($req); 1617 | 1618 | $ret = json_decode($rsp, true); 1619 | 1620 | if(!$ret){ 1621 | return self::getStatusText(); 1622 | } 1623 | 1624 | return $ret; 1625 | } 1626 | 1627 | /** 1628 | * @param $url 图片url 1629 | * @param $card_type 身份证照片类型,0 表示身份证正面, 1表示身份证反面 1630 | * @return 返回的结果,JSON字符串,字段参见API文档 1631 | */ 1632 | public static function idcardocrurl($url, $card_type, $seq = '') { 1633 | 1634 | $expired = time() + self::EXPIRED_SECONDS; 1635 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/idcardocr'; 1636 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1637 | 1638 | $post_data = array( 1639 | 'app_id' => Conf::$APPID, 1640 | 'url' => $url, 1641 | 'seq' => $seq, 1642 | 'card_type' => $card_type, 1643 | ); 1644 | 1645 | $req = array( 1646 | 'url' => $postUrl, 1647 | 'method' => 'post', 1648 | 'timeout' => 10, 1649 | 'data' => json_encode($post_data), 1650 | 'header' => array( 1651 | 'Authorization:'.$sign, 1652 | 'Content-Type:text/json', 1653 | 'Expect: ', 1654 | ), 1655 | ); 1656 | $rsp = Http::send($req); 1657 | 1658 | $ret = json_decode($rsp, true); 1659 | 1660 | if(!$ret){ 1661 | return self::getStatusText(); 1662 | } 1663 | 1664 | return $ret; 1665 | } 1666 | 1667 | 1668 | /** 1669 | * @param $url 图片url 1670 | * @param $retimage 是否返回名片图像 1671 | * @return 返回的结果,JSON字符串,字段参见API文档 1672 | */ 1673 | public static function namecardocrurl($url, $retimage = 1, $seq = '') 1674 | { 1675 | 1676 | $expired = time() + self::EXPIRED_SECONDS; 1677 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/namecardocr'; 1678 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1679 | 1680 | $post_data = array( 1681 | 'app_id' => Conf::$APPID, 1682 | 'url' => $url, 1683 | 'seq' => $seq, 1684 | 'retimage'=> (bool)$retimage 1685 | ); 1686 | 1687 | 1688 | $req = array( 1689 | 'url' => $postUrl, 1690 | 'method' => 'post', 1691 | 'timeout' => 10, 1692 | 'data' => json_encode($post_data), 1693 | 'header' => array( 1694 | 'Authorization:'.$sign, 1695 | 'Content-Type:text/json', 1696 | 'Expect: ', 1697 | ), 1698 | ); 1699 | $rsp = Http::send($req); 1700 | 1701 | $ret = json_decode($rsp, true); 1702 | 1703 | if(!$ret){ 1704 | return self::getStatusText(); 1705 | } 1706 | 1707 | return $ret; 1708 | } 1709 | 1710 | public static function livegetfour($seq = '') 1711 | { 1712 | 1713 | $expired = time() + self::EXPIRED_SECONDS; 1714 | $postUrl = Conf::$END_POINT . 'youtu/openliveapi/livegetfour'; 1715 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1716 | 1717 | $post_data = array( 1718 | 'app_id' => Conf::$APPID, 1719 | 'seq' => $seq 1720 | ); 1721 | 1722 | 1723 | $req = array( 1724 | 'url' => $postUrl, 1725 | 'method' => 'post', 1726 | 'timeout' => 10, 1727 | 'data' => json_encode($post_data), 1728 | 'header' => array( 1729 | 'Authorization:'.$sign, 1730 | 'Content-Type:text/json', 1731 | 'Expect: ', 1732 | ), 1733 | ); 1734 | $rsp = Http::send($req); 1735 | 1736 | $ret = json_decode($rsp, true); 1737 | 1738 | if(!$ret){ 1739 | return self::getStatusText(); 1740 | } 1741 | return $ret; 1742 | } 1743 | 1744 | public static function livedetectfour($validate_data,$video_path,$card_path,$compare_card=false,$seq = '') 1745 | { 1746 | 1747 | $expired = time() + self::EXPIRED_SECONDS; 1748 | $postUrl = Conf::$END_POINT . 'youtu/openliveapi/livedetectfour'; 1749 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1750 | 1751 | $real_video_path = realpath($video_path); 1752 | if (!file_exists($real_video_path)) 1753 | { 1754 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$video_path.' not exists', 'data' => array()); 1755 | } 1756 | 1757 | $video_data = file_get_contents($real_video_path); 1758 | 1759 | if($compare_card) 1760 | { 1761 | $real_card_path = realpath($card_path); 1762 | if (!file_exists($real_card_path)) 1763 | { 1764 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$card_path.' not exists', 'data' => array()); 1765 | } 1766 | 1767 | $card_data = file_get_contents($real_card_path); 1768 | $post_data = array( 1769 | 'app_id' => Conf::$APPID, 1770 | 'validate_data' => $validate_data, 1771 | 'compare_flag' => true, 1772 | 'video' => base64_encode($video_data), 1773 | 'card' => base64_encode($card_data), 1774 | 'seq' => $seq 1775 | ); 1776 | } 1777 | else 1778 | { 1779 | $post_data = array( 1780 | 'app_id' => Conf::$APPID, 1781 | 'validate_data' => $validate_data, 1782 | 'compare_flag' => false, 1783 | 'video' => base64_encode($video_data), 1784 | 'seq' => $seq 1785 | ); 1786 | } 1787 | 1788 | $req = array( 1789 | 'url' => $postUrl, 1790 | 'method' => 'post', 1791 | 'timeout' => 10, 1792 | 'data' => json_encode($post_data), 1793 | 'header' => array( 1794 | 'Authorization:'.$sign, 1795 | 'Content-Type:text/json', 1796 | 'Expect: ', 1797 | ), 1798 | ); 1799 | $rsp = Http::send($req); 1800 | 1801 | $ret = json_decode($rsp, true); 1802 | 1803 | if(!$ret){ 1804 | return self::getStatusText(); 1805 | } 1806 | return $ret; 1807 | } 1808 | 1809 | public static function idcardlivedetectfour($idcard_number,$idcard_name,$validate_data,$video_path,$seq = '') 1810 | { 1811 | 1812 | $expired = time() + self::EXPIRED_SECONDS; 1813 | $postUrl = Conf::$END_POINT . 'youtu/openliveapi/idcardlivedetectfour'; 1814 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1815 | 1816 | $real_video_path = realpath($video_path); 1817 | if (!file_exists($real_video_path)) 1818 | { 1819 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$video_path.' not exists', 'data' => array()); 1820 | } 1821 | 1822 | $video_data = file_get_contents($real_video_path); 1823 | 1824 | $post_data = array( 1825 | 'app_id' => Conf::$APPID, 1826 | 'idcard_number' => $idcard_number, 1827 | 'idcard_name' => $idcard_name, 1828 | 'validate_data' => $validate_data, 1829 | 'video' => base64_encode($video_data), 1830 | 'seq' => $seq 1831 | ); 1832 | 1833 | 1834 | $req = array( 1835 | 'url' => $postUrl, 1836 | 'method' => 'post', 1837 | 'timeout' => 10, 1838 | 'data' => json_encode($post_data), 1839 | 'header' => array( 1840 | 'Authorization:'.$sign, 1841 | 'Content-Type:text/json', 1842 | 'Expect: ', 1843 | ), 1844 | ); 1845 | $rsp = Http::send($req); 1846 | 1847 | $ret = json_decode($rsp, true); 1848 | 1849 | if(!$ret){ 1850 | return self::getStatusText(); 1851 | } 1852 | return $ret; 1853 | } 1854 | 1855 | public static function idcardfacecompare($idcard_number,$idcard_name,$image_path,$seq = '') 1856 | { 1857 | 1858 | $expired = time() + self::EXPIRED_SECONDS; 1859 | $postUrl = Conf::$END_POINT . 'youtu/openliveapi/idcardfacecompare'; 1860 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1861 | 1862 | $real_image_path = realpath($image_path); 1863 | if (!file_exists($real_image_path)) 1864 | { 1865 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1866 | } 1867 | 1868 | $image_data = file_get_contents($real_image_path); 1869 | 1870 | $post_data = array( 1871 | 'app_id' => Conf::$APPID, 1872 | 'idcard_number' => $idcard_number, 1873 | 'idcard_name' => $idcard_name, 1874 | 'image' => base64_encode($image_data), 1875 | 'seq' => $seq 1876 | ); 1877 | 1878 | 1879 | $req = array( 1880 | 'url' => $postUrl, 1881 | 'method' => 'post', 1882 | 'timeout' => 10, 1883 | 'data' => json_encode($post_data), 1884 | 'header' => array( 1885 | 'Authorization:'.$sign, 1886 | 'Content-Type:text/json', 1887 | 'Expect: ', 1888 | ), 1889 | ); 1890 | $rsp = Http::send($req); 1891 | 1892 | $ret = json_decode($rsp, true); 1893 | 1894 | if(!$ret){ 1895 | return self::getStatusText(); 1896 | } 1897 | return $ret; 1898 | } 1899 | 1900 | public static function validateidcard($idcard_number,$idcard_name,$seq = '') 1901 | { 1902 | 1903 | $expired = time() + self::EXPIRED_SECONDS; 1904 | $postUrl = Conf::$END_POINT . 'youtu/openliveapi/validateidcard'; 1905 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1906 | 1907 | 1908 | $post_data = array( 1909 | 'app_id' => Conf::$APPID, 1910 | 'idcard_number' => $idcard_number, 1911 | 'idcard_name' => $idcard_name, 1912 | 'seq' => $seq 1913 | ); 1914 | 1915 | 1916 | $req = array( 1917 | 'url' => $postUrl, 1918 | 'method' => 'post', 1919 | 'timeout' => 10, 1920 | 'data' => json_encode($post_data), 1921 | 'header' => array( 1922 | 'Authorization:'.$sign, 1923 | 'Content-Type:text/json', 1924 | 'Expect: ', 1925 | ), 1926 | ); 1927 | $rsp = Http::send($req); 1928 | 1929 | $ret = json_decode($rsp, true); 1930 | 1931 | if(!$ret){ 1932 | return self::getStatusText(); 1933 | } 1934 | return $ret; 1935 | } 1936 | 1937 | /** 1938 | * @param $image_path 待检测的路径 1939 | * @return 返回的结果,JSON字符串,字段参见API文档 1940 | */ 1941 | public static function generalocr($image_path, $seq='') { 1942 | 1943 | $real_image_path = realpath($image_path); 1944 | if(!file_exists($real_image_path)) 1945 | { 1946 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 1947 | } 1948 | 1949 | $expired = time() + self::EXPIRED_SECONDS; 1950 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/generalocr'; 1951 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1952 | 1953 | $image_data = file_get_contents($real_image_path); 1954 | 1955 | $post_data = array( 1956 | 'app_id' => Conf::$APPID, 1957 | 'image' => base64_encode($image_data) 1958 | ); 1959 | 1960 | $req = array( 1961 | 'url' => $postUrl, 1962 | 'method' => 'post', 1963 | 'timeout' => 10, 1964 | 'data' => json_encode($post_data), 1965 | 'header' => array( 1966 | 'Authorization:'.$sign, 1967 | 'Content-Type:text/json', 1968 | 'Expect: ', 1969 | ), 1970 | ); 1971 | 1972 | $rsp = Http::send($req); 1973 | $ret = json_decode($rsp, true); 1974 | 1975 | if(!$ret){ 1976 | return self::getStatusText(); 1977 | } 1978 | return $ret; 1979 | } 1980 | 1981 | /** 1982 | * @param $url 待检测的图片url 1983 | * @return 返回的结果,JSON字符串,字段参见API文档 1984 | */ 1985 | public static function generalocrurl($url, $seq='') { 1986 | 1987 | $expired = time() + self::EXPIRED_SECONDS; 1988 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/generalocr'; 1989 | $sign = Auth::appSign($expired, Conf::$USER_ID); 1990 | 1991 | $post_data = array( 1992 | 'app_id' => Conf::$APPID, 1993 | 'url' => $url 1994 | ); 1995 | 1996 | $req = array( 1997 | 'url' => $postUrl, 1998 | 'method' => 'post', 1999 | 'timeout' => 10, 2000 | 'data' => json_encode($post_data), 2001 | 'header' => array( 2002 | 'Authorization:'.$sign, 2003 | 'Content-Type:text/json', 2004 | 'Expect: ', 2005 | ), 2006 | ); 2007 | 2008 | $rsp = Http::send($req); 2009 | $ret = json_decode($rsp, true); 2010 | 2011 | if(!$ret){ 2012 | return self::getStatusText(); 2013 | } 2014 | return $ret; 2015 | } 2016 | 2017 | /** 2018 | * @param $image_path 待检测的路径 2019 | * @param $card_type 图片类型:行驶证/驾驶证 0/1 2020 | * @return 返回的结果,JSON字符串,字段参见API文档 2021 | */ 2022 | public static function driverlicenseocr($image_path, $card_type, $seq='') { 2023 | 2024 | $real_image_path = realpath($image_path); 2025 | if(!file_exists($real_image_path)) 2026 | { 2027 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 2028 | } 2029 | 2030 | $expired = time() + self::EXPIRED_SECONDS; 2031 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/driverlicenseocr'; 2032 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2033 | 2034 | $image_data = file_get_contents($real_image_path); 2035 | 2036 | $post_data = array( 2037 | 'app_id' => Conf::$APPID, 2038 | 'type' => $card_type, 2039 | 'image' => base64_encode($image_data) 2040 | ); 2041 | 2042 | $req = array( 2043 | 'url' => $postUrl, 2044 | 'method' => 'post', 2045 | 'timeout' => 10, 2046 | 'data' => json_encode($post_data), 2047 | 'header' => array( 2048 | 'Authorization:'.$sign, 2049 | 'Content-Type:text/json', 2050 | 'Expect: ', 2051 | ), 2052 | ); 2053 | 2054 | $rsp = Http::send($req); 2055 | $ret = json_decode($rsp, true); 2056 | 2057 | if(!$ret){ 2058 | return self::getStatusText(); 2059 | } 2060 | return $ret; 2061 | } 2062 | 2063 | /** 2064 | * @param $url 待检测的图片url 2065 | * @return 返回的结果,JSON字符串,字段参见API文档 2066 | */ 2067 | public static function driverlicenseocrurl($url, $card_type, $seq='') { 2068 | 2069 | $expired = time() + self::EXPIRED_SECONDS; 2070 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/driverlicenseocr'; 2071 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2072 | 2073 | $post_data = array( 2074 | 'app_id' => Conf::$APPID, 2075 | 'type' => $card_type, 2076 | 'url' => $url 2077 | ); 2078 | 2079 | $req = array( 2080 | 'url' => $postUrl, 2081 | 'method' => 'post', 2082 | 'timeout' => 10, 2083 | 'data' => json_encode($post_data), 2084 | 'header' => array( 2085 | 'Authorization:'.$sign, 2086 | 'Content-Type:text/json', 2087 | 'Expect: ', 2088 | ), 2089 | ); 2090 | 2091 | $rsp = Http::send($req); 2092 | $ret = json_decode($rsp, true); 2093 | 2094 | if(!$ret){ 2095 | return self::getStatusText(); 2096 | } 2097 | return $ret; 2098 | } 2099 | 2100 | /** 2101 | * @param $image_path 待检测的路径 2102 | * @return 返回的结果,JSON字符串,字段参见API文档 2103 | */ 2104 | public static function bcocr($image_path, $seq='') { 2105 | 2106 | $real_image_path = realpath($image_path); 2107 | if(!file_exists($real_image_path)) 2108 | { 2109 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 2110 | } 2111 | 2112 | $expired = time() + self::EXPIRED_SECONDS; 2113 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/bcocr'; 2114 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2115 | 2116 | $image_data = file_get_contents($real_image_path); 2117 | 2118 | $post_data = array( 2119 | 'app_id' => Conf::$APPID, 2120 | 'image' => base64_encode($image_data) 2121 | ); 2122 | 2123 | $req = array( 2124 | 'url' => $postUrl, 2125 | 'method' => 'post', 2126 | 'timeout' => 10, 2127 | 'data' => json_encode($post_data), 2128 | 'header' => array( 2129 | 'Authorization:'.$sign, 2130 | 'Content-Type:text/json', 2131 | 'Expect: ', 2132 | ), 2133 | ); 2134 | 2135 | $rsp = Http::send($req); 2136 | $ret = json_decode($rsp, true); 2137 | 2138 | if(!$ret){ 2139 | return self::getStatusText(); 2140 | } 2141 | return $ret; 2142 | } 2143 | 2144 | /** 2145 | * @param $url 待检测的图片url 2146 | * @return 返回的结果,JSON字符串,字段参见API文档 2147 | */ 2148 | public static function bcocrurl($url, $seq='') { 2149 | 2150 | $expired = time() + self::EXPIRED_SECONDS; 2151 | $postUrl = Conf::$END_POINT . '/youtu/ocrapi/bcocr'; 2152 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2153 | 2154 | $post_data = array( 2155 | 'app_id' => Conf::$APPID, 2156 | 'url' => $url 2157 | ); 2158 | 2159 | $req = array( 2160 | 'url' => $postUrl, 2161 | 'method' => 'post', 2162 | 'timeout' => 10, 2163 | 'data' => json_encode($post_data), 2164 | 'header' => array( 2165 | 'Authorization:'.$sign, 2166 | 'Content-Type:text/json', 2167 | 'Expect: ', 2168 | ), 2169 | ); 2170 | 2171 | $rsp = Http::send($req); 2172 | $ret = json_decode($rsp, true); 2173 | 2174 | if(!$ret){ 2175 | return self::getStatusText(); 2176 | } 2177 | return $ret; 2178 | } 2179 | 2180 | /** 2181 | * creditcardocr 银行卡OCR识别 2182 | * @param $image_path 待检测的路径 2183 | * @return 返回的结果,JSON字符串,字段参见API文档 2184 | */ 2185 | public static function creditcardocr($image_path, $seq='') { 2186 | 2187 | $real_image_path = realpath($image_path); 2188 | if(!file_exists($real_image_path)) 2189 | { 2190 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 2191 | } 2192 | 2193 | $expired = time() + self::EXPIRED_SECONDS; 2194 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/creditcardocr'; 2195 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2196 | 2197 | $image_data = file_get_contents($real_image_path); 2198 | 2199 | $post_data = array( 2200 | 'app_id' => Conf::$APPID, 2201 | 'image' => base64_encode($image_data) 2202 | ); 2203 | 2204 | $req = array( 2205 | 'url' => $postUrl, 2206 | 'method' => 'post', 2207 | 'timeout' => 10, 2208 | 'data' => json_encode($post_data), 2209 | 'header' => array( 2210 | 'Authorization:'.$sign, 2211 | 'Content-Type:text/json', 2212 | 'Expect: ', 2213 | ), 2214 | ); 2215 | 2216 | $rsp = Http::send($req); 2217 | $ret = json_decode($rsp, true); 2218 | 2219 | if(!$ret){ 2220 | return self::getStatusText(); 2221 | } 2222 | return $ret; 2223 | } 2224 | 2225 | /** 2226 | * creditcardocrurl 银行卡OCR识别 2227 | * @param $url 待检测的图片url 2228 | * @return 返回的结果,JSON字符串,字段参见API文档 2229 | */ 2230 | public static function creditcardocrurl($url, $seq='') { 2231 | 2232 | $expired = time() + self::EXPIRED_SECONDS; 2233 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/creditcardocr'; 2234 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2235 | 2236 | $post_data = array( 2237 | 'app_id' => Conf::$APPID, 2238 | 'url' => $url 2239 | ); 2240 | 2241 | $req = array( 2242 | 'url' => $postUrl, 2243 | 'method' => 'post', 2244 | 'timeout' => 10, 2245 | 'data' => json_encode($post_data), 2246 | 'header' => array( 2247 | 'Authorization:'.$sign, 2248 | 'Content-Type:text/json', 2249 | 'Expect: ', 2250 | ), 2251 | ); 2252 | 2253 | $rsp = Http::send($req); 2254 | $ret = json_decode($rsp, true); 2255 | 2256 | if(!$ret){ 2257 | return self::getStatusText(); 2258 | } 2259 | return $ret; 2260 | } 2261 | 2262 | /** 2263 | * bizlicenseocr 营业执照OCR识别 2264 | * @param $image_path 待检测的路径 2265 | * @return 返回的结果,JSON字符串,字段参见API文档 2266 | */ 2267 | public static function bizlicenseocr($image_path, $seq='') { 2268 | 2269 | $real_image_path = realpath($image_path); 2270 | if(!file_exists($real_image_path)) 2271 | { 2272 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 2273 | } 2274 | 2275 | $expired = time() + self::EXPIRED_SECONDS; 2276 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/bizlicenseocr'; 2277 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2278 | 2279 | $image_data = file_get_contents($real_image_path); 2280 | 2281 | $post_data = array( 2282 | 'app_id' => Conf::$APPID, 2283 | 'image' => base64_encode($image_data) 2284 | ); 2285 | 2286 | $req = array( 2287 | 'url' => $postUrl, 2288 | 'method' => 'post', 2289 | 'timeout' => 10, 2290 | 'data' => json_encode($post_data), 2291 | 'header' => array( 2292 | 'Authorization:'.$sign, 2293 | 'Content-Type:text/json', 2294 | 'Expect: ', 2295 | ), 2296 | ); 2297 | 2298 | $rsp = Http::send($req); 2299 | $ret = json_decode($rsp, true); 2300 | 2301 | if(!$ret){ 2302 | return self::getStatusText(); 2303 | } 2304 | return $ret; 2305 | } 2306 | 2307 | /** 2308 | * bizlicenseocrurl 营业执照OCR识别 2309 | * @param $url 待检测的图片url 2310 | * @return 返回的结果,JSON字符串,字段参见API文档 2311 | */ 2312 | public static function bizlicenseocrurl($url, $seq='') { 2313 | 2314 | $expired = time() + self::EXPIRED_SECONDS; 2315 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/bizlicenseocr'; 2316 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2317 | 2318 | $post_data = array( 2319 | 'app_id' => Conf::$APPID, 2320 | 'url' => $url 2321 | ); 2322 | 2323 | $req = array( 2324 | 'url' => $postUrl, 2325 | 'method' => 'post', 2326 | 'timeout' => 10, 2327 | 'data' => json_encode($post_data), 2328 | 'header' => array( 2329 | 'Authorization:'.$sign, 2330 | 'Content-Type:text/json', 2331 | 'Expect: ', 2332 | ), 2333 | ); 2334 | 2335 | $rsp = Http::send($req); 2336 | $ret = json_decode($rsp, true); 2337 | 2338 | if(!$ret){ 2339 | return self::getStatusText(); 2340 | } 2341 | return $ret; 2342 | } 2343 | 2344 | /** 2345 | * plateocr 车牌OCR识别 2346 | * @param $image_path 待检测的路径 2347 | * @return 返回的结果,JSON字符串,字段参见API文档 2348 | */ 2349 | public static function plateocr($image_path, $seq='') { 2350 | 2351 | $real_image_path = realpath($image_path); 2352 | if(!file_exists($real_image_path)) 2353 | { 2354 | return array('httpcode' => 0, 'code' => self::HTTP_BAD_REQUEST, 'message' => 'file '.$image_path.' not exists', 'data' => array()); 2355 | } 2356 | 2357 | $expired = time() + self::EXPIRED_SECONDS; 2358 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/plateocr'; 2359 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2360 | 2361 | $image_data = file_get_contents($real_image_path); 2362 | 2363 | $post_data = array( 2364 | 'app_id' => Conf::$APPID, 2365 | 'image' => base64_encode($image_data) 2366 | ); 2367 | 2368 | $req = array( 2369 | 'url' => $postUrl, 2370 | 'method' => 'post', 2371 | 'timeout' => 10, 2372 | 'data' => json_encode($post_data), 2373 | 'header' => array( 2374 | 'Authorization:'.$sign, 2375 | 'Content-Type:text/json', 2376 | 'Expect: ', 2377 | ), 2378 | ); 2379 | 2380 | $rsp = Http::send($req); 2381 | $ret = json_decode($rsp, true); 2382 | 2383 | if(!$ret){ 2384 | return self::getStatusText(); 2385 | } 2386 | return $ret; 2387 | } 2388 | 2389 | /** 2390 | * plateocrurl 车牌OCR识别 2391 | * @param $url 待检测的图片url 2392 | * @return 返回的结果,JSON字符串,字段参见API文档 2393 | */ 2394 | public static function plateocrurl($url, $seq='') { 2395 | 2396 | $expired = time() + self::EXPIRED_SECONDS; 2397 | $postUrl = Conf::$END_POINT . 'youtu/ocrapi/plateocr'; 2398 | $sign = Auth::appSign($expired, Conf::$USER_ID); 2399 | 2400 | $post_data = array( 2401 | 'app_id' => Conf::$APPID, 2402 | 'url' => $url 2403 | ); 2404 | 2405 | $req = array( 2406 | 'url' => $postUrl, 2407 | 'method' => 'post', 2408 | 'timeout' => 10, 2409 | 'data' => json_encode($post_data), 2410 | 'header' => array( 2411 | 'Authorization:'.$sign, 2412 | 'Content-Type:text/json', 2413 | 'Expect: ', 2414 | ), 2415 | ); 2416 | 2417 | $rsp = Http::send($req); 2418 | $ret = json_decode($rsp, true); 2419 | 2420 | if(!$ret){ 2421 | return self::getStatusText(); 2422 | } 2423 | return $ret; 2424 | } 2425 | } 2426 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "TencentYoutuyun/php-sdk", 3 | "keywords": ["TencentYoutuyun", "qcloud", "sdk"], 4 | "homepage": "http://open.youtu.qq.com/", 5 | "license": "MIT", 6 | "description": "php sdk for open.youtu.qq.com person face service", 7 | "require": { 8 | "php": ">=5.3.0" 9 | }, 10 | "autoload": { 11 | "psr-4": {"TencentYoutuyun\\": "TencentYoutuyun"} 12 | } 13 | } -------------------------------------------------------------------------------- /include.php: -------------------------------------------------------------------------------- 1 | = php 5.3.0 4 | spl_autoload_register(function($class){ 5 | $dir = dirname(__FILE__); 6 | $class = str_replace('\\', DIRECTORY_SEPARATOR, $class) . '.php'; 7 | include($dir.DIRECTORY_SEPARATOR.$class); 8 | }); -------------------------------------------------------------------------------- /sample.php: -------------------------------------------------------------------------------- 1 | 83 | -------------------------------------------------------------------------------- /test.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/Tencent-YouTu/php_sdk/dbce48f90f8ee4c7bc2080a5e84ab44e090e9b23/test.jpg --------------------------------------------------------------------------------