xiaogang 4 lat temu
rodzic
commit
db4908b758

+ 14 - 7
app/Http/Controllers/Api/UserController.php

xqd xqd xqd xqd
@@ -176,10 +176,9 @@ class UserController extends Controller
     public function get_photo(){
         try {
             $user = auth('api')->user();
-            $userinfo = UserInfoModel::query()->where('user_id', $user->id)->first(['photo','video']);
-            $userinfo['photo'] = json_decode($userinfo['photo'],true);
-            $userinfo['video'] = json_decode($userinfo['video'],true);
-
+            $userinfo = DB::table('users_info')->where(['user_id'=>$user->id])->select('photo','video')->first();
+            $userinfo->photo = json_decode($userinfo->photo,true);
+            $userinfo->video = json_decode($userinfo->video,true);
         }catch (\Exception $exception){
             return $this->response->errorForbidden($exception->getMessage());
         }
@@ -191,7 +190,7 @@ class UserController extends Controller
      * @param Request $request
      * @return \Illuminate\Http\JsonResponse|void
      */
-    public function upload_file(Request $request){
+        public function upload_file(Request $request){
         try {
             if($request->post('url')==''){
                 throw new Exception("请选择上传内容");
@@ -200,12 +199,12 @@ class UserController extends Controller
             $userinfo = UserInfoModel::query()->where('user_id',$user->id)->first();
             if($request->type==1){
                 //图片
-                $user_photo = json_encode($userinfo->photo,true);
+                $user_photo = json_decode($userinfo->photo,true);
                 $user_photo []= $request->post('url');
                 $userinfo->photo = json_encode($user_photo);
             }else{
                 //视频
-                $user_video = json_encode($userinfo->video,true);
+                $user_video = json_decode($userinfo->video,true);
                 $user_video []= $request->post('url');
                 $userinfo->video = json_encode($user_video);
             }
@@ -288,5 +287,13 @@ class UserController extends Controller
         return response()->json($res);
     }
 
+    public function auth(Request $request){
+        $apiFace = new \AipFace(env('BAI_DU_YUN_APP_ID'),env('BAI_DU_YUN_API_KEY'),env('BAI_DU_YUN_SECRET_KEY'));
+
+
+        $apiFace->match();
+
+    }
+
 
 }

+ 542 - 0
app/Libraries/baiduyun/AipFace.php

xqd
@@ -0,0 +1,542 @@
+<?php
+/*
+* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License. You may obtain a copy of
+* the License at
+*
+* Http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations under
+* the License.
+*/
+
+require_once 'lib/AipBase.php';
+class AipFace extends AipBase {
+
+    /**
+     * 人脸检测 detect api url
+     * @var string
+     */
+    private $detectUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/detect';
+
+    /**
+     * 人脸搜索 search api url
+     * @var string
+     */
+    private $searchUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/search';
+
+    /**
+     * 人脸搜索 M:N 识别 multi_search api url
+     * @var string
+     */
+    private $multiSearchUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/multi-search';
+
+    /**
+     * 人脸注册 user_add api url
+     * @var string
+     */
+    private $userAddUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/add';
+
+    /**
+     * 人脸更新 user_update api url
+     * @var string
+     */
+    private $userUpdateUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/update';
+
+    /**
+     * 人脸删除 face_delete api url
+     * @var string
+     */
+    private $faceDeleteUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/delete';
+
+    /**
+     * 用户信息查询 user_get api url
+     * @var string
+     */
+    private $userGetUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/get';
+
+    /**
+     * 获取用户人脸列表 face_getlist api url
+     * @var string
+     */
+    private $faceGetlistUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/face/getlist';
+
+    /**
+     * 获取用户列表 group_getusers api url
+     * @var string
+     */
+    private $groupGetusersUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/getusers';
+
+    /**
+     * 复制用户 user_copy api url
+     * @var string
+     */
+    private $userCopyUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/copy';
+
+    /**
+     * 删除用户 user_delete api url
+     * @var string
+     */
+    private $userDeleteUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/user/delete';
+
+    /**
+     * 创建用户组 group_add api url
+     * @var string
+     */
+    private $groupAddUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/add';
+
+    /**
+     * 删除用户组 group_delete api url
+     * @var string
+     */
+    private $groupDeleteUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/delete';
+
+    /**
+     * 组列表查询 group_getlist api url
+     * @var string
+     */
+    private $groupGetlistUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceset/group/getlist';
+
+    /**
+     * 身份验证 person_verify api url
+     * @var string
+     */
+    private $personVerifyUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/person/verify';
+
+    /**
+     * 语音校验码接口 video_sessioncode api url
+     * @var string
+     */
+    private $videoSessioncodeUrl = 'https://aip.baidubce.com/rest/2.0/face/v1/faceliveness/sessioncode';
+
+    
+
+    /**
+     * 人脸检测接口
+     *
+     * @param string $image - 图片信息(**总数据大小应小于10M**),图片上传方式根据image_type来判断
+     * @param string $imageType - 图片类型     <br> **BASE64**:图片的base64值,base64编码后的图片数据,编码后的图片大小不超过2M; <br>**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); <br>**FACE_TOKEN**: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   face_field 包括**age,beauty,expression,face_shape,gender,glasses,landmark,landmark72,landmark150,race,quality,eye_status,emotion,face_type信息**  <br> 逗号分隔. 默认只返回face_token、人脸框、概率和旋转角度
+     *   max_face_num 最多处理人脸的数目,默认值为1,仅检测图片中面积最大的那个人脸;**最大值10**,检测图片中面积最大的几张人脸。
+     *   face_type 人脸的类型 **LIVE**表示生活照:通常为手机、相机拍摄的人像图片、或从网络获取的人像图片等**IDCARD**表示身份证芯片照:二代身份证内置芯片中的人像照片 **WATERMARK**表示带水印证件照:一般为带水印的小图,如公安网小图 **CERT**表示证件照片:如拍摄的身份证、工卡、护照、学生证等证件图片 默认**LIVE**
+     *   liveness_control 活体检测控制  **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
+     * @return array
+     */
+    public function detect($image, $imageType, $options=array()){
+
+        $data = array();
+        
+        $data['image'] = $image;
+        $data['image_type'] = $imageType;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->detectUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 人脸搜索接口
+     *
+     * @param string $image - 图片信息(**总数据大小应小于10M**),图片上传方式根据image_type来判断
+     * @param string $imageType - 图片类型     <br> **BASE64**:图片的base64值,base64编码后的图片数据,编码后的图片大小不超过2M; <br>**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); <br>**FACE_TOKEN**: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。
+     * @param string $groupIdList - 从指定的group中进行查找 用逗号分隔,**上限20个**
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   max_face_num 最多处理人脸的数目<br>**默认值为1(仅检测图片中面积最大的那个人脸)** **最大值10**
+     *   match_threshold 匹配阈值(设置阈值后,score低于此阈值的用户信息将不会返回) 最大100 最小0 默认80 <br>**此阈值设置得越高,检索速度将会越快,推荐使用默认阈值`80`**
+     *   quality_control 图片质量控制  **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
+     *   liveness_control 活体检测控制  **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
+     *   user_id 当需要对特定用户进行比对时,指定user_id进行比对。即人脸认证功能。
+     *   max_user_num 查找后返回的用户数量。返回相似度最高的几个用户,默认为1,最多返回50个。
+     * @return array
+     */
+    public function search($image, $imageType, $groupIdList, $options=array()){
+
+        $data = array();
+        
+        $data['image'] = $image;
+        $data['image_type'] = $imageType;
+        $data['group_id_list'] = $groupIdList;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->searchUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 人脸搜索 M:N 识别接口
+     *
+     * @param string $image - 图片信息(**总数据大小应小于10M**),图片上传方式根据image_type来判断
+     * @param string $imageType - 图片类型     <br> **BASE64**:图片的base64值,base64编码后的图片数据,编码后的图片大小不超过2M; <br>**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); <br>**FACE_TOKEN**: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。
+     * @param string $groupIdList - 从指定的group中进行查找 用逗号分隔,**上限20个**
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   max_face_num 最多处理人脸的数目<br>**默认值为1(仅检测图片中面积最大的那个人脸)** **最大值10**
+     *   match_threshold 匹配阈值(设置阈值后,score低于此阈值的用户信息将不会返回) 最大100 最小0 默认80 <br>**此阈值设置得越高,检索速度将会越快,推荐使用默认阈值`80`**
+     *   quality_control 图片质量控制  **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
+     *   liveness_control 活体检测控制  **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
+     *   max_user_num 查找后返回的用户数量。返回相似度最高的几个用户,默认为1,最多返回50个。
+     * @return array
+     */
+    public function multiSearch($image, $imageType, $groupIdList, $options=array()){
+
+        $data = array();
+        
+        $data['image'] = $image;
+        $data['image_type'] = $imageType;
+        $data['group_id_list'] = $groupIdList;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->multiSearchUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 人脸注册接口
+     *
+     * @param string $image - 图片信息(总数据大小应小于10M),图片上传方式根据image_type来判断。注:组内每个uid下的人脸图片数目上限为20张
+     * @param string $imageType - 图片类型     <br> **BASE64**:图片的base64值,base64编码后的图片数据,编码后的图片大小不超过2M; <br>**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); <br>**FACE_TOKEN**: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   user_info 用户资料,长度限制256B
+     *   quality_control 图片质量控制  **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
+     *   liveness_control 活体检测控制  **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
+     *   action_type 操作方式  APPEND: 当user_id在库中已经存在时,对此user_id重复注册时,新注册的图片默认会追加到该user_id下,REPLACE : 当对此user_id重复注册时,则会用新图替换库中该user_id下所有图片,默认使用APPEND
+     * @return array
+     */
+    public function addUser($image, $imageType, $groupId, $userId, $options=array()){
+
+        $data = array();
+        
+        $data['image'] = $image;
+        $data['image_type'] = $imageType;
+        $data['group_id'] = $groupId;
+        $data['user_id'] = $userId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->userAddUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 人脸更新接口
+     *
+     * @param string $image - 图片信息(**总数据大小应小于10M**),图片上传方式根据image_type来判断
+     * @param string $imageType - 图片类型     <br> **BASE64**:图片的base64值,base64编码后的图片数据,编码后的图片大小不超过2M; <br>**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); <br>**FACE_TOKEN**: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。
+     * @param string $groupId - 更新指定groupid下uid对应的信息
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   user_info 用户资料,长度限制256B
+     *   quality_control 图片质量控制  **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
+     *   liveness_control 活体检测控制  **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
+     *   action_type 操作方式  APPEND: 当user_id在库中已经存在时,对此user_id重复注册时,新注册的图片默认会追加到该user_id下,REPLACE : 当对此user_id重复注册时,则会用新图替换库中该user_id下所有图片,默认使用APPEND
+     * @return array
+     */
+    public function updateUser($image, $imageType, $groupId, $userId, $options=array()){
+
+        $data = array();
+        
+        $data['image'] = $image;
+        $data['image_type'] = $imageType;
+        $data['group_id'] = $groupId;
+        $data['user_id'] = $userId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->userUpdateUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 人脸删除接口
+     *
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param string $faceToken - 需要删除的人脸图片token,(由数字、字母、下划线组成)长度限制64B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     * @return array
+     */
+    public function faceDelete($userId, $groupId, $faceToken, $options=array()){
+
+        $data = array();
+        
+        $data['user_id'] = $userId;
+        $data['group_id'] = $groupId;
+        $data['face_token'] = $faceToken;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->faceDeleteUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 用户信息查询接口
+     *
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     * @return array
+     */
+    public function getUser($userId, $groupId, $options=array()){
+
+        $data = array();
+        
+        $data['user_id'] = $userId;
+        $data['group_id'] = $groupId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->userGetUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 获取用户人脸列表接口
+     *
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     * @return array
+     */
+    public function faceGetlist($userId, $groupId, $options=array()){
+
+        $data = array();
+        
+        $data['user_id'] = $userId;
+        $data['group_id'] = $groupId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->faceGetlistUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 获取用户列表接口
+     *
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   start 默认值0,起始序号
+     *   length 返回数量,默认值100,最大值1000
+     * @return array
+     */
+    public function getGroupUsers($groupId, $options=array()){
+
+        $data = array();
+        
+        $data['group_id'] = $groupId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->groupGetusersUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 复制用户接口
+     *
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   src_group_id 从指定组里复制信息
+     *   dst_group_id 需要添加用户的组id
+     * @return array
+     */
+    public function userCopy($userId, $options=array()){
+
+        $data = array();
+        
+        $data['user_id'] = $userId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->userCopyUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 删除用户接口
+     *
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param string $userId - 用户id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     * @return array
+     */
+    public function deleteUser($groupId, $userId, $options=array()){
+
+        $data = array();
+        
+        $data['group_id'] = $groupId;
+        $data['user_id'] = $userId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->userDeleteUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 创建用户组接口
+     *
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     * @return array
+     */
+    public function groupAdd($groupId, $options=array()){
+
+        $data = array();
+        
+        $data['group_id'] = $groupId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->groupAddUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 删除用户组接口
+     *
+     * @param string $groupId - 用户组id(由数字、字母、下划线组成),长度限制128B
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     * @return array
+     */
+    public function groupDelete($groupId, $options=array()){
+
+        $data = array();
+        
+        $data['group_id'] = $groupId;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->groupDeleteUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 组列表查询接口
+     *
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   start 默认值0,起始序号
+     *   length 返回数量,默认值100,最大值1000
+     * @return array
+     */
+    public function getGroupList($options=array()){
+
+        $data = array();
+        
+
+        $data = array_merge($data, $options);
+        return $this->request($this->groupGetlistUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 身份验证接口
+     *
+     * @param string $image - 图片信息(**总数据大小应小于10M**),图片上传方式根据image_type来判断
+     * @param string $imageType - 图片类型     <br> **BASE64**:图片的base64值,base64编码后的图片数据,编码后的图片大小不超过2M; <br>**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长); <br>**FACE_TOKEN**: 人脸图片的唯一标识,调用人脸检测接口时,会为每个人脸图片赋予一个唯一的FACE_TOKEN,同一张图片多次检测得到的FACE_TOKEN是同一个。
+     * @param string $idCardNumber - 身份证号(真实身份证号号码)
+     * @param string $name - utf8,姓名(真实姓名,和身份证号匹配)
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   quality_control 图片质量控制  **NONE**: 不进行控制 **LOW**:较低的质量要求 **NORMAL**: 一般的质量要求 **HIGH**: 较高的质量要求 **默认 NONE**
+     *   liveness_control 活体检测控制  **NONE**: 不进行控制 **LOW**:较低的活体要求(高通过率 低攻击拒绝率) **NORMAL**: 一般的活体要求(平衡的攻击拒绝率, 通过率) **HIGH**: 较高的活体要求(高攻击拒绝率 低通过率) **默认NONE**
+     * @return array
+     */
+    public function personVerify($image, $imageType, $idCardNumber, $name, $options=array()){
+
+        $data = array();
+        
+        $data['image'] = $image;
+        $data['image_type'] = $imageType;
+        $data['id_card_number'] = $idCardNumber;
+        $data['name'] = $name;
+
+        $data = array_merge($data, $options);
+        return $this->request($this->personVerifyUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 语音校验码接口接口
+     *
+     * @param array $options - 可选参数对象,key: value都为string类型
+     * @description options列表:
+     *   appid 百度云创建应用时的唯一标识ID
+     * @return array
+     */
+    public function videoSessioncode($options=array()){
+
+        $data = array();
+        
+
+        $data = array_merge($data, $options);
+        return $this->request($this->videoSessioncodeUrl, json_encode($data),  array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+    /**
+     * 在线活体检测 faceverify api url
+     * @var string
+     */
+    private $faceverifyUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/faceverify';
+
+    /**
+     * 在线活体检测接口
+     *
+     * @param array $images
+     * @return array
+     */
+    public function faceverify($images){
+
+        return $this->request($this->faceverifyUrl, json_encode($images), array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+    /**
+     * 人脸比对 match api url
+     * @var string
+     */
+    private $matchUrl = 'https://aip.baidubce.com/rest/2.0/face/v3/match';
+
+    /**
+     * 人脸比对接口
+     *
+     * @param array $images
+     * @return array
+     */
+    public function match($images){
+
+        return $this->request($this->matchUrl, json_encode($images), array(
+            'Content-Type' => 'application/json',
+        ));
+    }
+
+}

Plik diff jest za duży
+ 0 - 0
app/Libraries/baiduyun/lib/1b585f5dbf750c557dece959401a7b73


+ 345 - 0
app/Libraries/baiduyun/lib/AipBCEUtil.php

xqd
@@ -0,0 +1,345 @@
+<?php
+/*
+* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License. You may obtain a copy of
+* the License at
+*
+* Http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations under
+* the License.
+*/
+
+/**
+ * BCE Util
+ */
+class AipHttpUtil
+{
+    // 根据RFC 3986,除了:
+    //   1.大小写英文字符
+    //   2.阿拉伯数字
+    //   3.点'.'、波浪线'~'、减号'-'以及下划线'_'
+    // 以外都要编码
+    public static $PERCENT_ENCODED_STRINGS;
+
+    //填充编码数组
+    public static function __init()
+    {
+        AipHttpUtil::$PERCENT_ENCODED_STRINGS = array();
+        for ($i = 0; $i < 256; ++$i) {
+            AipHttpUtil::$PERCENT_ENCODED_STRINGS[$i] = sprintf("%%%02X", $i);
+        }
+
+        //a-z不编码
+        foreach (range('a', 'z') as $ch) {
+            AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($ch)] = $ch;
+        }
+
+        //A-Z不编码
+        foreach (range('A', 'Z') as $ch) {
+            AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($ch)] = $ch;
+        }
+
+        //0-9不编码
+        foreach (range('0', '9') as $ch) {
+            AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($ch)] = $ch;
+        }
+
+        //以下4个字符不编码
+        AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('-')] = '-';
+        AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('.')] = '.';
+        AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('_')] = '_';
+        AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord('~')] = '~';
+    }
+
+    /**
+     * 在uri编码中不能对'/'编码
+     * @param  string $path
+     * @return string
+     */
+    public static function urlEncodeExceptSlash($path)
+    {
+        return str_replace("%2F", "/", AipHttpUtil::urlEncode($path));
+    }
+
+    /**
+     * 使用编码数组编码
+     * @param  string $path
+     * @return string
+     */
+    public static function urlEncode($value)
+    {
+        $result = '';
+        for ($i = 0; $i < strlen($value); ++$i) {
+            $result .= AipHttpUtil::$PERCENT_ENCODED_STRINGS[ord($value[$i])];
+        }
+        return $result;
+    }
+
+    /**
+     * 生成标准化QueryString
+     * @param  array $parameters
+     * @return array
+     */
+    public static function getCanonicalQueryString(array $parameters)
+    {
+        //没有参数,直接返回空串
+        if (count($parameters) == 0) {
+            return '';
+        }
+
+        $parameterStrings = array();
+        foreach ($parameters as $k => $v) {
+            //跳过Authorization字段
+            if (strcasecmp('Authorization', $k) == 0) {
+                continue;
+            }
+            if (!isset($k)) {
+                throw new \InvalidArgumentException(
+                    "parameter key should not be null"
+                );
+            }
+            if (isset($v)) {
+                //对于有值的,编码后放在=号两边
+                $parameterStrings[] = AipHttpUtil::urlEncode($k)
+                    . '=' . AipHttpUtil::urlEncode((string) $v);
+            } else {
+                //对于没有值的,只将key编码后放在=号的左边,右边留空
+                $parameterStrings[] = AipHttpUtil::urlEncode($k) . '=';
+            }
+        }
+        //按照字典序排序
+        sort($parameterStrings);
+
+        //使用'&'符号连接它们
+        return implode('&', $parameterStrings);
+    }
+
+    /**
+     * 生成标准化uri
+     * @param  string $path
+     * @return string
+     */
+    public static function getCanonicalURIPath($path)
+    {
+        //空路径设置为'/'
+        if (empty($path)) {
+            return '/';
+        } else {
+            //所有的uri必须以'/'开头
+            if ($path[0] == '/') {
+                return AipHttpUtil::urlEncodeExceptSlash($path);
+            } else {
+                return '/' . AipHttpUtil::urlEncodeExceptSlash($path);
+            }
+        }
+    }
+
+    /**
+     * 生成标准化http请求头串
+     * @param  array $headers
+     * @return array
+     */
+    public static function getCanonicalHeaders($headers)
+    {
+        //如果没有headers,则返回空串
+        if (count($headers) == 0) {
+            return '';
+        }
+
+        $headerStrings = array();
+        foreach ($headers as $k => $v) {
+            //跳过key为null的
+            if ($k === null) {
+                continue;
+            }
+            //如果value为null,则赋值为空串
+            if ($v === null) {
+                $v = '';
+            }
+            //trim后再encode,之后使用':'号连接起来
+            $headerStrings[] = AipHttpUtil::urlEncode(strtolower(trim($k))) . ':' . AipHttpUtil::urlEncode(trim($v));
+        }
+        //字典序排序
+        sort($headerStrings);
+
+        //用'\n'把它们连接起来
+        return implode("\n", $headerStrings);
+    }
+}
+AipHttpUtil::__init();
+
+
+class AipSignOption
+{
+    const EXPIRATION_IN_SECONDS = 'expirationInSeconds';
+
+    const HEADERS_TO_SIGN = 'headersToSign';
+
+    const TIMESTAMP = 'timestamp';
+
+    const DEFAULT_EXPIRATION_IN_SECONDS = 1800;
+
+    const MIN_EXPIRATION_IN_SECONDS = 300;
+
+    const MAX_EXPIRATION_IN_SECONDS = 129600;
+}
+
+
+class AipSampleSigner
+{
+
+    const BCE_AUTH_VERSION = "bce-auth-v1";
+    const BCE_PREFIX = 'x-bce-';
+
+    //不指定headersToSign情况下,默认签名http头,包括:
+    //    1.host
+    //    2.content-length
+    //    3.content-type
+    //    4.content-md5
+    public static $defaultHeadersToSign;
+
+    public static function  __init()
+    {
+        AipSampleSigner::$defaultHeadersToSign = array(
+            "host",
+            "content-length",
+            "content-type",
+            "content-md5",
+        );
+    }
+
+    /**
+     * 签名
+     * @param  array $credentials
+     * @param  string $httpMethod
+     * @param  string $path
+     * @param  array  $headers
+     * @param  string $params
+     * @param  array  $options
+     * @return string
+     */
+    public static function sign(
+        array $credentials,
+        $httpMethod,
+        $path,
+        $headers,
+        $params,
+        $options = array()
+    ) {
+        //设定签名有效时间
+        if (!isset($options[AipSignOption::EXPIRATION_IN_SECONDS])) {
+            //默认值1800秒
+            $expirationInSeconds = AipSignOption::DEFAULT_EXPIRATION_IN_SECONDS;
+        } else {
+            $expirationInSeconds = $options[AipSignOption::EXPIRATION_IN_SECONDS];
+        }
+
+        //解析ak sk
+        $accessKeyId = $credentials['ak'];
+        $secretAccessKey = $credentials['sk'];
+
+        //设定时间戳,注意:如果自行指定时间戳需要为UTC时间
+        if (!isset($options[AipSignOption::TIMESTAMP])) {
+            //默认值当前时间
+            $timestamp = gmdate('Y-m-d\TH:i:s\Z');
+        } else {
+            $timestamp = $options[AipSignOption::TIMESTAMP];
+        }
+
+        //生成authString
+        $authString = AipSampleSigner::BCE_AUTH_VERSION . '/' . $accessKeyId . '/'
+            . $timestamp . '/' . $expirationInSeconds;
+
+        //使用sk和authString生成signKey
+        $signingKey = hash_hmac('sha256', $authString, $secretAccessKey);
+
+        //生成标准化URI
+        $canonicalURI = AipHttpUtil::getCanonicalURIPath($path);
+
+        //生成标准化QueryString
+        $canonicalQueryString = AipHttpUtil::getCanonicalQueryString($params);
+
+        //填充headersToSign,也就是指明哪些header参与签名
+        $headersToSign = null;
+        if (isset($options[AipSignOption::HEADERS_TO_SIGN])) {
+            $headersToSign = $options[AipSignOption::HEADERS_TO_SIGN];
+        }
+
+        //生成标准化header
+        $canonicalHeader = AipHttpUtil::getCanonicalHeaders(
+            AipSampleSigner::getHeadersToSign($headers, $headersToSign)
+        );
+
+        //整理headersToSign,以';'号连接
+        $signedHeaders = '';
+        if ($headersToSign !== null) {
+            $signedHeaders = strtolower(
+                trim(implode(";", $headersToSign))
+            );
+        }
+
+        //组成标准请求串
+        $canonicalRequest = "$httpMethod\n$canonicalURI\n"
+            . "$canonicalQueryString\n$canonicalHeader";
+
+        //使用signKey和标准请求串完成签名
+        $signature = hash_hmac('sha256', $canonicalRequest, $signingKey);
+
+        //组成最终签名串
+        $authorizationHeader = "$authString/$signedHeaders/$signature";
+
+        return $authorizationHeader;
+    }
+
+    /**
+     * 根据headsToSign过滤应该参与签名的header
+     * @param  array $headers
+     * @param  array $headersToSign
+     * @return array
+     */
+    public static function getHeadersToSign($headers, $headersToSign)
+    {
+
+        $arr = array();
+        foreach ($headersToSign as $value) {
+            $arr[] = strtolower(trim($value));
+        }
+
+        //value被trim后为空串的header不参与签名
+        $result = array();
+        foreach ($headers as $key => $value) {
+            if (trim($value) !== '') {
+                $key = strtolower(trim($key));
+                if (in_array($key, $arr)) {
+                    $result[$key] = $value;
+                } 
+            }
+        }
+
+        //返回需要参与签名的header
+        return $result;
+    }
+
+    /**
+     * 检查header是不是默认参加签名的:
+     * 1.是host、content-type、content-md5、content-length之一
+     * 2.以x-bce开头
+     * @param  array $header
+     * @return boolean
+     */
+    public static function isDefaultHeaderToSign($header)
+    {
+        $header = strtolower(trim($header));
+        if (in_array($header, AipSampleSigner::$defaultHeadersToSign)) {
+            return true;
+        }
+        return substr_compare($header, AipSampleSigner::BCE_PREFIX, 0, strlen(AipSampleSigner::BCE_PREFIX)) == 0;
+    }
+}
+AipSampleSigner::__init();

+ 394 - 0
app/Libraries/baiduyun/lib/AipBase.php

xqd
@@ -0,0 +1,394 @@
+<?php
+/*
+* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License. You may obtain a copy of
+* the License at
+*
+* Http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations under
+* the License.
+*/
+
+require_once 'AipHttpClient.php';
+require_once 'AipBCEUtil.php';
+
+/**
+ * Aip Base 基类
+ */
+class AipBase {
+
+    /**
+     * 获取access token url
+     * @var string
+     */
+    protected $accessTokenUrl = 'https://aip.baidubce.com/oauth/2.0/token';
+
+     /**
+     * 反馈接口
+     * @var string
+     */
+    protected $reportUrl = 'https://aip.baidubce.com/rpc/2.0/feedback/v1/report';
+
+    /**
+     * appId
+     * @var string
+     */
+    protected $appId = '';
+
+    /**
+     * apiKey
+     * @var string
+     */
+    protected $apiKey = '';
+
+    /**
+     * secretKey
+     * @var string
+     */
+    protected $secretKey = '';
+
+    /**
+     * 权限
+     * @var array
+     */
+    protected $scope = 'brain_all_scope';
+
+    /**
+     * @param string $appId
+     * @param string $apiKey
+     * @param string $secretKey
+     */
+    public function __construct($appId, $apiKey, $secretKey){
+        $this->appId = trim($appId);
+        $this->apiKey = trim($apiKey);
+        $this->secretKey = trim($secretKey);
+        $this->isCloudUser = null;
+        $this->client = new AipHttpClient();
+        $this->version = '2_2_20';
+        $this->proxies = array();
+    }
+
+    /**
+     * 查看版本
+     * @return string
+     *
+     */
+    public function getVersion(){
+        return $this->version;
+    }
+
+    /**
+     * 连接超时
+     * @param int $ms 毫秒
+     */
+    public function setConnectionTimeoutInMillis($ms){
+        $this->client->setConnectionTimeoutInMillis($ms);
+    }
+
+    /**
+     * 响应超时
+     * @param int $ms 毫秒
+     */
+    public function setSocketTimeoutInMillis($ms){
+        $this->client->setSocketTimeoutInMillis($ms);
+    }
+
+    /**
+     * 代理
+     * @param array $proxy
+     * @return string
+     *
+     */
+    public function setProxies($proxies){
+        $this->client->setConf($proxies);
+    }
+
+    /**
+     * 处理请求参数
+     * @param  string $url
+     * @param array $params
+     * @param array $data
+     * @param array $headers
+     */
+    protected function proccessRequest($url, &$params, &$data, $headers){
+        $params['aipSdk'] = 'php';
+        $params['aipSdkVersion'] = $this->version;
+    }
+
+    /**
+     * Api 请求
+     * @param  string $url
+     * @param  mixed $data
+     * @return mixed
+     */
+    protected function request($url, $data, $headers=array()){
+        try{
+            $result = $this->validate($url, $data);
+            if($result !== true){
+                return $result;
+            }
+
+            $params = array();
+            $authObj = $this->auth();
+
+            if($this->isCloudUser === false){
+                $params['access_token'] = $authObj['access_token'];
+            }
+
+            // 特殊处理
+            $this->proccessRequest($url, $params, $data, $headers);
+
+            $headers = $this->getAuthHeaders('POST', $url, $params, $headers);
+            $response = $this->client->post($url, $data, $params, $headers);
+
+            $obj = $this->proccessResult($response['content']);
+
+            if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){
+                $authObj = $this->auth(true);
+                $params['access_token'] = $authObj['access_token'];
+                $response = $this->client->post($url, $data, $params, $headers);
+                $obj = $this->proccessResult($response['content']);
+            }
+
+            if(empty($obj) || !isset($obj['error_code'])){
+                $this->writeAuthObj($authObj);
+            }
+        }catch(Exception $e){
+            return array(
+                'error_code' => 'SDK108',
+                'error_msg' => 'connection or read data timeout',
+            );
+        }
+
+        return $obj;
+    }
+
+    /**
+     * Api 多个并发请求
+     * @param  string $url
+     * @param  mixed $data
+     * @return mixed
+     */
+    protected function multi_request($url, $data){
+        try{
+            $params = array();
+            $authObj = $this->auth();
+            $headers = $this->getAuthHeaders('POST', $url);
+
+            if($this->isCloudUser === false){
+                $params['access_token'] = $authObj['access_token'];
+            }
+
+            $responses = $this->client->multi_post($url, $data, $params, $headers);
+
+            $is_success = false;
+            foreach($responses as $response){
+                $obj = $this->proccessResult($response['content']);
+
+                if(empty($obj) || !isset($obj['error_code'])){
+                    $is_success = true;
+                }
+
+                if(!$this->isCloudUser && isset($obj['error_code']) && $obj['error_code'] == 110){
+                    $authObj = $this->auth(true);
+                    $params['access_token'] = $authObj['access_token'];
+                    $responses = $this->client->post($url, $data, $params, $headers);
+                    break;
+                }
+            }
+
+            if($is_success){
+                $this->writeAuthObj($authObj);
+            }
+
+            $objs = array();
+            foreach($responses as $response){
+                $objs[] = $this->proccessResult($response['content']);
+            }
+
+        }catch(Exception $e){
+            return array(
+                'error_code' => 'SDK108',
+                'error_msg' => 'connection or read data timeout',
+            );
+        }
+
+        return $objs;
+    }
+
+    /**
+     * 格式检查
+     * @param  string $url
+     * @param  array $data
+     * @return mix
+     */
+    protected function validate($url, &$data){
+        return true;
+    }
+
+    /**
+     * 格式化结果
+     * @param $content string
+     * @return mixed
+     */
+    protected function proccessResult($content){
+        return json_decode($content, true);
+    }
+
+    /**
+     * 返回 access token 路径
+     * @return string
+     */
+    private function getAuthFilePath(){
+        return dirname(__FILE__) . DIRECTORY_SEPARATOR . md5($this->apiKey);
+    }
+
+    /**
+     * 写入本地文件
+     * @param  array $obj
+     * @return void
+     */
+    private function writeAuthObj($obj){
+        if($obj === null || (isset($obj['is_read']) && $obj['is_read'] === true)){
+            return;
+        }
+
+        $obj['time'] = time();
+        $obj['is_cloud_user'] = $this->isCloudUser;
+        @file_put_contents($this->getAuthFilePath(), json_encode($obj));
+    }
+
+    /**
+     * 读取本地缓存
+     * @return array
+     */
+    private function readAuthObj(){
+        $content = @file_get_contents($this->getAuthFilePath());
+        if($content !== false){
+            $obj = json_decode($content, true);
+            $this->isCloudUser = $obj['is_cloud_user'];
+            $obj['is_read'] = true;
+            if($this->isCloudUser || $obj['time'] + $obj['expires_in'] - 30 > time()){
+                return $obj;
+            }
+        }
+
+        return null;
+    }
+
+    /**
+     * 认证
+     * @param bool $refresh 是否刷新
+     * @return array
+     */
+    private function auth($refresh=false){
+
+        //非过期刷新
+        if(!$refresh){
+            $obj = $this->readAuthObj();
+            if(!empty($obj)){
+                return $obj;
+            }
+        }
+
+        $response = $this->client->get($this->accessTokenUrl, array(
+            'grant_type' => 'client_credentials',
+            'client_id' => $this->apiKey,
+            'client_secret' => $this->secretKey,
+        ));
+
+        $obj = json_decode($response['content'], true);
+
+        $this->isCloudUser = !$this->isPermission($obj);
+        return $obj;
+    }
+
+    /**
+     * 判断认证是否有权限
+     * @param  array   $authObj
+     * @return boolean
+     */
+    protected function isPermission($authObj)
+    {
+        if(empty($authObj) || !isset($authObj['scope'])){
+            return false;
+        }
+
+        $scopes = explode(' ', $authObj['scope']);
+
+        return in_array($this->scope, $scopes);
+    }
+
+    /**
+     * @param  string $method HTTP method
+     * @param  string $url
+     * @param  array $param 参数
+     * @return array
+     */
+    private function getAuthHeaders($method, $url, $params=array(), $headers=array()){
+
+        //不是云的老用户则不用在header中签名 认证
+        if($this->isCloudUser === false){
+            return $headers;
+        }
+
+        $obj = parse_url($url);
+        if(!empty($obj['query'])){
+            foreach(explode('&', $obj['query']) as $kv){
+                if(!empty($kv)){
+                    list($k, $v) = explode('=', $kv, 2);
+                    $params[$k] = $v;
+                }
+            }
+        }
+
+        //UTC 时间戳
+        $timestamp = gmdate('Y-m-d\TH:i:s\Z');
+        $headers['Host'] = isset($obj['port']) ? sprintf('%s:%s', $obj['host'], $obj['port']) : $obj['host'];
+        $headers['x-bce-date'] = $timestamp;
+
+        //签名
+        $headers['authorization'] = AipSampleSigner::sign(array(
+            'ak' => $this->apiKey,
+            'sk' => $this->secretKey,
+        ), $method, $obj['path'], $headers, $params, array(
+            'timestamp' => $timestamp,
+            'headersToSign' => array_keys($headers),
+        ));
+
+        return $headers;
+    }
+
+    /**
+     * 反馈
+     *
+     * @param array $feedbacks
+     * @return array
+     */
+    public function report($feedback){
+
+        $data = array();
+
+        $data['feedback'] = $feedback;
+
+        return $this->request($this->reportUrl, $data);
+    }
+
+    /**
+     * 通用接口
+     * @param string $url
+     * @param array $data
+     * @param array header
+     * @return array
+     */
+    public function post($url, $data, $headers=array()){
+        return $this->request($url, $data, $headers);
+    }
+
+}

+ 214 - 0
app/Libraries/baiduyun/lib/AipHttpClient.php

xqd
@@ -0,0 +1,214 @@
+<?php
+/*
+* Copyright (c) 2017 Baidu.com, Inc. All Rights Reserved
+*
+* Licensed under the Apache License, Version 2.0 (the "License"); you may not
+* use this file except in compliance with the License. You may obtain a copy of
+* the License at
+*
+* Http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+* License for the specific language governing permissions and limitations under
+* the License.
+*/
+
+/**
+ * Http Client
+ */
+class AipHttpClient{
+
+    /**
+     * HttpClient
+     * @param array $headers HTTP header
+     */
+    public function __construct($headers=array()){
+        $this->headers = $this->buildHeaders($headers);
+        $this->connectTimeout = 60000;
+        $this->socketTimeout = 60000;
+        $this->conf = array();
+    }
+
+    /**
+     * 连接超时
+     * @param int $ms 毫秒
+     */
+    public function setConnectionTimeoutInMillis($ms){
+        $this->connectTimeout = $ms;
+    }
+
+    /**
+     * 响应超时
+     * @param int $ms 毫秒
+     */
+    public function setSocketTimeoutInMillis($ms){
+        $this->socketTimeout = $ms;
+    }    
+
+    /**
+     * 配置
+     * @param array $conf
+     */
+    public function setConf($conf){
+        $this->conf = $conf;
+    }
+
+    /**
+     * 请求预处理
+     * @param resource $ch
+     */
+    public function prepare($ch){
+        foreach($this->conf as $key => $value){
+            curl_setopt($ch, $key, $value);
+        }
+    }    
+
+    /**
+     * @param  string $url
+     * @param  array $data HTTP POST BODY
+     * @param  array $param HTTP URL
+     * @param  array $headers HTTP header
+     * @return array
+     */
+    public function post($url, $data=array(), $params=array(), $headers=array()){
+        $url = $this->buildUrl($url, $params);
+        $headers = array_merge($this->headers, $this->buildHeaders($headers));
+
+        $ch = curl_init();
+        $this->prepare($ch);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_POST, 1);
+        curl_setopt($ch, CURLOPT_HEADER, false);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? http_build_query($data) : $data);
+        curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout);
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout);
+        $content = curl_exec($ch);
+        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+        if($code === 0){
+            throw new Exception(curl_error($ch));
+        }
+
+        curl_close($ch);
+        return array(
+            'code' => $code,
+            'content' => $content,
+        );
+    }
+
+    /**
+     * @param  string $url
+     * @param  array $datas HTTP POST BODY
+     * @param  array $param HTTP URL
+     * @param  array $headers HTTP header
+     * @return array
+     */
+    public function multi_post($url, $datas=array(), $params=array(), $headers=array()){
+        $url = $this->buildUrl($url, $params);
+        $headers = array_merge($this->headers, $this->buildHeaders($headers));
+
+        $chs = array();
+        $result = array();
+        $mh = curl_multi_init();
+        foreach($datas as $data){        
+            $ch = curl_init();
+            $chs[] = $ch;
+            $this->prepare($ch);
+            curl_setopt($ch, CURLOPT_URL, $url);
+            curl_setopt($ch, CURLOPT_POST, 1);
+            curl_setopt($ch, CURLOPT_HEADER, false);
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+            curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+            curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+            curl_setopt($ch, CURLOPT_POSTFIELDS, is_array($data) ? http_build_query($data) : $data);
+            curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout);
+            curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout);
+            curl_multi_add_handle($mh, $ch);
+        }
+
+        $running = null;
+        do{
+            curl_multi_exec($mh, $running);
+            usleep(100);
+        }while($running);
+
+        foreach($chs as $ch){        
+            $content = curl_multi_getcontent($ch);
+            $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+            $result[] = array(
+                'code' => $code,
+                'content' => $content,
+            );
+            curl_multi_remove_handle($mh, $ch);
+        }
+        curl_multi_close($mh);
+        
+        return $result;
+    }
+
+    /**
+     * @param  string $url
+     * @param  array $param HTTP URL
+     * @param  array $headers HTTP header
+     * @return array
+     */
+    public function get($url, $params=array(), $headers=array()){
+        $url = $this->buildUrl($url, $params);
+        $headers = array_merge($this->headers, $this->buildHeaders($headers));
+
+        $ch = curl_init();
+        $this->prepare($ch);
+        curl_setopt($ch, CURLOPT_URL, $url);
+        curl_setopt($ch, CURLOPT_HEADER, false);
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
+        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
+        curl_setopt($ch, CURLOPT_TIMEOUT_MS, $this->socketTimeout);
+        curl_setopt($ch, CURLOPT_CONNECTTIMEOUT_MS, $this->connectTimeout);
+        $content = curl_exec($ch);
+        $code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
+
+        if($code === 0){
+            throw new Exception(curl_error($ch));
+        }
+        
+        curl_close($ch);
+        return array(
+            'code' => $code,
+            'content' => $content,
+        );
+    }
+
+    /**
+     * 构造 header
+     * @param  array $headers
+     * @return array
+     */
+    private function buildHeaders($headers){
+        $result = array();
+        foreach($headers as $k => $v){
+            $result[] = sprintf('%s:%s', $k, $v);
+        }
+        return $result;
+    }
+
+    /**
+     * 
+     * @param  string $url
+     * @param  array $params 参数
+     * @return string
+     */
+    private function buildUrl($url, $params){
+        if(!empty($params)){
+            $str = http_build_query($params);
+            return $url . (strpos($url, '?') === false ? '?' : '&') . $str;
+        }else{
+            return $url;
+        }
+    }
+}

+ 1 - 0
app/Libraries/baiduyun/lib/ce806917ed5a9613d4ca1507ec25c343

xqd
@@ -0,0 +1 @@
+{"error_description":"unknown client id","error":"invalid_client","time":1605068523,"is_cloud_user":true}

+ 3 - 0
composer.json

xqd
@@ -33,6 +33,9 @@
         "phpunit/phpunit": "^9.3.3"
     },
     "autoload": {
+        "classmap": [
+            "app/Libraries/baiduyun"
+        ],
         "files": [
             "app/Helper/function.php"
         ],

Niektóre pliki nie zostały wyświetlone z powodu dużej ilości zmienionych plików