Exemplo n.º 1
0
 /**
  * 上传文件或者字符串
  * @param array $options 参数数组
  * 必须填写的参数:
  *   bucket_name:资源空间名称
  *   type:操作类型,具体取值如下:
  *     1:上传字符串
  *     2:上传文件
  *     3:上传文件,并将文件名和文件大小回调给业务服务器
  *     4:上传视频,上传完成后进行m3u8的转码,并给视频打水印
  * @return array
  */
 public function uploadFile($options)
 {
     $resArr = ['code' => 0];
     $uploadManager = new UploadManager();
     if ($options['type'] == 1) {
         $token = $this->auth->uploadToken($options['bucket_name']);
         list($res, $err) = $uploadManager->put($token, null, $options['content']);
         if ($err !== null) {
             $resArr['code'] = 2;
             $resArr['message'] = $err->message();
         } else {
             $resArr['data'] = \Jw\Upload\QiNiu\Support\json_decode($res, true);
         }
     } else {
         if ($options['type'] == 2) {
             $token = $this->auth->uploadToken($options['bucket_name']);
             list($res, $err) = $uploadManager->putFile($token, $options['file_name'], $options['save_name']);
             if ($err !== null) {
                 $resArr['code'] = 3;
                 $resArr['message'] = $err->message();
             } else {
                 $resArr['data'] = \Jw\Upload\QiNiu\Support\json_decode($res, true);
             }
         } else {
             if ($options['type'] == 3) {
                 $policy = ['callbackUrl' => $options['callback_url'], 'callbackBody' => 'filename=' . $options['file_name'] . '&filesize=' . $options['file_size']];
                 $token = $this->auth->uploadToken($options['bucket_name'], null, 3600, $policy);
                 list($res, $err) = $uploadManager->putFile($token, null, $options['save_name']);
                 if ($err !== null) {
                     $resArr['code'] = 4;
                     $resArr['message'] = $err->message();
                 } else {
                     $resArr['data'] = \Jw\Upload\QiNiu\Support\json_decode($res, true);
                 }
             } else {
                 if ($options['type'] == 4) {
                     $wmImg = \Jw\Upload\QiNiu\Support\base64_urlSafeEncode($options['water_url']);
                     $pfop = "avthumb/m3u8/wmImage/" . $wmImg;
                     $policy = array('persistentOps' => $pfop, 'persistentNotifyUrl' => $options['notify_url'], 'persistentPipeline' => $options['pipeline']);
                     $token = $this->auth->uploadToken($options['bucket_name'], null, 3600, $policy);
                     list($res, $err) = $uploadManager->putFile($token, null, $options['save_name']);
                     if ($err !== null) {
                         $resArr['code'] = 5;
                         $resArr['message'] = $err->message();
                     } else {
                         $resArr['data'] = \Jw\Upload\QiNiu\Support\json_decode($res, true);
                     }
                 } else {
                     $resArr['code'] = 1;
                     $resArr['message'] = '操作类型不正确';
                 }
             }
         }
     }
     return $resArr;
 }
Exemplo n.º 2
0
 private static function bodyJson($body, array $config = array())
 {
     return \Jw\Upload\QiNiu\Support\json_decode((string) $body, array_key_exists('object', $config) ? !$config['object'] : true, 512, array_key_exists('big_int_strings', $config) ? JSON_BIGINT_AS_STRING : 0);
 }