├── Cloud ├── QiniuSDK.class.php └── sdk │ ├── QiniuAudioVisualSDK.class.php │ ├── QiniuImageViewSDK.class.php │ ├── QiniuRSSDK.class.php │ └── QiniuRSTransferSDK.class.php ├── LICENSE └── README.md /Cloud/QiniuSDK.class.php: -------------------------------------------------------------------------------- 1 | 20130801 5 | // +---------------------------------------------------------------------- 6 | // | Docs:http://docs.qiniu.com/php-sdk/v6/index.html 7 | 8 | /** 9 | * 七牛API封装基类 10 | */ 11 | abstract class QiniuSDK{ 12 | /** 13 | * SDK版本 14 | */ 15 | private $SDK_Version='1.0'; 16 | private $SDK_Release='20130801'; 17 | /** 18 | * API版本 19 | * @var string 20 | */ 21 | protected $Version = '6.1.1'; 22 | /** 23 | * 申请应用时分配的app_key 24 | * @var string 25 | */ 26 | protected $AppKey = ''; 27 | 28 | /** 29 | * 申请应用时分配的 app_secret 30 | * @var string 31 | */ 32 | protected $AppSecret = ''; 33 | /** 34 | * API根路径 35 | * @var string 36 | */ 37 | protected $ApiBase = ''; 38 | /** 39 | * 调用接口类型 40 | * @var string 41 | */ 42 | private $Type = ''; 43 | //请求信息 44 | public $URL; 45 | public $rqHeader; 46 | public $rqBody; 47 | //错误信息 48 | public $Err; // string 49 | public $Reqid; // string 50 | public $Details; // []string 51 | public $Code; // int 52 | //响应信息 53 | public $StatusCode; 54 | public $rpHeader; 55 | public $ContentLength; 56 | public $rpBody; 57 | //上传下载域 58 | public $downDomain; 59 | /** 60 | * 构造方法,配置应用信息 61 | */ 62 | public function __construct(){ 63 | //设置SDK类型 64 | $class = get_class($this); 65 | $this->Type = strtoupper(substr($class, 0, strlen($class)-3)); 66 | //获取应用配置 67 | $config = C("THINK_SDK_QINIU"); 68 | if(empty($config['APP_KEY']) || empty($config['APP_SECRET'])){ 69 | throw new Exception('请配置您申请的APP_KEY和APP_SECRET'); 70 | } else { 71 | $this->AppKey = $config['APP_KEY']; 72 | $this->AppSecret = $config['APP_SECRET']; 73 | $this->downDomain = $config['DOWN_DOMAIN']; 74 | } 75 | } 76 | /** 77 | * 取得API实例 78 | * @static 79 | * @return mixed 返回API 80 | */ 81 | public static function getInstance($type, $param = null) { 82 | $name = ucfirst(strtolower($type)) . 'SDK'; 83 | require_once "sdk/{$name}.class.php"; 84 | if (class_exists($name)) { 85 | return new $name($param); 86 | } else { 87 | halt(L('_CLASS_NOT_EXIST_') . ':' . $name); 88 | } 89 | } 90 | /** 91 | * URLSafeBase64Encode 92 | * @param string str 安全编码串 93 | */ 94 | public function SafeBaseEncode($str){ 95 | $find = array('+', '/'); 96 | $replace = array('-', '_'); 97 | return str_replace($find, $replace, base64_encode($str)); 98 | } 99 | /** 100 | * 请求执行 101 | * @param string $url 完整url 102 | * @return object 错误信息对象 103 | */ 104 | public function callNoRet($url){ 105 | $u = array('path' => $url); 106 | self::request($u, null); 107 | self::RoundTrip(); 108 | self::setResponse(); 109 | } 110 | public function call($url){ 111 | $u = array('path' => $url); 112 | self::request($u, null); 113 | self::RoundTrip(); 114 | return self::getReponseRet(); 115 | } 116 | public function CallWithMultipartForm($url, $fields, $files){ 117 | list($contentType, $body) = self::buildMultipartForm($fields, $files); 118 | return self::CallWithForm($url, $body, $contentType); 119 | } 120 | /** 121 | * 组装请求参数 122 | * @param array $fields 字段数组 123 | * @param array $files 文件数组 124 | * @return array 组装结果 125 | */ 126 | public function buildMultipartForm($fields, $files){ 127 | $data = array(); 128 | $mimeBoundary = md5(microtime()); 129 | foreach ($fields as $name => $val) { 130 | array_push($data, '--' . $mimeBoundary); 131 | array_push($data, "Content-Disposition: form-data; name=\"$name\""); 132 | array_push($data, ''); 133 | array_push($data, $val); 134 | } 135 | foreach ($files as $file) { 136 | array_push($data, '--' . $mimeBoundary); 137 | list($name, $fileName, $fileBody) = $file; 138 | $fileName = self::escapeQuotes($fileName); 139 | array_push($data, "Content-Disposition: form-data; name=\"$name\"; filename=\"$fileName\""); 140 | array_push($data, 'Content-Type: application/octet-stream'); 141 | array_push($data, ''); 142 | array_push($data, $fileBody); 143 | } 144 | 145 | array_push($data, '--' . $mimeBoundary . '--'); 146 | array_push($data, ''); 147 | $body = implode("\r\n", $data); 148 | $contentType = 'multipart/form-data; boundary=' . $mimeBoundary; 149 | return array($contentType, $body); 150 | } 151 | /** 152 | * 数据提交过程 153 | * @param string $url 操作路径 154 | * @param array $params 数据参数 155 | * @param string $contentType 文本内容 156 | */ 157 | function CallWithForm($url, $params, $contentType = 'application/x-www-form-urlencoded'){ 158 | $u = array('path' => $url); 159 | if ($contentType === 'application/x-www-form-urlencoded') { 160 | if (is_array($params)) { 161 | $params = http_build_query($params); 162 | } 163 | } 164 | self::request($u, $params); 165 | if ($contentType !== 'multipart/form-data') { 166 | $this->rqHeader['Content-Type'] = $contentType; 167 | } 168 | self::RoundTrip(); 169 | return self::getReponseRet(); 170 | } 171 | /** 172 | * 替换处理 173 | * @param string $str 需处理串 174 | * @return string 处理结果 175 | */ 176 | function escapeQuotes($str){ 177 | $find = array("\\", "\""); 178 | $replace = array("\\\\", "\\\""); 179 | return str_replace($find, $replace, $str); 180 | } 181 | /** 182 | * 设置请求参数 183 | * @param string $url URL 184 | * @param string $body 头body内容 185 | */ 186 | public function request($url, $body){ 187 | $this->URL = $url; 188 | $this->rqHeader = array(); 189 | $this->rqBody = $body; 190 | } 191 | /** 192 | * 执行请求 193 | */ 194 | public function doCall(){ 195 | $ch = curl_init(); 196 | $url = $this->URL; 197 | $options = array( 198 | CURLOPT_RETURNTRANSFER => true, 199 | CURLOPT_SSL_VERIFYPEER => false, 200 | CURLOPT_SSL_VERIFYHOST => false, 201 | CURLOPT_CUSTOMREQUEST => 'POST', 202 | CURLOPT_URL => $url['path'] 203 | ); 204 | $httpHeader = $this->rqHeader; 205 | if (!empty($httpHeader)) 206 | { 207 | $header = array(); 208 | foreach($httpHeader as $key => $parsedUrlValue) { 209 | $header[] = "$key: $parsedUrlValue"; 210 | } 211 | $options[CURLOPT_HTTPHEADER] = $header; 212 | } 213 | $body = $this->rqBody; 214 | if (!empty($body)) { 215 | $options[CURLOPT_POSTFIELDS] = $body; 216 | } 217 | curl_setopt_array($ch, $options); 218 | $result = curl_exec($ch); 219 | $ret = curl_errno($ch); 220 | if ($ret !== 0) { 221 | self::error(0, curl_error($ch)); 222 | curl_close($ch); 223 | } 224 | $code = curl_getinfo($ch, CURLINFO_HTTP_CODE); 225 | $contentType = curl_getinfo($ch, CURLINFO_CONTENT_TYPE); 226 | curl_close($ch); 227 | self::response($code, $result); 228 | $this->rpHeader['Content-Type'] = $contentType; 229 | } 230 | /** 231 | * 设置错误信息 232 | * @param int $code 错误码 233 | * @param string $err 错误信息 234 | */ 235 | public function error($code, $err){ 236 | $this->Code = $code; 237 | $this->Err = $err; 238 | } 239 | /** 240 | * 设置响应信息 241 | * @param int $code 响应码 242 | * @param string $body 响应文本 243 | */ 244 | public function response($code,$body){ 245 | $this->StatusCode = $code; 246 | $this->rpHeader = array(); 247 | $this->rpBody = $body; 248 | $this->ContentLength = strlen($body); 249 | } 250 | /** 251 | * 判断是否有body或者设置了application/x-www-form-urlencoded头 252 | * @return bool 253 | */ 254 | public function incBody(){ 255 | $body = $this->rpBody; 256 | if (!isset($body)) { 257 | return false; 258 | } 259 | 260 | $ct = self::getHeaderType($this->rpHeader, 'Content-Type'); 261 | if ($ct === 'application/x-www-form-urlencoded') { 262 | return true; 263 | } 264 | return false; 265 | } 266 | /** 267 | * 获得头类型值 268 | * @param array $header 269 | * @param string $key 270 | */ 271 | public function getHeaderType($header, $key){ 272 | $val = @$header[$key]; 273 | if (isset($val)) { 274 | if (is_array($val)) { 275 | return $val[0]; 276 | } 277 | return $val; 278 | } else { 279 | return ''; 280 | } 281 | } 282 | /** 283 | * 请求过程 284 | */ 285 | public function RoundTrip(){ 286 | $incbody = self::incBody(); 287 | $token = self::SignRequest($incbody); 288 | $this->rqHeader['Authorization'] = "QBox $token"; 289 | return self::doCall(); 290 | } 291 | /** 292 | * 请求签名 293 | * @param int $incbody 294 | */ 295 | public function SignRequest($incbody) 296 | { 297 | $url = $this->URL; 298 | $url = parse_url($url['path']); 299 | $data = ''; 300 | if (isset($url['path'])) { 301 | $data = $url['path']; 302 | } 303 | if (isset($url['query'])) { 304 | $data .= '?' . $url['query']; 305 | } 306 | $data .= "\n"; 307 | 308 | if ($incbody) { 309 | $data .= $this->Body; 310 | } 311 | return $this->Sign($data); 312 | } 313 | /** 314 | * 数据签名 315 | * @param array $data 需签名数据 316 | */ 317 | public function Sign($data){ 318 | $sign = hash_hmac('sha1', $data, $this->AppSecret, true); 319 | return $this->AppKey . ':' . self::SafeBaseEncode($sign); 320 | } 321 | public function SignWithData($data){ 322 | $data = self::SafeBaseEncode($data); 323 | return $this->Sign($data) . ':' . $data; 324 | } 325 | /** 326 | * 设置相应错误信息 327 | */ 328 | public function setResponse(){ 329 | $header = $this->rpHeader; 330 | $details = self::getHeaderType($header, 'X-Log'); 331 | $reqId = self::getHeaderType($header, 'X-Reqid'); 332 | self::error($this->StatusCode, null); 333 | if ($this->Code > 299) { 334 | if ($this->ContentLength !== 0) { 335 | if (self::getHeaderType($header, 'Content-Type') === 'application/json') { 336 | $ret = json_decode($this->rpBody, true); 337 | $this->Err = $ret['error']; 338 | } 339 | } 340 | } 341 | } 342 | /** 343 | * 获得响应结果信息 344 | * @return object 345 | */ 346 | public function getReponseErr(){ 347 | $data['Err']=$this->Err; // string 348 | $data['Reqid']=$this->Reqid; // string 349 | $data['Details']=$this->Details; // []string 350 | $data['Code']=$this->Code; // int 351 | return (object)($data); 352 | } 353 | public function getReponseRet(){ 354 | $code = $this->StatusCode; 355 | $data = null; 356 | if ($code >= 200 && $code <= 299) { 357 | if ($this->ContentLength !== 0) { 358 | $data = json_decode($this->rpBody, true); 359 | if ($data === null) { 360 | self::error(0, 'json decode null'); 361 | } 362 | } 363 | if ($code === 200) { 364 | return array($data, null); 365 | } 366 | } 367 | return array($data, self::getReponseErr()); 368 | } 369 | } 370 | ?> -------------------------------------------------------------------------------- /Cloud/sdk/QiniuAudioVisualSDK.class.php: -------------------------------------------------------------------------------- 1 | 20130802 5 | // +---------------------------------------------------------------------- 6 | // | Docs:http://docs.qiniu.com/api/v6/audio-video-hls-process.html 7 | 8 | /** 9 | * 媒体资源类 10 | */ 11 | class QiniuAudioVisualSDK extends QiniuSDK{ 12 | /** 13 | * 申请应用时分配的app_key 14 | * @param string 15 | */ 16 | protected $AppKey = ''; 17 | 18 | /** 19 | * 申请应用时分配的 app_secret 20 | * @param string 21 | */ 22 | protected $AppSecret = ''; 23 | /** 24 | * API根路径 25 | * @param string 26 | */ 27 | protected $ApiBase = ''; 28 | //上传下载域 29 | public $DownDomain; 30 | public $Map; 31 | //应用参数 32 | public $HLS; 33 | //媒体格式 34 | public $Format; 35 | //静态码率 36 | public $BitRate; 37 | //动态码率 38 | public $AudioQuality; 39 | //音频采样频率 40 | public $SamplingRate; 41 | //视频帧率 42 | public $FrameRate; 43 | //视频比特率 44 | public $VideoBitRate; 45 | //视频编码方案 46 | public $Vcodec; 47 | //音频编码方案 48 | public $Acodec; 49 | //取视频的第几秒 50 | public $Offset; 51 | //缩略图宽度 52 | public $Width; 53 | //缩略图高度 54 | public $Height; 55 | //预设集 56 | public $Preset; 57 | public function __construct($params=''){ 58 | parent::__construct(); 59 | } 60 | /** 61 | * 设置请求参数 62 | * @param array $params 请求参数数组 63 | */ 64 | public function setRequestParams($params){ 65 | foreach ($params as $key => $value) { 66 | if(array_key_exists($key, $this->Map)){ 67 | $this->Map[$key] = $value; 68 | }else{ 69 | $this->$key = $value; 70 | } 71 | } 72 | } 73 | /** 74 | * 生成请求 75 | * @param string $url 请求地址 76 | * @param strng $type 请求类型 77 | */ 78 | public function MakeRequest($url,$type='avthumb',$params=''){ 79 | if($params!=''){ 80 | self::setRequestParams($params); 81 | } 82 | $func = '_make_'.$type.'_Request'; 83 | return self::$func($url); 84 | } 85 | protected function _make_avthumb_Request($url){ 86 | if (!empty($this->Format)) { 87 | $ops[] = $this->Format; 88 | } 89 | //HLS自定义 90 | if (!empty($this->HLS)) { 91 | $ops[] = 'm3u8/segtime'; 92 | //HLS自定义必须 93 | if (!empty($this->SegSeconds)) { 94 | $ops[] = $this->SegSeconds; 95 | } 96 | //HLS预设必须 97 | if (!empty($this->Preset)) { 98 | $ops[] = 'preset/'.$this->Preset; 99 | } 100 | } 101 | //视频 102 | if (!empty($this->FrameRate)) { 103 | $ops[] = 'r/' . $this->FrameRate; 104 | } 105 | if (!empty($this->VideoBitRate)) { 106 | $ops[] = 'vb/' . $this->VideoBitRate; 107 | } 108 | if (!empty($this->Vcodec)) { 109 | $ops[] = 'vcodec/' . $this->Vcodec; 110 | } 111 | if (!empty($this->Acodec)) { 112 | $ops[] = 'acodec/' . $this->Acodec; 113 | } 114 | /// 115 | if (!empty($this->BitRate)) { 116 | $ops[] = 'ab/' . $this->BitRate; 117 | } 118 | if (!empty($this->AudioQuality)) { 119 | $ops[] = 'aq/' . $this->AudioQuality; 120 | } 121 | if (!empty($this->AudioQuality)) { 122 | $ops[] = 'ar/' . $this->SamplingRate; 123 | } 124 | return $url . "?avthumb/". implode('/', $ops); 125 | } 126 | protected function _make_vframe_Request($url){ 127 | if (!empty($this->Format)) { 128 | $ops[] = $this->Format; 129 | } 130 | if (!empty($this->Offset)) { 131 | $ops[] = 'offset/' . $this->Offset; 132 | } 133 | if (!empty($this->Width)) { 134 | $ops[] = 'w/' . $this->Width; 135 | } 136 | if (!empty($this->Height)) { 137 | $ops[] = 'h/' . $this->Height; 138 | } 139 | return $url . "?vframe/". implode('/', $ops); 140 | } 141 | } 142 | ?> -------------------------------------------------------------------------------- /Cloud/sdk/QiniuImageViewSDK.class.php: -------------------------------------------------------------------------------- 1 | 20130801 5 | // +---------------------------------------------------------------------- 6 | // | Docs:http://docs.qiniu.com/api/v6/image-process.html 7 | 8 | /** 9 | * 图片资源类 10 | */ 11 | class QiniuImageViewSDK extends QiniuSDK{ 12 | /** 13 | * 申请应用时分配的app_key 14 | * @param string 15 | */ 16 | protected $AppKey = ''; 17 | 18 | /** 19 | * 申请应用时分配的 app_secret 20 | * @param string 21 | */ 22 | protected $AppSecret = ''; 23 | /** 24 | * API根路径 25 | * @param string 26 | */ 27 | protected $ApiBase = ''; 28 | //上传下载域 29 | public $DownDomain; 30 | //字段映射 31 | public $map = array(); 32 | //应用参数 33 | //图像缩略处理的模式 34 | public $Mode; 35 | //指定目标缩略图的宽度,单位:像素 36 | public $Width; 37 | //指定目标缩略图的高度,单位:像素 38 | public $Height; 39 | //指定目标缩略图的图像质量 40 | public $Quality; 41 | //指定目标缩略图的输出格式 42 | public $Format; 43 | //自动旋正 44 | public $Autoorient = 1; 45 | //缩略图大小 46 | public $Thumbnail; 47 | //位置偏移,只会使裁剪偏移受到影响 48 | public $Gravity; 49 | //裁剪大小和偏移 50 | public $Crop; 51 | //旋转角度 52 | public $Rotate; 53 | //水印模式 54 | public $WaterMode=1; 55 | //水印图片url 56 | public $Waterimageurl; 57 | //透明度 58 | public $Dissolve=100; 59 | //横向边距 60 | public $Dx=10; 61 | //纵向边距 62 | public $Dy=10; 63 | //水印文本 64 | public $Text; 65 | //字体名 66 | public $Font; 67 | //字体大小 68 | public $Fontsize; 69 | //字体颜色 70 | public $Fill; 71 | public function __construct($params=''){ 72 | parent::__construct(); 73 | } 74 | /** 75 | * 设置请求参数 76 | * @param array $params 请求参数数组 77 | */ 78 | public function setRequestParams($params){ 79 | foreach ($params as $key => $value) { 80 | if(array_key_exists($key, $map)){ 81 | $this->$map[$key] = $value; 82 | }else{ 83 | $this->$key = $value; 84 | } 85 | } 86 | } 87 | /** 88 | * 生成请求 89 | * @param string $url 请求地址 90 | * @param strng $type 请求类型 91 | */ 92 | public function MakeRequest($url,$type='imageInfo',$params=''){ 93 | if($params!=''){ 94 | self::setRequestParams($params); 95 | } 96 | $func = '_make_'.$type.'_Request'; 97 | return self::$func($url); 98 | } 99 | //基础功能 100 | protected function _make_imageInfo_Request($url){ 101 | return $url . "?imageInfo"; 102 | } 103 | protected function _make_exif_Request($url){ 104 | return $url . "?exif"; 105 | } 106 | protected function _make_imageView_Request($url){ 107 | $ops = array($this->Mode); 108 | if (!empty($this->Width)) { 109 | $ops[] = 'w/' . $this->Width; 110 | } 111 | if (!empty($this->Height)) { 112 | $ops[] = 'h/' . $this->Height; 113 | } 114 | if (!empty($this->Quality)) { 115 | $ops[] = 'q/' . $this->Quality; 116 | } 117 | if (!empty($this->Format)) { 118 | $ops[] = 'format/' . $this->Format; 119 | } 120 | return $url . "?imageView/" . implode('/', $ops); 121 | } 122 | //高级功能,暂未处理 ‘链式处理’ 123 | protected function _make_imageMogr_Request($url){ 124 | $ops = array(); 125 | if ($this->Autoorient) { 126 | $ops[] = 'auto-orient'; 127 | } 128 | if (!empty($this->Thumbnail)) { 129 | $this->Thumbnail = '!'.str_replace(array('%','^'), array('p','r'), $this->Thumbnail); 130 | $ops[] = 'thumbnail/' . $this->Thumbnail; 131 | } 132 | if (!empty($this->Gravity)) { 133 | $ops[] = 'gravity/' . $this->Gravity; 134 | } 135 | if (!empty($this->Crop)) { 136 | $this->Crop = '!'.str_replace(array('+'), array('a'), $this->Crop); 137 | $ops[] = 'crop/' . $this->Crop; 138 | } 139 | if (!empty($this->Quality)) { 140 | $ops[] = 'quality/' . $this->Quality; 141 | } 142 | if (!empty($this->Rotate)) { 143 | $ops[] = 'rotate/' . $this->Rotate; 144 | } 145 | if (!empty($this->Format)) { 146 | $ops[] = 'format/' . $this->Format; 147 | } 148 | return $url . "?imageMogr/v2/".implode('/', $ops); 149 | } 150 | //建议在上传图片后进行图片水印预转 151 | protected function _make_watermark_Request($url){ 152 | $ops = array(); 153 | if (!empty($this->WaterMode)) { 154 | $ops[] = $this->WaterMode; 155 | if($this->WaterMode==1){ 156 | if (!empty($this->Waterimageurl)){ 157 | $ops[] = 'image/' . parent::SafeBaseEncode($this->Waterimageurl); 158 | } 159 | } 160 | if($this->WaterMode==2){ 161 | if (!empty($this->Text)) { 162 | $ops[] = 'text/' . parent::SafeBaseEncode($this->Text); 163 | } 164 | if (!empty($this->Font)) { 165 | 166 | if(preg_match("/[^a-zA-Z]/", $this->Font)){ 167 | $ops[] = 'font/' . parent::SafeBaseEncode($this->Font); 168 | }else{ 169 | $ops[] = 'font/' . $this->Font; 170 | } 171 | 172 | } 173 | if (!empty($this->Fontsize)) { 174 | $ops[] = 'fontsize/' . $this->Fontsize; 175 | } 176 | if (!empty($this->Fill)) { 177 | $ops[] = 'fill/' . parent::SafeBaseEncode($this->Fill); 178 | } 179 | } 180 | 181 | 182 | if (!empty($this->Dissolv)) { 183 | $ops[] = 'dissolve/' . $this->Dissolve; 184 | } 185 | if (!empty($this->Gravity)) { 186 | $ops[] = 'gravity/' . $this->Gravity; 187 | } 188 | if (!empty($this->Dx)) { 189 | $ops[] = 'dx/' . $this->Dx; 190 | } 191 | if (!empty($this->Dy)) { 192 | $ops[] = 'dy/' . $this->Dy; 193 | } 194 | 195 | } 196 | return $url . "?watermark/". implode('/', $ops); 197 | } 198 | 199 | } -------------------------------------------------------------------------------- /Cloud/sdk/QiniuRSSDK.class.php: -------------------------------------------------------------------------------- 1 | 20130801 5 | // +---------------------------------------------------------------------- 6 | // | Docs:http://docs.qiniu.com/php-sdk/v6/index.html#rs-api 7 | 8 | /** 9 | * 资源管理类 10 | */ 11 | abstract class QiniuRSSDK extends QiniuSDK{ 12 | /** 13 | * 申请应用时分配的app_key 14 | * @var string 15 | */ 16 | protected $AppKey = ''; 17 | 18 | /** 19 | * 申请应用时分配的 app_secret 20 | * @var string 21 | */ 22 | protected $AppSecret = ''; 23 | /** 24 | * API根路径 25 | * @var string 26 | */ 27 | protected $ApiBase = 'http://rs.qbox.me'; 28 | public function __construct($param){ 29 | parent::__construct(); 30 | } 31 | /** 32 | * 取得API实例 33 | * @static 34 | * @return mixed 返回API 35 | */ 36 | public static function getInstance($type, $param = null) { 37 | $name = ucfirst(strtolower($type)) . 'SDK'; 38 | require_once "sdk/{$name}.class.php"; 39 | if (class_exists($name)) { 40 | return new $name($param); 41 | } else { 42 | halt(L('_CLASS_NOT_EXIST_') . ':' . $name); 43 | } 44 | } 45 | /** 46 | * 资源状态 47 | * @param string $bucket 空间名 48 | * @param string $key 文件名 49 | */ 50 | public function Stat($bucket, $key){ 51 | $uri = self::get_RS_URIStat($bucket, $key); 52 | return parent::call($this->ApiBase . $uri); 53 | } 54 | /** 55 | * 资源移动 56 | * @param string $bucket 空间桶名 57 | * @param string $key 文件名 58 | * @param string $bucket1 空间桶名 59 | * @param string $key1 文件名 60 | */ 61 | public function Move($bucket, $key, $bucket1, $key1){ 62 | $uri = self::get_RS_URIMove($bucket, $key, $bucket1, $key1); 63 | parent::callNoRet($this->ApiBase . $uri); 64 | } 65 | /** 66 | * 资源复制 67 | * @param string $bucket 空间桶名 68 | * @param string $key 文件名 69 | * @param string $bucket1 空间桶名 70 | * @param string $key1 文件名 71 | */ 72 | public function Copy($bucket, $key, $bucket1, $key1){ 73 | $uri = self::get_RS_URICopy($bucket, $key, $bucket1, $key1); 74 | parent::callNoRet($this->ApiBase . $uri); 75 | } 76 | /** 77 | * 资源删除 78 | * @param string $bucket 空间名 79 | * @param string $key 文件名 80 | */ 81 | public function Delete($bucket, $key){ 82 | $uri = self::get_RS_URIDelete($bucket, $key); 83 | parent::callNoRet($this->ApiBase . $uri); 84 | } 85 | /** 86 | * 组合操作地址 87 | * @param string $bucket 空间桶名 88 | * @param string $key 文件名 89 | * @param string $bucket1 空间桶名 90 | * @param string $key1 文件名 91 | * @return string uri 92 | */ 93 | public function get_RS_URIMove($bucket, $key, $bucket1, $key1){ 94 | return '/move/' . parent::SafeBaseEncode("$bucket:$key") . '/' . parent::SafeBaseEncode("$bucket1:$key1"); 95 | } 96 | public function get_RS_URIStat($bucket, $key){ 97 | return '/stat/' . parent::SafeBaseEncode("$bucket:$key"); 98 | } 99 | 100 | public function get_RS_URIDelete($bucket, $key){ 101 | return '/delete/' . parent::SafeBaseEncode("$bucket:$key"); 102 | } 103 | 104 | public function get_RS_URICopy($bucketSrc, $keySrc, $bucketDest, $keyDest){ 105 | return '/copy/' . parent::SafeBaseEncode("$bucketSrc:$keySrc") . '/' . parent::SafeBaseEncode("$bucketDest:$keyDest"); 106 | } 107 | } 108 | ?> -------------------------------------------------------------------------------- /Cloud/sdk/QiniuRSTransferSDK.class.php: -------------------------------------------------------------------------------- 1 | 20130801 5 | // +---------------------------------------------------------------------- 6 | // | Docs:http://docs.qiniu.com/php-sdk/v6/index.html#get-and-put-api 7 | 8 | /** 9 | * 资源传输类 10 | */ 11 | class QiniuRSTransferSDK extends QiniuSDK{ 12 | /** 13 | * 申请应用时分配的app_key 14 | * @var string 15 | */ 16 | protected $AppKey = ''; 17 | 18 | /** 19 | * 申请应用时分配的 app_secret 20 | * @var string 21 | */ 22 | protected $AppSecret = ''; 23 | /** 24 | * API根路径 25 | * @var string 26 | */ 27 | protected $ApiBase = 'http://up.qiniu.com'; 28 | //上传策略参数 29 | public $Scope;//客户端的权限 30 | public $CallbackUrl;//回调地址 31 | public $CallbackBody;//回调信息 32 | public $ReturnUrl;//跳转地址 33 | public $ReturnBody;//跳转信息 34 | public $AsyncOps;//可指定上传完成后,需要自动执行哪些数据处理 35 | public $EndUser; 36 | public $Expires;//默认是 3600 秒 37 | //校验参数 38 | public $Params = null; 39 | public $MimeType = null; 40 | public $Crc32 = 0; 41 | public $CheckCrc = 0; 42 | //资源下载域名 43 | public $downDomain = ''; 44 | 45 | public function __construct($scope){ 46 | $this->Scope = $scope; 47 | parent::__construct(); 48 | } 49 | /** 50 | * 授权凭证 51 | */ 52 | public function Token($mac=null){ 53 | $deadline = $this->Expires; 54 | if ($deadline == 0) { 55 | $deadline = 3600; 56 | } 57 | $deadline += time(); 58 | if(empty($this->Scope)){ 59 | exit('error:scope is null'); 60 | } 61 | $policy = array('scope' => $this->Scope, 'deadline' => $deadline); 62 | if (!empty($this->CallbackUrl)) { 63 | $policy['callbackUrl'] = $this->CallbackUrl; 64 | } 65 | if (!empty($this->CallbackBody)) { 66 | $policy['callbackBody'] = $this->CallbackBody; 67 | } 68 | if (!empty($this->ReturnUrl)) { 69 | $policy['returnUrl'] = $this->ReturnUrl; 70 | } 71 | if (!empty($this->ReturnBody)) { 72 | $policy['returnBody'] = $this->ReturnBody; 73 | } 74 | if (!empty($this->AsyncOps)) { 75 | $policy['asyncOps'] = $this->AsyncOps; 76 | } 77 | if (!empty($this->EndUser)) { 78 | $policy['endUser'] = $this->EndUser; 79 | } 80 | 81 | $b = json_encode($policy); 82 | return parent::SignWithData($b); 83 | } 84 | /** 85 | * 传输字符文本 86 | * @param string $upToken 凭证 87 | * @param string $key 文件名 88 | * @param string $body 文本 89 | */ 90 | public function Put($upToken, $key, $body){ 91 | $fields = array('token' => $upToken); 92 | if ($key === null) { 93 | $fname = '?'; 94 | } else { 95 | $fname = $key; 96 | $fields['key'] = $key; 97 | } 98 | if ($this->CheckCrc) { 99 | $fields['crc32'] = $this->Crc32; 100 | } 101 | $files = array(array('file', $fname, $body)); 102 | return parent::CallWithMultipartForm($this->ApiBase, $fields, $files); 103 | } 104 | /** 105 | * 文件上传 106 | * @param string $upToken 凭证 107 | * @param string $key 文件名 108 | * @param string $localFile 文件名 109 | * @param int $CheckCrc 是否计算crc 110 | */ 111 | public function PutFile($upToken, $key, $localFile, $CheckCrc=1){ 112 | $this->CheckCrc = $CheckCrc; 113 | $fields = array('token' => $upToken, 'file' => '@' . $localFile); 114 | if ($key === null) { 115 | $fname = '?'; 116 | } else { 117 | $fname = $key; 118 | $fields['key'] = $key; 119 | } 120 | if ($this->CheckCrc) { 121 | if ($this->CheckCrc === 1) { 122 | $hash = hash_file('crc32b', $localFile); 123 | $array = unpack('N', pack('H*', $hash)); 124 | $this->Crc32 = $array[1]; 125 | } 126 | $fields['crc32'] = sprintf('%u', $this->Crc32); 127 | } 128 | return parent::CallWithForm($this->ApiBase, $fields,'multipart/form-data'); 129 | } 130 | 131 | /** 132 | * 生成地址 133 | * @param srting $key 文件名 134 | * @param string $domain 下载域 135 | */ 136 | public function MakeBaseUrl($key,$domain=''){ 137 | if($domain!=''){ 138 | $this->downDomain = $domain; 139 | } 140 | $keyEsc = rawurlencode($key); 141 | return "http://$this->downDomain/$keyEsc"; 142 | } 143 | /** 144 | * 生成私有地址 145 | * @param srting $baseUrl 基础URL 146 | */ 147 | public function MakePrivateUrl($baseUrl){ 148 | $deadline = $this->Expires; 149 | if ($deadline == 0) { 150 | $deadline = 3600; 151 | } 152 | $deadline += time(); 153 | 154 | $pos = strpos($baseUrl, '?'); 155 | if ($pos !== false) { 156 | $baseUrl .= '&e='; 157 | } else { 158 | $baseUrl .= '?e='; 159 | } 160 | $baseUrl .= $deadline; 161 | $token = parent::Sign($baseUrl); 162 | return "$baseUrl&token=$token"; 163 | } 164 | } 165 | ?> -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, and 10 | distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by the copyright 13 | owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all other entities 16 | that control, are controlled by, or are under common control with that entity. 17 | For the purposes of this definition, "control" means (i) the power, direct or 18 | indirect, to cause the direction or management of such entity, whether by 19 | contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the 20 | outstanding shares, or (iii) beneficial ownership of such entity. 21 | 22 | "You" (or "Your") shall mean an individual or Legal Entity exercising 23 | permissions granted by this License. 24 | 25 | "Source" form shall mean the preferred form for making modifications, including 26 | but not limited to software source code, documentation source, and configuration 27 | files. 28 | 29 | "Object" form shall mean any form resulting from mechanical transformation or 30 | translation of a Source form, including but not limited to compiled object code, 31 | generated documentation, and conversions to other media types. 32 | 33 | "Work" shall mean the work of authorship, whether in Source or Object form, made 34 | available under the License, as indicated by a copyright notice that is included 35 | in or attached to the work (an example is provided in the Appendix below). 36 | 37 | "Derivative Works" shall mean any work, whether in Source or Object form, that 38 | is based on (or derived from) the Work and for which the editorial revisions, 39 | annotations, elaborations, or other modifications represent, as a whole, an 40 | original work of authorship. For the purposes of this License, Derivative Works 41 | shall not include works that remain separable from, or merely link (or bind by 42 | name) to the interfaces of, the Work and Derivative Works thereof. 43 | 44 | "Contribution" shall mean any work of authorship, including the original version 45 | of the Work and any modifications or additions to that Work or Derivative Works 46 | thereof, that is intentionally submitted to Licensor for inclusion in the Work 47 | by the copyright owner or by an individual or Legal Entity authorized to submit 48 | on behalf of the copyright owner. For the purposes of this definition, 49 | "submitted" means any form of electronic, verbal, or written communication sent 50 | to the Licensor or its representatives, including but not limited to 51 | communication on electronic mailing lists, source code control systems, and 52 | issue tracking systems that are managed by, or on behalf of, the Licensor for 53 | the purpose of discussing and improving the Work, but excluding communication 54 | that is conspicuously marked or otherwise designated in writing by the copyright 55 | owner as "Not a Contribution." 56 | 57 | "Contributor" shall mean Licensor and any individual or Legal Entity on behalf 58 | of whom a Contribution has been received by Licensor and subsequently 59 | incorporated within the Work. 60 | 61 | 2. Grant of Copyright License. 62 | 63 | Subject to the terms and conditions of this License, each Contributor hereby 64 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 65 | irrevocable copyright license to reproduce, prepare Derivative Works of, 66 | publicly display, publicly perform, sublicense, and distribute the Work and such 67 | Derivative Works in Source or Object form. 68 | 69 | 3. Grant of Patent License. 70 | 71 | Subject to the terms and conditions of this License, each Contributor hereby 72 | grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, 73 | irrevocable (except as stated in this section) patent license to make, have 74 | made, use, offer to sell, sell, import, and otherwise transfer the Work, where 75 | such license applies only to those patent claims licensable by such Contributor 76 | that are necessarily infringed by their Contribution(s) alone or by combination 77 | of their Contribution(s) with the Work to which such Contribution(s) was 78 | submitted. If You institute patent litigation against any entity (including a 79 | cross-claim or counterclaim in a lawsuit) alleging that the Work or a 80 | Contribution incorporated within the Work constitutes direct or contributory 81 | patent infringement, then any patent licenses granted to You under this License 82 | for that Work shall terminate as of the date such litigation is filed. 83 | 84 | 4. Redistribution. 85 | 86 | You may reproduce and distribute copies of the Work or Derivative Works thereof 87 | in any medium, with or without modifications, and in Source or Object form, 88 | provided that You meet the following conditions: 89 | 90 | You must give any other recipients of the Work or Derivative Works a copy of 91 | this License; and 92 | You must cause any modified files to carry prominent notices stating that You 93 | changed the files; and 94 | You must retain, in the Source form of any Derivative Works that You distribute, 95 | all copyright, patent, trademark, and attribution notices from the Source form 96 | of the Work, excluding those notices that do not pertain to any part of the 97 | Derivative Works; and 98 | If the Work includes a "NOTICE" text file as part of its distribution, then any 99 | Derivative Works that You distribute must include a readable copy of the 100 | attribution notices contained within such NOTICE file, excluding those notices 101 | that do not pertain to any part of the Derivative Works, in at least one of the 102 | following places: within a NOTICE text file distributed as part of the 103 | Derivative Works; within the Source form or documentation, if provided along 104 | with the Derivative Works; or, within a display generated by the Derivative 105 | Works, if and wherever such third-party notices normally appear. The contents of 106 | the NOTICE file are for informational purposes only and do not modify the 107 | License. You may add Your own attribution notices within Derivative Works that 108 | You distribute, alongside or as an addendum to the NOTICE text from the Work, 109 | provided that such additional attribution notices cannot be construed as 110 | modifying the License. 111 | You may add Your own copyright statement to Your modifications and may provide 112 | additional or different license terms and conditions for use, reproduction, or 113 | distribution of Your modifications, or for any such Derivative Works as a whole, 114 | provided Your use, reproduction, and distribution of the Work otherwise complies 115 | with the conditions stated in this License. 116 | 117 | 5. Submission of Contributions. 118 | 119 | Unless You explicitly state otherwise, any Contribution intentionally submitted 120 | for inclusion in the Work by You to the Licensor shall be under the terms and 121 | conditions of this License, without any additional terms or conditions. 122 | Notwithstanding the above, nothing herein shall supersede or modify the terms of 123 | any separate license agreement you may have executed with Licensor regarding 124 | such Contributions. 125 | 126 | 6. Trademarks. 127 | 128 | This License does not grant permission to use the trade names, trademarks, 129 | service marks, or product names of the Licensor, except as required for 130 | reasonable and customary use in describing the origin of the Work and 131 | reproducing the content of the NOTICE file. 132 | 133 | 7. Disclaimer of Warranty. 134 | 135 | Unless required by applicable law or agreed to in writing, Licensor provides the 136 | Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, 137 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, 138 | including, without limitation, any warranties or conditions of TITLE, 139 | NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are 140 | solely responsible for determining the appropriateness of using or 141 | redistributing the Work and assume any risks associated with Your exercise of 142 | permissions under this License. 143 | 144 | 8. Limitation of Liability. 145 | 146 | In no event and under no legal theory, whether in tort (including negligence), 147 | contract, or otherwise, unless required by applicable law (such as deliberate 148 | and grossly negligent acts) or agreed to in writing, shall any Contributor be 149 | liable to You for damages, including any direct, indirect, special, incidental, 150 | or consequential damages of any character arising as a result of this License or 151 | out of the use or inability to use the Work (including but not limited to 152 | damages for loss of goodwill, work stoppage, computer failure or malfunction, or 153 | any and all other commercial damages or losses), even if such Contributor has 154 | been advised of the possibility of such damages. 155 | 156 | 9. Accepting Warranty or Additional Liability. 157 | 158 | While redistributing the Work or Derivative Works thereof, You may choose to 159 | offer, and charge a fee for, acceptance of support, warranty, indemnity, or 160 | other liability obligations and/or rights consistent with this License. However, 161 | in accepting such obligations, You may act only on Your own behalf and on Your 162 | sole responsibility, not on behalf of any other Contributor, and only if You 163 | agree to indemnify, defend, and hold each Contributor harmless for any liability 164 | incurred by, or claims asserted against, such Contributor by reason of your 165 | accepting any such warranty or additional liability. 166 | 167 | END OF TERMS AND CONDITIONS 168 | 169 | APPENDIX: How to apply the Apache License to your work 170 | 171 | To apply the Apache License to your work, attach the following boilerplate 172 | notice, with the fields enclosed by brackets "[]" replaced with your own 173 | identifying information. (Don't include the brackets!) The text should be 174 | enclosed in the appropriate comment syntax for the file format. We also 175 | recommend that a file or class name and description of purpose be included on 176 | the same "printed page" as the copyright notice for easier identification within 177 | third-party archives. 178 | 179 | Copyright 2013 LunnLew 180 | 181 | Licensed under the Apache License, Version 2.0 (the "License"); 182 | you may not use this file except in compliance with the License. 183 | You may obtain a copy of the License at 184 | 185 | http://www.apache.org/licenses/LICENSE-2.0 186 | 187 | Unless required by applicable law or agreed to in writing, software 188 | distributed under the License is distributed on an "AS IS" BASIS, 189 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 190 | See the License for the specific language governing permissions and 191 | limitations under the License. 192 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | QiniuSDKForThinkPHP 2 | =================== 3 | 4 | 使用ThinkPHP封装的七牛云存储API 5 | 如何在ThinkPHP中使用 6 | ------------------- 7 | ### 放置位置 8 | 将Cloud文件夹放在ThinkPHP\Extend\Library\ORG目录下,你也可以按需要放在其他地方。 9 | ### 增加配置 10 | 请在框架配置文件中加入下面配置项 11 | 'THINK_SDK_QINIU'=>array( 12 | 'APP_KEY'=>'<你的access key>', 13 | 'APP_SECRET'=>'<你的secret key', 14 | 'DOWN_DOMAIN'=>'<你的资源域>' 15 | ), 16 | ### 使用DEMO 17 | ##### 资源管理接口 18 | 1、查看单个文件属性信息 19 | import('ORG.Cloud.QiniuSDK'); 20 | $Instance = QiniuSDK::getInstance('QiniuRS'); 21 | list($ret, $err) = $Instance->Stat('cdnimg','test.png'); 22 | if ($err !== null) { 23 | var_dump($err); 24 | } else { 25 | var_dump($ret); 26 | } 27 | 2、复制单个文件 28 | import('ORG.Cloud.QiniuSDK'); 29 | $Instance = QiniuSDK::getInstance('QiniuRS'); 30 | list($ret, $err) = $Instance->Copy('cdnimg','test.png','cdnimg','test1.png'); 31 | if ($err !== null) { 32 | var_dump($err); 33 | } else { 34 | var_dump($ret); 35 | } 36 | 3、移动单个文件 37 | import('ORG.Cloud.QiniuSDK'); 38 | $Instance = QiniuSDK::getInstance('QiniuRS'); 39 | list($ret, $err) = $Instance->Move('cdnimg','test.png','cdnimg','test1.png'); 40 | if ($err !== null) { 41 | var_dump($err); 42 | } else { 43 | var_dump($ret); 44 | } 45 | 4、删除单个文件 46 | import('ORG.Cloud.QiniuSDK'); 47 | $Instance = QiniuSDK::getInstance('QiniuRS'); 48 | list($ret, $err) = $Instance->Delete('cdnimg','test.png'); 49 | if ($err !== null) { 50 | var_dump($err); 51 | } else { 52 | var_dump($ret); 53 | } 54 | ##### 上传下载接口 55 | 1、上传字符串 56 | import('ORG.Cloud.QiniuSDK'); 57 | $key1 = "test.png"; 58 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 59 | $Instance->setScope('cdnimg'); 60 | $upToken=$Instance->Token(); 61 | list($ret, $err) = $Instance->Put($upToken, $key1, "Qiniu Storage!"); 62 | if ($err !== null) { 63 | var_dump($err); 64 | } else { 65 | var_dump($ret); 66 | } 67 | 2、上传本地文件 68 | import('ORG.Cloud.QiniuSDK'); 69 | $key1 = "test.txt"; 70 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 71 | $upToken=$Instance->Token(); 72 | list($ret, $err) = $Instance->PutFile($upToken, $key1, __file__, 1); 73 | if ($err !== null) { 74 | var_dump($err); 75 | } else { 76 | var_dump($ret); 77 | } 78 | 3、 公有资源下载 79 | import('ORG.Cloud.QiniuSDK'); 80 | $key = "test.png"; 81 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 82 | $baseurl=$Instance->MakeBaseUrl($key); 83 | 4、私有资源下载 84 | import('ORG.Cloud.QiniuSDK'); 85 | $key = "test.png"; 86 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 87 | $baseurl=$Instance->MakeBaseUrl($key); 88 | $privateurl=$Instance->MakePrivateUrl($baseurl); 89 | ##### 图像处理接口 90 | 1、生成缩略图 91 | import('ORG.Cloud.QiniuSDK'); 92 | $key = "test.png"; 93 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 94 | $baseurl = $Instance->MakeBaseUrl($key); 95 | $Instance = QiniuSDK::getInstance('QiniuImageView'); 96 | $params = array( 97 | 'Mode'=>2, 98 | 'Width'=>50, 99 | 'Height'=>50, 100 | 'Quality'=>70, 101 | 'Format'=>'jpg' 102 | ); 103 | echo $Instance->MakeRequest($baseurl,'imageView',$params); 104 | 2、文字水印 105 | import('ORG.Cloud.QiniuSDK'); 106 | $key = "test.png"; 107 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 108 | $baseurl = $Instance->MakeBaseUrl($key); 109 | $Instance = QiniuSDK::getInstance('QiniuImageView'); 110 | $params = array( 111 | 'WaterMode'=>2, 112 | 'Text'=>'文字水印', 113 | 'Font'=>'宋体', 114 | 'Fill'=>'white', 115 | 'Fontsize'=>1000, 116 | 'Dissolve'=>85, 117 | 'Gravity'=>'SouthEast', 118 | 'Dx'=>10, 119 | 'Dy'=>10 120 | ); 121 | echo $Instance->MakeRequest($baseurl,'watermark',$params); 122 | 3、图片水印 123 | import('ORG.Cloud.QiniuSDK'); 124 | $key = "test.png"; 125 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer'); 126 | $baseurl = $Instance->MakeBaseUrl($key); 127 | $Instance = QiniuSDK::getInstance('QiniuImageView'); 128 | $params = array( 129 | 'WaterMode'=>1, 130 | 'Waterimageurl'=>'http://www.domain.com/water.png', 131 | 'Dissolve'=>50, 132 | 'Gravity'=>'SouthEast', 133 | 'Dx'=>10, 134 | 'Dy'=>10 135 | ); 136 | echo $Instance->MakeRequest($baseurl,'watermark',$params); 137 | #### 媒体资源接口 138 | 1、音频转换 139 | import('ORG.Cloud.QiniuSDK'); 140 | $key = "music.mp3"; 141 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer','cdnimg'); 142 | $params = array( 143 | 'Format'=>'wav', 144 | 'AudioQuality'=>'3', 145 | 'SamplingRate'=>'44100' 146 | ); 147 | $baseurl = $Instance->MakeBaseUrl($key); 148 | $Instance = QiniuSDK::getInstance('QiniuAudioVisual'); 149 | echo $Instance->MakeRequest($baseurl,'avthumb',$params); 150 | 2、视频转换 151 | import('ORG.Cloud.QiniuSDK'); 152 | $key = "test.mp4"; 153 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer','cdnimg'); 154 | $params = array( 155 | 'Format'=>'flv', 156 | 'FrameRate'=>'30', 157 | 'VideoBitRate'=>'256k', 158 | 'Vcodec'=>'ibx264', 159 | 'SamplingRate'=>'22050', 160 | 'BitRate'=>'64k', 161 | 'Acodec'=>'libmp3lame', 162 | ); 163 | $baseurl = $Instance->MakeBaseUrl($key); 164 | $Instance = QiniuSDK::getInstance('QiniuAudioVisual'); 165 | echo $Instance->MakeRequest($baseurl,'avthumb',$params); 166 | 2、视频缩略图 167 | import('ORG.Cloud.QiniuSDK'); 168 | $key = "test.mp4"; 169 | $Instance = QiniuSDK::getInstance('QiniuRSTransfer','cdnimg'); 170 | $params = array( 171 | 'Format'=>'jpg', 172 | 'Offset'=>'7', 173 | 'Width'=>'480', 174 | 'Height'=>'360', 175 | ); 176 | $baseurl = $Instance->MakeBaseUrl($key); 177 | $Instance = QiniuSDK::getInstance('QiniuAudioVisual'); 178 | echo $Instance->MakeRequest($baseurl,'vframe',$params); 179 | --------------------------------------------------------------------------------