first commit
This commit is contained in:
1
金壶/ydyd_service/extend/BaiduOcr/.pydio
Normal file
1
金壶/ydyd_service/extend/BaiduOcr/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
d35f126a-3a1f-46c0-9323-0ad130651687
|
||||
208
金壶/ydyd_service/extend/BaiduOcr/AipBodyAnalysis.php
Normal file
208
金壶/ydyd_service/extend/BaiduOcr/AipBodyAnalysis.php
Normal file
@@ -0,0 +1,208 @@
|
||||
<?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 AipBodyAnalysis extends AipBase {
|
||||
|
||||
/**
|
||||
* 人体关键点识别 body_analysis api url
|
||||
* @var string
|
||||
*/
|
||||
private $bodyAnalysisUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_analysis';
|
||||
|
||||
/**
|
||||
* 人体检测与属性识别 body_attr api url
|
||||
* @var string
|
||||
*/
|
||||
private $bodyAttrUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_attr';
|
||||
|
||||
/**
|
||||
* 人流量统计 body_num api url
|
||||
* @var string
|
||||
*/
|
||||
private $bodyNumUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_num';
|
||||
|
||||
/**
|
||||
* 手势识别 gesture api url
|
||||
* @var string
|
||||
*/
|
||||
private $gestureUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/gesture';
|
||||
|
||||
/**
|
||||
* 人像分割 body_seg api url
|
||||
* @var string
|
||||
*/
|
||||
private $bodySegUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_seg';
|
||||
|
||||
/**
|
||||
* 驾驶行为分析 driver_behavior api url
|
||||
* @var string
|
||||
*/
|
||||
private $driverBehaviorUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/driver_behavior';
|
||||
|
||||
/**
|
||||
* 人流量统计-动态版 body_tracking api url
|
||||
* @var string
|
||||
*/
|
||||
private $bodyTrackingUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/body_tracking';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 人体关键点识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function bodyAnalysis($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->bodyAnalysisUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 人体检测与属性识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* type gender,<br>age,<br>lower_wear,<br>upper_wear,<br>headwear,<br>glasses,<br>upper_color,<br>lower_color,<br>cellphone,<br>upper_wear_fg,<br>upper_wear_texture,<br>lower_wear_texture,<br>orientation,<br>umbrella,<br>bag,<br>smoke,<br>vehicle,<br>carrying_item,<br>upper_cut,<br>lower_cut,<br>occlusion | 1)可选值说明:<br>gender-性别,<br>age-年龄阶段,<br>lower_wear-下身服饰,<br>upper_wear-上身服饰,<br>headwear-是否戴帽子,<br>glasses-是否戴眼镜,<br>upper_color-上身服饰颜色,<br>lower_color-下身服饰颜色,<br>cellphone-是否使用手机,<br>upper_wear_fg-上身服饰细分类,<br>upper_wear_texture-上身服饰纹理,<br>orientation-身体朝向,<br>umbrella-是否撑伞;<br>bag-背包,<br>smoke-是否吸烟,<br>vehicle-交通工具,<br>carrying_item-是否有手提物,<br>upper_cut-上方截断,<br>lower_cut-下方截断,<br>occlusion-遮挡<br>2)type 参数值可以是可选值的组合,用逗号分隔;**如果无此参数默认输出全部20个属性**
|
||||
* @return array
|
||||
*/
|
||||
public function bodyAttr($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->bodyAttrUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 人流量统计接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* area 特定框选区域坐标,逗号分隔,如‘x1,y1,x2,y2,x3,y3...xn,yn',默认尾点和首点相连做闭合,**此参数为空或无此参数默认识别整个图片的人数**
|
||||
* show 是否输出渲染的图片,默认不返回,**选true时返回渲染后的图片(base64)**,其它无效值或为空则默认false
|
||||
* @return array
|
||||
*/
|
||||
public function bodyNum($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->bodyNumUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 手势识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function gesture($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->gestureUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 人像分割接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* type 可以通过设置type参数,自主设置返回哪些结果图,避免造成带宽的浪费<br>1)可选值说明:<br>labelmap - 二值图像,需二次处理方能查看分割效果<br>scoremap - 人像前景灰度图<br>foreground - 人像前景抠图,透明背景<br>2)type 参数值可以是可选值的组合,用逗号分隔;如果无此参数默认输出全部3类结果图
|
||||
* @return array
|
||||
*/
|
||||
public function bodySeg($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->bodySegUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 驾驶行为分析接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* type smoke,cellphone,<br>not_buckling_up,<br>both_hands_leaving_wheel,<br>not_facing_front |识别的属性行为类别,英文逗号分隔,默认所有属性都识别;<br>smoke //吸烟,<br>cellphone //打手机 ,<br>not_buckling_up // 未系安全带,<br>both_hands_leaving_wheel // 双手离开方向盘,<br>not_facing_front // 视角未看前方
|
||||
* @return array
|
||||
*/
|
||||
public function driverBehavior($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->driverBehaviorUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 人流量统计-动态版接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param string $dynamic - true:动态人流量统计,返回总人数、跟踪ID、区域进出人数;<br>false:静态人数统计,返回总人数
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* case_id 任务ID(通过case_id区分不同视频流,自拟,不同序列间不可重复即可)
|
||||
* case_init 每个case的初始化信号,为true时对该case下的跟踪算法进行初始化,为false时重载该case的跟踪状态。当为false且读取不到相应case的信息时,直接重新初始化
|
||||
* show 否返回结果图(含统计值和跟踪框渲染),默认不返回,选true时返回渲染后的图片(base64),其它无效值或为空则默认false
|
||||
* area 静态人数统计时,只统计区域内的人,缺省时为全图统计。<br>动态人流量统计时,进出区域的人流会被统计。<br>逗号分隔,如‘x1,y1,x2,y2,x3,y3...xn,yn',按顺序依次给出每个顶点的xy坐标(默认尾点和首点相连),形成闭合多边形区域。<br>服务会做范围(顶点左边需在图像范围内)及个数校验(数组长度必须为偶数,且大于3个顶点)。只支持单个多边形区域,建议设置矩形框,即4个顶点。**坐标取值不能超过图像宽度和高度,比如1280的宽度,坐标值最小建议从1开始,最大到1279**。
|
||||
* @return array
|
||||
*/
|
||||
public function bodyTracking($image, $dynamic, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
$data['dynamic'] = $dynamic;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->bodyTrackingUrl, $data);
|
||||
}
|
||||
}
|
||||
25
金壶/ydyd_service/extend/BaiduOcr/AipContentCensor.php
Normal file
25
金壶/ydyd_service/extend/BaiduOcr/AipContentCensor.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?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 'AipImageCensor.php';
|
||||
|
||||
/**
|
||||
* 内容审核
|
||||
*/
|
||||
class AipContentCensor extends AipImageCensor{
|
||||
|
||||
}
|
||||
544
金壶/ydyd_service/extend/BaiduOcr/AipFace.php
Normal file
544
金壶/ydyd_service/extend/BaiduOcr/AipFace.php
Normal file
@@ -0,0 +1,544 @@
|
||||
<?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 - 图片类型 **BASE64**:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**;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 - 图片类型 **BASE64**:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**;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 - 图片类型 **BASE64**:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**;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 - 图片类型 **BASE64**:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**;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 - 图片类型 **BASE64**:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**;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 - 图片类型 **BASE64**:图片的base64值,base64编码后的图片数据,需urlencode,编码后的图片大小不超过2M;**URL**:图片的 URL地址( 可能由于网络等原因导致下载图片时间过长)**;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',
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
211
金壶/ydyd_service/extend/BaiduOcr/AipImageCensor.php
Normal file
211
金壶/ydyd_service/extend/BaiduOcr/AipImageCensor.php
Normal file
@@ -0,0 +1,211 @@
|
||||
<?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 AipImageCensor extends AipBase{
|
||||
|
||||
/**
|
||||
* antiporn api url
|
||||
* @var string
|
||||
*/
|
||||
private $antiPornUrl = 'https://aip.baidubce.com/rest/2.0/antiporn/v1/detect';
|
||||
|
||||
/**
|
||||
* antiporn gif api url
|
||||
* @var string
|
||||
*/
|
||||
private $antiPornGifUrl = 'https://aip.baidubce.com/rest/2.0/antiporn/v1/detect_gif';
|
||||
|
||||
/**
|
||||
* antiterror api url
|
||||
* @var string
|
||||
*/
|
||||
private $antiTerrorUrl = 'https://aip.baidubce.com/rest/2.0/antiterror/v1/detect';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $faceAuditUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/face_audit';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $imageCensorCombUrl = 'https://aip.baidubce.com/api/v1/solution/direct/img_censor';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $imageCensorUserDefinedUrl = 'https://aip.baidubce.com/rest/2.0/solution/v1/img_censor/user_defined';
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $antiSpamUrl = 'https://aip.baidubce.com/rest/2.0/antispam/v2/spam';
|
||||
|
||||
/**
|
||||
* @param string $image 图像读取
|
||||
* @return array
|
||||
*/
|
||||
public function antiPorn($image){
|
||||
|
||||
$data = array();
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
return $this->request($this->antiPornUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $image 图像读取
|
||||
* @return array
|
||||
*/
|
||||
public function multi_antiporn($images){
|
||||
|
||||
$data = array();
|
||||
foreach($images as $image){
|
||||
$data[] = array(
|
||||
'image' => base64_encode($image),
|
||||
);
|
||||
}
|
||||
|
||||
return $this->multi_request($this->antiPornUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $image 图像读取
|
||||
* @return array
|
||||
*/
|
||||
public function antiPornGif($image){
|
||||
|
||||
$data = array();
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
return $this->request($this->antiPornGifUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $image 图像读取
|
||||
* @return array
|
||||
*/
|
||||
public function antiTerror($image){
|
||||
|
||||
$data = array();
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
return $this->request($this->antiTerrorUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $images 图像读取
|
||||
* @return array
|
||||
*/
|
||||
public function faceAudit($images, $configId=''){
|
||||
|
||||
// 非数组则处理为数组
|
||||
if(!is_array($images)){
|
||||
$images = array(
|
||||
$images,
|
||||
);
|
||||
}
|
||||
|
||||
$data = array(
|
||||
'configId' => $configId,
|
||||
);
|
||||
|
||||
$isUrl = substr(trim($images[0]), 0, 4) === 'http';
|
||||
if(!$isUrl){
|
||||
$arr = array();
|
||||
|
||||
foreach($images as $image){
|
||||
$arr[] = base64_encode($image);
|
||||
}
|
||||
$data['images'] = implode(',', $arr);
|
||||
}else{
|
||||
$urls = array();
|
||||
|
||||
foreach($images as $url){
|
||||
$urls[] = urlencode($url);
|
||||
}
|
||||
|
||||
$data['imgUrls'] = implode(',', $urls);
|
||||
}
|
||||
|
||||
return $this->request($this->faceAuditUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $image 图像读取
|
||||
* @return array
|
||||
*/
|
||||
public function imageCensorComb($image, $scenes='antiporn', $options=array()){
|
||||
|
||||
$scenes = !is_array($scenes) ? explode(',', $scenes) : $scenes;
|
||||
|
||||
$data = array(
|
||||
'scenes' => $scenes,
|
||||
);
|
||||
|
||||
$isUrl = substr(trim($image), 0, 4) === 'http';
|
||||
if(!$isUrl){
|
||||
$data['image'] = base64_encode($image);
|
||||
}else{
|
||||
$data['imgUrl'] = $image;
|
||||
}
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->imageCensorCombUrl, json_encode($data), array(
|
||||
'Content-Type' => 'application/json',
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $image 图像
|
||||
* @return array
|
||||
*/
|
||||
public function imageCensorUserDefined($image){
|
||||
|
||||
$data = array();
|
||||
|
||||
$isUrl = substr(trim($image), 0, 4) === 'http';
|
||||
if(!$isUrl){
|
||||
$data['image'] = base64_encode($image);
|
||||
}else{
|
||||
$data['imgUrl'] = $image;
|
||||
}
|
||||
|
||||
return $this->request($this->imageCensorUserDefinedUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $content
|
||||
* @return array
|
||||
*/
|
||||
public function antiSpam($content, $options=array()){
|
||||
|
||||
$data = array();
|
||||
$data['content'] = $content;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->antiSpamUrl, $data);
|
||||
}
|
||||
|
||||
}
|
||||
304
金壶/ydyd_service/extend/BaiduOcr/AipImageClassify.php
Normal file
304
金壶/ydyd_service/extend/BaiduOcr/AipImageClassify.php
Normal file
@@ -0,0 +1,304 @@
|
||||
<?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 AipImageClassify extends AipBase {
|
||||
|
||||
/**
|
||||
* 通用物体识别 advanced_general api url
|
||||
* @var string
|
||||
*/
|
||||
private $advancedGeneralUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/advanced_general';
|
||||
|
||||
/**
|
||||
* 菜品识别 dish_detect api url
|
||||
* @var string
|
||||
*/
|
||||
private $dishDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/dish';
|
||||
|
||||
/**
|
||||
* 车辆识别 car_detect api url
|
||||
* @var string
|
||||
*/
|
||||
private $carDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/car';
|
||||
|
||||
/**
|
||||
* logo商标识别 logo_search api url
|
||||
* @var string
|
||||
*/
|
||||
private $logoSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v2/logo';
|
||||
|
||||
/**
|
||||
* logo商标识别—添加 logo_add api url
|
||||
* @var string
|
||||
*/
|
||||
private $logoAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/add';
|
||||
|
||||
/**
|
||||
* logo商标识别—删除 logo_delete api url
|
||||
* @var string
|
||||
*/
|
||||
private $logoDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/v1/logo/delete';
|
||||
|
||||
/**
|
||||
* 动物识别 animal_detect api url
|
||||
* @var string
|
||||
*/
|
||||
private $animalDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/animal';
|
||||
|
||||
/**
|
||||
* 植物识别 plant_detect api url
|
||||
* @var string
|
||||
*/
|
||||
private $plantDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/plant';
|
||||
|
||||
/**
|
||||
* 图像主体检测 object_detect api url
|
||||
* @var string
|
||||
*/
|
||||
private $objectDetectUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/object_detect';
|
||||
|
||||
/**
|
||||
* 地标识别 landmark api url
|
||||
* @var string
|
||||
*/
|
||||
private $landmarkUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/landmark';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 通用物体识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* baike_num 返回百科信息的结果数,默认不返回
|
||||
* @return array
|
||||
*/
|
||||
public function advancedGeneral($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->advancedGeneralUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 菜品识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* top_num 返回预测得分top结果数,默认为5
|
||||
* filter_threshold 默认0.95,可以通过该参数调节识别效果,降低非菜识别率.
|
||||
* baike_num 返回百科信息的结果数,默认不返回
|
||||
* @return array
|
||||
*/
|
||||
public function dishDetect($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->dishDetectUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 车辆识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* top_num 返回预测得分top结果数,默认为5
|
||||
* baike_num 返回百科信息的结果数,默认不返回
|
||||
* @return array
|
||||
*/
|
||||
public function carDetect($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->carDetectUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* logo商标识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* custom_lib 是否只使用自定义logo库的结果,默认false:返回自定义库+默认库的识别结果
|
||||
* @return array
|
||||
*/
|
||||
public function logoSearch($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->logoSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* logo商标识别—添加接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param string $brief - brief,检索时带回。此处要传对应的name与code字段,name长度小于100B,code长度小于150B
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function logoAdd($image, $brief, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
$data['brief'] = $brief;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->logoAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* logo商标识别—删除接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function logoDeleteByImage($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->logoDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* logo商标识别—删除接口
|
||||
*
|
||||
* @param string $contSign - 图片签名(和image二选一,image优先级更高)
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function logoDeleteBySign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->logoDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 动物识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* top_num 返回预测得分top结果数,默认为6
|
||||
* baike_num 返回百科信息的结果数,默认不返回
|
||||
* @return array
|
||||
*/
|
||||
public function animalDetect($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->animalDetectUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 植物识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* baike_num 返回百科信息的结果数,默认不返回
|
||||
* @return array
|
||||
*/
|
||||
public function plantDetect($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->plantDetectUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图像主体检测接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* with_face 如果检测主体是人,主体区域是否带上人脸部分,0-不带人脸区域,其他-带人脸区域,裁剪类需求推荐带人脸,检索/识别类需求推荐不带人脸。默认取1,带人脸。
|
||||
* @return array
|
||||
*/
|
||||
public function objectDetect($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->objectDetectUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 地标识别接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function landmark($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->landmarkUrl, $data);
|
||||
}
|
||||
}
|
||||
97
金壶/ydyd_service/extend/BaiduOcr/AipImageProcess.php
Normal file
97
金壶/ydyd_service/extend/BaiduOcr/AipImageProcess.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?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 AipImageProcess extends AipBase {
|
||||
|
||||
/**
|
||||
* 图像无损放大 image_quality_enhance api url
|
||||
* @var string
|
||||
*/
|
||||
private $imageQualityEnhanceUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/image_quality_enhance';
|
||||
|
||||
/**
|
||||
* 图像去雾 dehaze api url
|
||||
* @var string
|
||||
*/
|
||||
private $dehazeUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/dehaze';
|
||||
|
||||
/**
|
||||
* 图像对比度增强 contrast_enhance api url
|
||||
* @var string
|
||||
*/
|
||||
private $contrastEnhanceUrl = 'https://aip.baidubce.com/rest/2.0/image-process/v1/contrast_enhance';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 图像无损放大接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function imageQualityEnhance($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->imageQualityEnhanceUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图像去雾接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function dehaze($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->dehazeUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 图像对比度增强接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function contrastEnhance($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->contrastEnhanceUrl, $data);
|
||||
}
|
||||
}
|
||||
724
金壶/ydyd_service/extend/BaiduOcr/AipImageSearch.php
Normal file
724
金壶/ydyd_service/extend/BaiduOcr/AipImageSearch.php
Normal file
@@ -0,0 +1,724 @@
|
||||
<?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 AipImageSearch extends AipBase {
|
||||
|
||||
/**
|
||||
* 相同图检索—入库 same_hq_add api url
|
||||
* @var string
|
||||
*/
|
||||
private $sameHqAddUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/add';
|
||||
|
||||
/**
|
||||
* 相同图检索—检索 same_hq_search api url
|
||||
* @var string
|
||||
*/
|
||||
private $sameHqSearchUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/search';
|
||||
|
||||
/**
|
||||
* 相同图检索—更新 same_hq_update api url
|
||||
* @var string
|
||||
*/
|
||||
private $sameHqUpdateUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/update';
|
||||
|
||||
/**
|
||||
* 相同图检索—删除 same_hq_delete api url
|
||||
* @var string
|
||||
*/
|
||||
private $sameHqDeleteUrl = 'https://aip.baidubce.com/rest/2.0/realtime_search/same_hq/delete';
|
||||
|
||||
/**
|
||||
* 相似图检索—入库 similar_add api url
|
||||
* @var string
|
||||
*/
|
||||
private $similarAddUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/add';
|
||||
|
||||
/**
|
||||
* 相似图检索—检索 similar_search api url
|
||||
* @var string
|
||||
*/
|
||||
private $similarSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/search';
|
||||
|
||||
/**
|
||||
* 相似图检索—更新 similar_update api url
|
||||
* @var string
|
||||
*/
|
||||
private $similarUpdateUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/update';
|
||||
|
||||
/**
|
||||
* 相似图检索—删除 similar_delete api url
|
||||
* @var string
|
||||
*/
|
||||
private $similarDeleteUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/similar/delete';
|
||||
|
||||
/**
|
||||
* 商品检索—入库 product_add api url
|
||||
* @var string
|
||||
*/
|
||||
private $productAddUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/add';
|
||||
|
||||
/**
|
||||
* 商品检索—检索 product_search api url
|
||||
* @var string
|
||||
*/
|
||||
private $productSearchUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/search';
|
||||
|
||||
/**
|
||||
* 商品检索—更新 product_update api url
|
||||
* @var string
|
||||
*/
|
||||
private $productUpdateUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/update';
|
||||
|
||||
/**
|
||||
* 商品检索—删除 product_delete api url
|
||||
* @var string
|
||||
*/
|
||||
private $productDeleteUrl = 'https://aip.baidubce.com/rest/2.0/image-classify/v1/realtime_search/product/delete';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 相同图检索—入库接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 检索时原样带回,最长256B。
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqAdd($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—入库接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 检索时原样带回,最长256B。
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqAddUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—检索接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* tag_logic 检索时tag之间的逻辑, 0:逻辑and,1:逻辑or
|
||||
* pn 分页功能,起始位置,例:0。未指定分页时,默认返回前300个结果;接口返回数量最大限制1000条,例如:起始位置为900,截取条数500条,接口也只返回第900 - 1000条的结果,共计100条
|
||||
* rn 分页功能,截取条数,例:250
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqSearch($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—检索接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* tag_logic 检索时tag之间的逻辑, 0:逻辑and,1:逻辑or
|
||||
* pn 分页功能,起始位置,例:0。未指定分页时,默认返回前300个结果;接口返回数量最大限制1000条,例如:起始位置为900,截取条数500条,接口也只返回第900 - 1000条的结果,共计100条
|
||||
* rn 分页功能,截取条数,例:250
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqSearchUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—更新接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqUpdate($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—更新接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqUpdateUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—更新接口
|
||||
*
|
||||
* @param string $contSign - 图片签名
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqUpdateContSign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—删除接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqDeleteByImage($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—删除接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqDeleteByUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相同图检索—删除接口
|
||||
*
|
||||
* @param string $contSign - 图片签名
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function sameHqDeleteBySign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->sameHqDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—入库接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 检索时原样带回,最长256B。
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function similarAdd($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—入库接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 检索时原样带回,最长256B。
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function similarAddUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—检索接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* tag_logic 检索时tag之间的逻辑, 0:逻辑and,1:逻辑or
|
||||
* pn 分页功能,起始位置,例:0。未指定分页时,默认返回前300个结果;接口返回数量最大限制1000条,例如:起始位置为900,截取条数500条,接口也只返回第900 - 1000条的结果,共计100条
|
||||
* rn 分页功能,截取条数,例:250
|
||||
* @return array
|
||||
*/
|
||||
public function similarSearch($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—检索接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* tag_logic 检索时tag之间的逻辑, 0:逻辑and,1:逻辑or
|
||||
* pn 分页功能,起始位置,例:0。未指定分页时,默认返回前300个结果;接口返回数量最大限制1000条,例如:起始位置为900,截取条数500条,接口也只返回第900 - 1000条的结果,共计100条
|
||||
* rn 分页功能,截取条数,例:250
|
||||
* @return array
|
||||
*/
|
||||
public function similarSearchUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—更新接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function similarUpdate($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—更新接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function similarUpdateUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—更新接口
|
||||
*
|
||||
* @param string $contSign - 图片签名
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* tags 1 - 65535范围内的整数,tag间以逗号分隔,最多2个tag。样例:"100,11" ;检索时可圈定分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function similarUpdateContSign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—删除接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function similarDeleteByImage($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—删除接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function similarDeleteByUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 相似图检索—删除接口
|
||||
*
|
||||
* @param string $contSign - 图片签名
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function similarDeleteBySign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->similarDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—入库接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 检索时原样带回,最长256B。**请注意,检索接口不返回原图,仅反馈当前填写的brief信息,所以调用该入库接口时,brief信息请尽量填写可关联至本地图库的图片id或者图片url、图片名称等信息**
|
||||
* class_id1 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* class_id2 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function productAdd($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—入库接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 检索时原样带回,最长256B。**请注意,检索接口不返回原图,仅反馈当前填写的brief信息,所以调用该入库接口时,brief信息请尽量填写可关联至本地图库的图片id或者图片url、图片名称等信息**
|
||||
* class_id1 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* class_id2 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* @return array
|
||||
*/
|
||||
public function productAddUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productAddUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—检索接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* class_id1 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* class_id2 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* pn 分页功能,起始位置,例:0。未指定分页时,默认返回前300个结果;接口返回数量最大限制1000条,例如:起始位置为900,截取条数500条,接口也只返回第900 - 1000条的结果,共计100条
|
||||
* rn 分页功能,截取条数,例:250
|
||||
* @return array
|
||||
*/
|
||||
public function productSearch($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—检索接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* class_id1 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* class_id2 商品分类维度1,支持1-60范围内的整数。检索时可圈定该分类维度进行检索
|
||||
* pn 分页功能,起始位置,例:0。未指定分页时,默认返回前300个结果;接口返回数量最大限制1000条,例如:起始位置为900,截取条数500条,接口也只返回第900 - 1000条的结果,共计100条
|
||||
* rn 分页功能,截取条数,例:250
|
||||
* @return array
|
||||
*/
|
||||
public function productSearchUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productSearchUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—更新接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* class_id1 更新的商品分类1,支持1-60范围内的整数。
|
||||
* class_id2 更新的商品分类2,支持1-60范围内的整数。
|
||||
* @return array
|
||||
*/
|
||||
public function productUpdate($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—更新接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* class_id1 更新的商品分类1,支持1-60范围内的整数。
|
||||
* class_id2 更新的商品分类2,支持1-60范围内的整数。
|
||||
* @return array
|
||||
*/
|
||||
public function productUpdateUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—更新接口
|
||||
*
|
||||
* @param string $contSign - 图片签名
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* brief 更新的摘要信息,最长256B。样例:{"name":"周杰伦", "id":"666"}
|
||||
* class_id1 更新的商品分类1,支持1-60范围内的整数。
|
||||
* class_id2 更新的商品分类2,支持1-60范围内的整数。
|
||||
* @return array
|
||||
*/
|
||||
public function productUpdateContSign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productUpdateUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—删除接口
|
||||
*
|
||||
* @param string $image - 图像数据,base64编码,要求base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function productDeleteByImage($image, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['image'] = base64_encode($image);
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—删除接口
|
||||
*
|
||||
* @param string $url - 图片完整URL,URL长度不超过1024字节,URL对应的图片base64编码后大小不超过4M,最短边至少15px,最长边最大4096px,支持jpg/png/bmp格式,当image字段存在时url字段失效
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function productDeleteByUrl($url, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['url'] = $url;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productDeleteUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 商品检索—删除接口
|
||||
*
|
||||
* @param string $contSign - 图片签名
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function productDeleteBySign($contSign, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['cont_sign'] = $contSign;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->productDeleteUrl, $data);
|
||||
}
|
||||
}
|
||||
|
||||
189
金壶/ydyd_service/extend/BaiduOcr/AipKg.php
Normal file
189
金壶/ydyd_service/extend/BaiduOcr/AipKg.php
Normal file
@@ -0,0 +1,189 @@
|
||||
<?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 AipKg extends AipBase {
|
||||
|
||||
/**
|
||||
* 创建任务 create_task api url
|
||||
* @var string
|
||||
*/
|
||||
private $createTaskUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_create';
|
||||
|
||||
/**
|
||||
* 更新任务 update_task api url
|
||||
* @var string
|
||||
*/
|
||||
private $updateTaskUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_update';
|
||||
|
||||
/**
|
||||
* 获取任务详情 task_info api url
|
||||
* @var string
|
||||
*/
|
||||
private $taskInfoUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_info';
|
||||
|
||||
/**
|
||||
* 以分页的方式查询当前用户所有的任务信息 task_query api url
|
||||
* @var string
|
||||
*/
|
||||
private $taskQueryUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_query';
|
||||
|
||||
/**
|
||||
* 启动任务 task_start api url
|
||||
* @var string
|
||||
*/
|
||||
private $taskStartUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_start';
|
||||
|
||||
/**
|
||||
* 查询任务状态 task_status api url
|
||||
* @var string
|
||||
*/
|
||||
private $taskStatusUrl = 'https://aip.baidubce.com/rest/2.0/kg/v1/pie/task_status';
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* 创建任务接口
|
||||
*
|
||||
* @param string $name - 任务名字
|
||||
* @param string $templateContent - json string 解析模板内容
|
||||
* @param string $inputMappingFile - 抓取结果映射文件的路径
|
||||
* @param string $outputFile - 输出文件名字
|
||||
* @param string $urlPattern - url pattern
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* limit_count 限制解析数量limit_count为0时进行全量任务,limit_count>0时只解析limit_count数量的页面
|
||||
* @return array
|
||||
*/
|
||||
public function createTask($name, $templateContent, $inputMappingFile, $outputFile, $urlPattern, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['name'] = $name;
|
||||
$data['template_content'] = $templateContent;
|
||||
$data['input_mapping_file'] = $inputMappingFile;
|
||||
$data['output_file'] = $outputFile;
|
||||
$data['url_pattern'] = $urlPattern;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->createTaskUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 更新任务接口
|
||||
*
|
||||
* @param integer $id - 任务ID
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* name 任务名字
|
||||
* template_content json string 解析模板内容
|
||||
* input_mapping_file 抓取结果映射文件的路径
|
||||
* url_pattern url pattern
|
||||
* output_file 输出文件名字
|
||||
* @return array
|
||||
*/
|
||||
public function updateTask($id, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['id'] = $id;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->updateTaskUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取任务详情接口
|
||||
*
|
||||
* @param integer $id - 任务ID
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function getTaskInfo($id, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['id'] = $id;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->taskInfoUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 以分页的方式查询当前用户所有的任务信息接口
|
||||
*
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* id 任务ID,精确匹配
|
||||
* name 中缀模糊匹配,abc可以匹配abc,aaabc,abcde等
|
||||
* status 要筛选的任务状态
|
||||
* page 页码
|
||||
* per_page 页码
|
||||
* @return array
|
||||
*/
|
||||
public function getUserTasks($options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->taskQueryUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 启动任务接口
|
||||
*
|
||||
* @param integer $id - 任务ID
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function startTask($id, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['id'] = $id;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->taskStartUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询任务状态接口
|
||||
*
|
||||
* @param integer $id - 任务ID
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function getTaskStatus($id, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['id'] = $id;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->taskStatusUrl, $data);
|
||||
}
|
||||
}
|
||||
409
金壶/ydyd_service/extend/BaiduOcr/AipNlp.php
Normal file
409
金壶/ydyd_service/extend/BaiduOcr/AipNlp.php
Normal file
@@ -0,0 +1,409 @@
|
||||
<?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 AipNlp extends AipBase {
|
||||
|
||||
/**
|
||||
* 词法分析 lexer api url
|
||||
* @var string
|
||||
*/
|
||||
private $lexerUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer';
|
||||
|
||||
/**
|
||||
* 词法分析(定制版) lexer_custom api url
|
||||
* @var string
|
||||
*/
|
||||
private $lexerCustomUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/lexer_custom';
|
||||
|
||||
/**
|
||||
* 依存句法分析 dep_parser api url
|
||||
* @var string
|
||||
*/
|
||||
private $depParserUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/depparser';
|
||||
|
||||
/**
|
||||
* 词向量表示 word_embedding api url
|
||||
* @var string
|
||||
*/
|
||||
private $wordEmbeddingUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/word_emb_vec';
|
||||
|
||||
/**
|
||||
* DNN语言模型 dnnlm_cn api url
|
||||
* @var string
|
||||
*/
|
||||
private $dnnlmCnUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/dnnlm_cn';
|
||||
|
||||
/**
|
||||
* 词义相似度 word_sim_embedding api url
|
||||
* @var string
|
||||
*/
|
||||
private $wordSimEmbeddingUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/word_emb_sim';
|
||||
|
||||
/**
|
||||
* 短文本相似度 simnet api url
|
||||
* @var string
|
||||
*/
|
||||
private $simnetUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/simnet';
|
||||
|
||||
/**
|
||||
* 评论观点抽取 comment_tag api url
|
||||
* @var string
|
||||
*/
|
||||
private $commentTagUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v2/comment_tag';
|
||||
|
||||
/**
|
||||
* 情感倾向分析 sentiment_classify api url
|
||||
* @var string
|
||||
*/
|
||||
private $sentimentClassifyUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/sentiment_classify';
|
||||
|
||||
/**
|
||||
* 文章标签 keyword api url
|
||||
* @var string
|
||||
*/
|
||||
private $keywordUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/keyword';
|
||||
|
||||
/**
|
||||
* 文章分类 topic api url
|
||||
* @var string
|
||||
*/
|
||||
private $topicUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/topic';
|
||||
|
||||
/**
|
||||
* 文本纠错 ecnet api url
|
||||
* @var string
|
||||
*/
|
||||
private $ecnetUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/ecnet';
|
||||
|
||||
/**
|
||||
* 对话情绪识别接口 emotion api url
|
||||
* @var string
|
||||
*/
|
||||
private $emotionUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/emotion';
|
||||
|
||||
/**
|
||||
* 新闻摘要接口 news_summary api url
|
||||
* @var string
|
||||
*/
|
||||
private $newsSummaryUrl = 'https://aip.baidubce.com/rpc/2.0/nlp/v1/news_summary';
|
||||
|
||||
/**
|
||||
* 格式化结果
|
||||
* @param $content string
|
||||
* @return mixed
|
||||
*/
|
||||
protected function proccessResult($content){
|
||||
return json_decode(mb_convert_encoding($content, 'UTF8', 'GBK'), true, 512, JSON_BIGINT_AS_STRING);
|
||||
}
|
||||
|
||||
/**
|
||||
* 词法分析接口
|
||||
*
|
||||
* @param string $text - 待分析文本(目前仅支持GBK编码),长度不超过65536字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function lexer($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->lexerUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 词法分析(定制版)接口
|
||||
*
|
||||
* @param string $text - 待分析文本(目前仅支持GBK编码),长度不超过65536字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function lexerCustom($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->lexerCustomUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 依存句法分析接口
|
||||
*
|
||||
* @param string $text - 待分析文本(目前仅支持GBK编码),长度不超过256字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* mode 模型选择。默认值为0,可选值mode=0(对应web模型);mode=1(对应query模型)
|
||||
* @return array
|
||||
*/
|
||||
public function depParser($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->depParserUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 词向量表示接口
|
||||
*
|
||||
* @param string $word - 文本内容(GBK编码),最大64字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function wordEmbedding($word, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['word'] = $word;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->wordEmbeddingUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* DNN语言模型接口
|
||||
*
|
||||
* @param string $text - 文本内容(GBK编码),最大512字节,不需要切词
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function dnnlm($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->dnnlmCnUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 词义相似度接口
|
||||
*
|
||||
* @param string $word1 - 词1(GBK编码),最大64字节
|
||||
* @param string $word2 - 词1(GBK编码),最大64字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* mode 预留字段,可选择不同的词义相似度模型。默认值为0,目前仅支持mode=0
|
||||
* @return array
|
||||
*/
|
||||
public function wordSimEmbedding($word1, $word2, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['word_1'] = $word1;
|
||||
$data['word_2'] = $word2;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->wordSimEmbeddingUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 短文本相似度接口
|
||||
*
|
||||
* @param string $text1 - 待比较文本1(GBK编码),最大512字节
|
||||
* @param string $text2 - 待比较文本2(GBK编码),最大512字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* model 默认为"BOW",可选"BOW"、"CNN"与"GRNN"
|
||||
* @return array
|
||||
*/
|
||||
public function simnet($text1, $text2, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text_1'] = $text1;
|
||||
$data['text_2'] = $text2;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->simnetUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 评论观点抽取接口
|
||||
*
|
||||
* @param string $text - 评论内容(GBK编码),最大10240字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* type 评论行业类型,默认为4(餐饮美食)
|
||||
* @return array
|
||||
*/
|
||||
public function commentTag($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->commentTagUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 情感倾向分析接口
|
||||
*
|
||||
* @param string $text - 文本内容(GBK编码),最大102400字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function sentimentClassify($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->sentimentClassifyUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章标签接口
|
||||
*
|
||||
* @param string $title - 篇章的标题,最大80字节
|
||||
* @param string $content - 篇章的正文,最大65535字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function keyword($title, $content, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['title'] = $title;
|
||||
$data['content'] = $content;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->keywordUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文章分类接口
|
||||
*
|
||||
* @param string $title - 篇章的标题,最大80字节
|
||||
* @param string $content - 篇章的正文,最大65535字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function topic($title, $content, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['title'] = $title;
|
||||
$data['content'] = $content;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->topicUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 文本纠错接口
|
||||
*
|
||||
* @param string $text - 待纠错文本,输入限制511字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* @return array
|
||||
*/
|
||||
public function ecnet($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->ecnetUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 对话情绪识别接口接口
|
||||
*
|
||||
* @param string $text - 待识别情感文本,输入限制512字节
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* scene default(默认项-不区分场景),talk(闲聊对话-如度秘聊天等),task(任务型对话-如导航对话等),customer_service(客服对话-如电信/银行客服等)
|
||||
* @return array
|
||||
*/
|
||||
public function emotion($text, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['text'] = $text;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->emotionUrl, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* 新闻摘要接口接口
|
||||
*
|
||||
* @param string $content - 字符串(限3000字符数以内)字符串仅支持GBK编码,长度需小于3000字符数(即6000字节),请输入前确认字符数没有超限,若字符数超长会返回错误。正文中如果包含段落信息,请使用"\n"分隔,段落信息算法中有重要的作用,请尽量保留
|
||||
* @param integer $maxSummaryLen - 此数值将作为摘要结果的最大长度。例如:原文长度1000字,本参数设置为150,则摘要结果的最大长度是150字;推荐最优区间:200-500字
|
||||
* @param array $options - 可选参数对象,key: value都为string类型
|
||||
* @description options列表:
|
||||
* title 字符串(限200字符数)字符串仅支持GBK编码,长度需小于200字符数(即400字节),请输入前确认字符数没有超限,若字符数超长会返回错误。标题在算法中具有重要的作用,若文章确无标题,输入参数的“标题”字段为空即可
|
||||
* @return array
|
||||
*/
|
||||
public function newsSummary($content, $maxSummaryLen, $options=array()){
|
||||
|
||||
$data = array();
|
||||
|
||||
$data['content'] = $content;
|
||||
$data['max_summary_len'] = $maxSummaryLen;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
$data = mb_convert_encoding(json_encode($data), 'GBK', 'UTF8');
|
||||
|
||||
return $this->request($this->newsSummaryUrl, $data);
|
||||
}
|
||||
}
|
||||
1113
金壶/ydyd_service/extend/BaiduOcr/AipOcr.php
Normal file
1113
金壶/ydyd_service/extend/BaiduOcr/AipOcr.php
Normal file
File diff suppressed because it is too large
Load Diff
138
金壶/ydyd_service/extend/BaiduOcr/AipSpeech.php
Normal file
138
金壶/ydyd_service/extend/BaiduOcr/AipSpeech.php
Normal file
@@ -0,0 +1,138 @@
|
||||
<?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 AipSpeech extends AipBase{
|
||||
|
||||
/**
|
||||
* url
|
||||
* @var string
|
||||
*/
|
||||
public $asrUrl = 'http://vop.baidu.com/server_api';
|
||||
|
||||
/**
|
||||
* url
|
||||
* @var string
|
||||
*/
|
||||
public $ttsUrl = 'http://tsn.baidu.com/text2audio';
|
||||
|
||||
/**
|
||||
* 判断认证是否有权限
|
||||
* @param array $authObj
|
||||
* @return boolean
|
||||
*/
|
||||
protected function isPermission($authObj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理请求参数
|
||||
* @param string $url
|
||||
* @param array $params
|
||||
* @param array $data
|
||||
* @param array $headers
|
||||
*/
|
||||
protected function proccessRequest($url, &$params, &$data, $headers){
|
||||
|
||||
$token = isset($params['access_token']) ? $params['access_token'] : '';
|
||||
|
||||
if(empty($data['cuid'])){
|
||||
$data['cuid'] = md5($token);
|
||||
}
|
||||
|
||||
if($url === $this->asrUrl){
|
||||
$data['token'] = $token;
|
||||
$data = json_encode($data);
|
||||
}else{
|
||||
$data['tok'] = $token;
|
||||
}
|
||||
|
||||
unset($params['access_token']);
|
||||
}
|
||||
|
||||
/**
|
||||
* 格式化结果
|
||||
* @param $content string
|
||||
* @return mixed
|
||||
*/
|
||||
protected function proccessResult($content){
|
||||
$obj = json_decode($content, true);
|
||||
|
||||
if($obj === null){
|
||||
$obj = array(
|
||||
'__json_decode_error' => $content
|
||||
);
|
||||
}
|
||||
|
||||
return $obj;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $speech
|
||||
* @param string $format
|
||||
* @param int $rate
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function asr($speech, $format, $rate, $options=array()){
|
||||
$data = array();
|
||||
|
||||
if(!empty($speech)){
|
||||
$data['speech'] = base64_encode($speech);
|
||||
$data['len'] = strlen($speech);
|
||||
}
|
||||
|
||||
$data['format'] = $format;
|
||||
$data['rate'] = $rate;
|
||||
$data['channel'] = 1;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
return $this->request($this->asrUrl, $data, array());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $text
|
||||
* @param string $lang
|
||||
* @param int $ctp
|
||||
* @param array $options
|
||||
* @return array
|
||||
*/
|
||||
public function synthesis($text, $lang='zh', $ctp=1, $options=array()){
|
||||
$data = array();
|
||||
|
||||
$data['tex'] = $text;
|
||||
$data['lan'] = $lang;
|
||||
$data['ctp'] = $ctp;
|
||||
|
||||
$data = array_merge($data, $options);
|
||||
|
||||
$result = $this->request($this->ttsUrl, $data, array());
|
||||
|
||||
if(isset($result['__json_decode_error'])){
|
||||
return $result['__json_decode_error'];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
}
|
||||
28
金壶/ydyd_service/extend/BaiduOcr/composer.json
Normal file
28
金壶/ydyd_service/extend/BaiduOcr/composer.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"name": "baidu/aip-sdk",
|
||||
"description": "baidu pulic ai php sdk",
|
||||
"authors": [
|
||||
{
|
||||
"name": "baidu"
|
||||
}
|
||||
],
|
||||
"license": "Apache-2.0",
|
||||
"require": {
|
||||
"php": ">=5.3.3"
|
||||
},
|
||||
"minimum-stability": "stable",
|
||||
"autoload": {
|
||||
"files": [
|
||||
"lib/AipBase.php",
|
||||
"AipBodyAnalysis.php",
|
||||
"AipContentCensor.php",
|
||||
"AipFace.php",
|
||||
"AipImageClassify.php",
|
||||
"AipImageSearch.php",
|
||||
"AipKg.php",
|
||||
"AipNlp.php",
|
||||
"AipOcr.php",
|
||||
"AipSpeech.php"
|
||||
]
|
||||
}
|
||||
}
|
||||
1
金壶/ydyd_service/extend/BaiduOcr/lib/.pydio
Normal file
1
金壶/ydyd_service/extend/BaiduOcr/lib/.pydio
Normal file
@@ -0,0 +1 @@
|
||||
67e6fe11-3667-462b-947e-f5d4d9fe918a
|
||||
345
金壶/ydyd_service/extend/BaiduOcr/lib/AipBCEUtil.php
Normal file
345
金壶/ydyd_service/extend/BaiduOcr/lib/AipBCEUtil.php
Normal file
@@ -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.
|
||||
*/
|
||||
namespace BaiduOcr\lib;
|
||||
/**
|
||||
* 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();
|
||||
398
金壶/ydyd_service/extend/BaiduOcr/lib/AipBase.php
Normal file
398
金壶/ydyd_service/extend/BaiduOcr/lib/AipBase.php
Normal file
@@ -0,0 +1,398 @@
|
||||
<?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.
|
||||
*/
|
||||
namespace BaiduOcr\lib;
|
||||
//require_once 'AipHttpClient.php';
|
||||
//require_once 'AipBCEUtil.php';
|
||||
|
||||
|
||||
use BaiduOcr\lib\AipHttpClient as AipHttpClient;
|
||||
use BaiduOcr\lib\AipBCEUtil as AipBCEUtil;
|
||||
|
||||
/**
|
||||
* 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_15';
|
||||
$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);
|
||||
}
|
||||
|
||||
}
|
||||
215
金壶/ydyd_service/extend/BaiduOcr/lib/AipHttpClient.php
Normal file
215
金壶/ydyd_service/extend/BaiduOcr/lib/AipHttpClient.php
Normal file
@@ -0,0 +1,215 @@
|
||||
<?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.
|
||||
*/
|
||||
namespace BaiduOcr\lib;
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
{"refresh_token":"25.d3afd58367f9b83c9c1050351a39949c.315360000.1885190493.282335-17393063","expires_in":2592000,"session_key":"9mzdWBXHl3rzZnYwDbIXWIOP13psR1DcWcRYjn9l90\/wnKw0yRpXvLeBgOCseBb0R1Z8CQpSnLPpCvtY1aLNGb9wgQoecQ==","access_token":"24.cea0ed80a1cd81807dbfe827e6de264f.2592000.1572422493.282335-17393063","scope":"public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_antispam_spam brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_nlp_ecnet brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_\u53f0\u6e7e\u901a\u884c\u8bc1 vis-ocr_\u6e2f\u6fb3\u901a\u884c\u8bc1 vis-ocr_\u673a\u52a8\u8f66\u68c0\u9a8c\u5408\u683c\u8bc1\u8bc6\u522b vis-ocr_\u8f66\u8f86vin\u7801\u8bc6\u522b solution_face vis-ocr_\u5b9a\u989d\u53d1\u7968\u8bc6\u522b vis-ocr_\u4fdd\u5355\u8bc6\u522b brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_certificate brain_ocr_insurance_doc wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi fake_face_detect_\u5f00\u653eScope","session_secret":"30a863980c0cab64b861f52619711d5d","time":1569830494,"is_cloud_user":false}
|
||||
@@ -0,0 +1 @@
|
||||
{"refresh_token":"25.8a38b4f72b23bfd9873904847c09b490.315360000.1900484860.282335-17614601","expires_in":2592000,"session_key":"9mzdCuD\/nrbL3I0WLtbqw3oaxKRdlkjNID355V4Pavpe\/8ILowiVfMTHMqLnRQeC8ENKjnaFUDKbaE8QFmLYBWd3xFv+1w==","access_token":"24.1d3dd93c6453ea6f71009fdf8421170e.2592000.1587716860.282335-17614601","scope":"vis-ocr_\u884c\u7a0b\u5355\u8bc6\u522b brain_ocr_air_ticket public vis-ocr_ocr brain_ocr_scope brain_ocr_general brain_ocr_general_basic vis-ocr_business_license brain_ocr_webimage brain_all_scope brain_ocr_idcard brain_ocr_driving_license brain_ocr_vehicle_license vis-ocr_plate_number brain_solution brain_ocr_plate_number brain_ocr_accurate brain_ocr_accurate_basic brain_ocr_receipt brain_ocr_business_license brain_solution_iocr brain_qrcode brain_ocr_handwriting brain_ocr_passport brain_ocr_vat_invoice brain_numbers brain_ocr_business_card brain_ocr_train_ticket brain_ocr_taxi_receipt vis-ocr_household_register vis-ocr_vis-classify_birth_certificate vis-ocr_\u53f0\u6e7e\u901a\u884c\u8bc1 vis-ocr_\u6e2f\u6fb3\u901a\u884c\u8bc1 vis-ocr_\u673a\u52a8\u8f66\u68c0\u9a8c\u5408\u683c\u8bc1\u8bc6\u522b vis-ocr_\u8f66\u8f86vin\u7801\u8bc6\u522b vis-ocr_\u5b9a\u989d\u53d1\u7968\u8bc6\u522b vis-ocr_\u4fdd\u5355\u8bc6\u522b brain_ocr_vin brain_ocr_quota_invoice brain_ocr_birth_certificate brain_ocr_household_register brain_ocr_HK_Macau_pass brain_ocr_taiwan_pass brain_ocr_vehicle_certificate brain_ocr_insurance_doc wise_adapt lebo_resource_base lightservice_public hetu_basic lightcms_map_poi kaidian_kaidian ApsMisTest_Test\u6743\u9650 vis-classify_flower lpq_\u5f00\u653e cop_helloScope ApsMis_fangdi_permission smartapp_snsapi_base iop_autocar oauth_tp_app smartapp_smart_game_openapi oauth_sessionkey smartapp_swanid_verify smartapp_opensource_openapi smartapp_opensource_recapi qatest_scope1 fake_face_detect_\u5f00\u653eScope vis-ocr_\u865a\u62df\u4eba\u7269\u52a9\u7406 idl-video_\u865a\u62df\u4eba\u7269\u52a9\u7406","session_secret":"4df7ce78d05af9d18d308e000fdf7c03","time":1585124860,"is_cloud_user":false}
|
||||
Reference in New Issue
Block a user