|
|
@ -12,10 +12,10 @@ declare (strict_types=1); |
|
|
|
|
|
|
|
|
|
|
|
namespace app\api\controller; |
|
|
|
namespace app\api\controller; |
|
|
|
|
|
|
|
|
|
|
|
use app\api\service\User as UserService; |
|
|
|
|
|
|
|
use think\response\Json; |
|
|
|
|
|
|
|
use app\api\service\Upload as UploadService; |
|
|
|
use app\api\service\Upload as UploadService; |
|
|
|
|
|
|
|
use app\api\service\User as UserService; |
|
|
|
use app\common\enum\file\FileType as FileTypeEnum; |
|
|
|
use app\common\enum\file\FileType as FileTypeEnum; |
|
|
|
|
|
|
|
use think\response\Json; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* 文件上传管理 |
|
|
|
* 文件上传管理 |
|
|
@ -45,8 +45,29 @@ class Upload extends Controller |
|
|
|
return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成功'); |
|
|
|
return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成功'); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function uploadBase64Image(): Json |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
$base64_file = $this->request->post('file'); // 获取Base64编码的字符串 |
|
|
|
|
|
|
|
$file_info = explode(';', $base64_file); |
|
|
|
|
|
|
|
$file_type_info = explode('/', $file_info[0]); |
|
|
|
|
|
|
|
$file_extension = $file_type_info[1]; // 获取文件扩展名 |
|
|
|
|
|
|
|
$file_data = explode(',', $base64_file)[1]; // 获取Base64编码后的数据 |
|
|
|
|
|
|
|
$file_data = base64_decode($file_data); // 解码Base64数据 |
|
|
|
|
|
|
|
$file_name = uniqid((string)rand(), true) . '.' . $file_extension; // 创建唯一文件名 |
|
|
|
|
|
|
|
$file_path = base_url() . 'temp/' . $file_name; |
|
|
|
|
|
|
|
if (file_put_contents($file_path, $file_data)) { |
|
|
|
|
|
|
|
$service = new UploadService(); |
|
|
|
|
|
|
|
if (!$service->uploadBase64(FileTypeEnum::IMAGE, false, $file_path)) { |
|
|
|
|
|
|
|
return $this->renderError('文件上传失败:' . $service->getError()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
// 图片上传成功 |
|
|
|
|
|
|
|
return $this->renderSuccess(['fileInfo' => $service->getFileInfo()], '文件上传成'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return $this->renderError('文件上传失败'); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function wxUpload(): Json { |
|
|
|
public function wxUpload(): Json |
|
|
|
|
|
|
|
{ |
|
|
|
$checkLogin = $this->request->param('checkLogin'); |
|
|
|
$checkLogin = $this->request->param('checkLogin'); |
|
|
|
// 执行文件上传 |
|
|
|
// 执行文件上传 |
|
|
|
$service = new UploadService(); |
|
|
|
$service = new UploadService(); |
|
|
@ -105,7 +126,8 @@ class Upload extends Controller |
|
|
|
return $this->renderSuccess($result['data'], $result['message']); |
|
|
|
return $this->renderSuccess($result['data'], $result['message']); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function getFileName($imageUrl,$user_id) { |
|
|
|
public function getFileName($imageUrl, $user_id) |
|
|
|
|
|
|
|
{ |
|
|
|
$imageFile = $this->setFileData($imageUrl); |
|
|
|
$imageFile = $this->setFileData($imageUrl); |
|
|
|
$savePath = "./uploads/wxImage/" . date("Y-m-d") . '/'; |
|
|
|
$savePath = "./uploads/wxImage/" . date("Y-m-d") . '/'; |
|
|
|
$fileName = $user_id . '.jpg'; |
|
|
|
$fileName = $user_id . '.jpg'; |
|
|
@ -116,7 +138,8 @@ class Upload extends Controller |
|
|
|
return $savePath . $fileName; |
|
|
|
return $savePath . $fileName; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public function setFileData($image_url) { |
|
|
|
public function setFileData($image_url) |
|
|
|
|
|
|
|
{ |
|
|
|
return file_get_contents($image_url); |
|
|
|
return file_get_contents($image_url); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|