123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150 |
- <?php
- namespace app\adminall\controller;
- use OSS\Core\OssException;
- use OSS\OssClient;
- class Ueditor
- {
- public function index($action)
- {
- if (method_exists($this, $action)) {
- return $this->$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);
- }
- }
|