$action(); } else { return; } } /** * 文件上传配置 */ public function config() { return json(config('ueditor')); } /** * 图片抓取 */ public function catchimage() { $list = array(); $request = request(); $source = $request->param('source'); $accessKeyId = config('app.ali_oss_access_key_id'); $accessKeySecret = config('app.ali_oss_access_key_secret'); $endpoint = config('app.ali_oss_end_point'); $bucket = config('app.ali_oss_bucket'); $bucketUrl = config('app.ali_oss_bindurl'); $oss = new OssClient($accessKeyId, $accessKeySecret, $endpoint); $list = []; try { foreach ($source as $imgUrl) { $ext = pathinfo($imgUrl, PATHINFO_EXTENSION); if (empty($ext)) { $query = parse_url($imgUrl, PHP_URL_QUERY); parse_str($query, $urlParam); if (isset($urlParam['wx_fmt'])) { $ext = $urlParam['wx_fmt']; } else { array_push($list, [ "state" => '文件类型获取失败', "url" => '', "size" => '', "title" => '', "original" => '', "source" => $imgUrl ]); continue; } } // 判断文件格式 if(!in_array($ext, ['png','PNG','jpg','JPG', 'jpeg','JPEG', 'bmp','BMP', 'gif',"GIF","WEBP", 'webp', 'psd',"PSD", 'svg', 'tiff'])){ array_push($list, [ "state" => '文件类型不支持', "url" => '', "size" => '', "title" => '', "original" => '', "source" => $imgUrl ]); continue; } $content = file_get_contents($imgUrl); $size = strlen($content); $path = 'wxcontent' . DIRECTORY_SEPARATOR . date('Ymd') . DIRECTORY_SEPARATOR . time() . rand(1000, 9999) . '.' . $ext; $oss->putObject($bucket, $path, $content); array_push($list, array( "state" => 'SUCCESS', "url" => 'https://' . $bucketUrl . '/' . $path, "size" => $size, "title" => '', "original" => '', "source" => $imgUrl )); } } catch (OssException $e) { trace($e, 'error'); } return json(['state' => 'SUCCESS', 'list' => $list]); } /** * 文件上传 */ public function uploadimage() { $url = request()->param('upfile'); $bucketUrl = config('app.ali_oss_bindurl'); $data = [ 'original' => "", 'size' => '', 'state' => "SUCCESS", 'title' => "", 'type' => "", 'url' => 'https://' . $bucketUrl . '/' . $url, ]; return json($data); } /** * 涂鸦图片上传 */ public function uploadscrawl() { $url = request()->param('upfile'); $bucketUrl = config('app.ali_oss_bindurl'); $data = [ 'original' => "", 'size' => '', 'state' => "SUCCESS", 'title' => "", 'type' => "", 'url' => 'https://' . $bucketUrl . '/' . $url, ]; return json($data); } public function uploadvideo() { $url = request()->param('upfile'); $bucketUrl = config('app.ali_oss_bindurl'); $data = [ 'original' => "", 'size' => '', 'state' => "SUCCESS", 'title' => "", 'type' => "", 'url' => 'https://' . $bucketUrl . '/' . $url, ]; return json($data); } }