作者 李宇航

合并分支 'lyh-server' 到 'master'

Lyh server



查看合并请求 !3297
... ... @@ -1642,5 +1642,16 @@ if (!function_exists('httpGetSsl')) {
return $truncated;
}
/**
* @remark :写入日志
* @name :outMessage
* @author :lyh
* @method :post
* @time :2025/11/20 16:04
*/
function outMessage($filename = 'lyh_info',$message = '')
{
@file_put_contents(storage_path('logs/'.$filename.'.log'), "上传失败: " . $message . PHP_EOL, FILE_APPEND);
return true;
}
}
... ...
... ... @@ -232,7 +232,7 @@ class IndexController extends BaseController
public function prInfoDownload()
{
$url = 'http://crawl.scraper.waimaoq.com/export/issuewire?token=MT0CM7y4tdFTFTm';
$response = Http::get($url,['page'=>$this->param['page'],'pagesize'=>$this->param['row']]);
$response = Http::get($url,['page'=>$this->page,'pagesize'=>$this->row]);
if ($response->successful()) {
$result = $response->json();
}
... ...
... ... @@ -207,11 +207,14 @@ class ImageController extends Controller
if($this->upload_location == 0){
$watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName,false,$watermarkOptions);
$res = $cosService->uploadFile($files,$this->path,$fileName,false,$watermarkOptions);
}else{
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
$res = $amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
if($res === false){
$this->response('上传失败,请重新上传',Code::SYSTEM_ERROR);
}
$this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name);
$this->synchronizationImage($fileName,$this->upload_location);
... ... @@ -354,11 +357,15 @@ class ImageController extends Controller
if($this->upload_location == 0){
$watermarkOptions = $this->getProjectConfig($this->cache['project_id'] ?? 0);
$cosService = new CosService();
$cosService->uploadFile($file,$this->path,$fileName,false,$watermarkOptions);
$res = $cosService->uploadFile($file,$this->path,$fileName,false,$watermarkOptions);
}else{
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($file,$this->path,$fileName);
$res = $amazonS3Service->uploadFiles($file,$this->path,$fileName);
}
if($res === false){
outMessage('upload_images','文件上传失败'.$name);
continue;
}
$this->synchronizationImage($fileName,$this->upload_location);
$data[] = $this->responseData($this->path.'/'.$fileName,$name);
... ...
... ... @@ -24,7 +24,7 @@ class CosService
* @method :post
* @time :2023/7/19 15:28
*/
public function uploadFile(&$files,$path,$filename, $binary = false,$watermarkOptions = '')
public function uploadFile(&$files, $path, $filename, $binary = false, $watermarkOptions = '')
{
$cos = config('filesystems.disks.cos');
$cosClient = new Client([
... ... @@ -34,7 +34,9 @@ class CosService
'secretKey' => $cos['credentials']['secretKey'],
],
]);
$key = $path.'/'.$filename;
$key = $path . '/' . $filename;
// 判断是否为 Base64 编码的图片流文件
if (Str::startsWith($files, 'data:image')) {
// 分离 Base64 头部和数据部分
... ... @@ -42,33 +44,56 @@ class CosService
// 解码 Base64 数据
$Body = base64_decode($base64Data);
if ($Body === false) {
throw new \Exception("Base64 数据解码失败");
outMessage('upload_images',"解码失败");
return false;
}
} else {
// 如果不是 Base64 流文件,处理为普通文件上传
$Body = $binary ? $files : fopen($files->getRealPath(), 'r');
try {
$Body = $binary ? $files : fopen($files->getRealPath(), 'r');
// 检查文件是否有效
if (!$Body) {
outMessage('upload_images',"文件打开失败");
return false;
}
} catch (\Exception $e) {
outMessage('upload_images',"文件处理失败: " . $e->getMessage());
return false;
}
}
$options = [
'Bucket' => $cos['bucket'],
'Key' => $key,
'Body' => $Body,
];
//水印
if ($watermarkOptions) {
$options['PicOperations'] = json_encode([
'is_pic_info' => 1,
'rules' => [
[
'fileid' => $key, // 使用相同的文件名保存
'rule' => $watermarkOptions,
try {
$options = [
'Bucket' => $cos['bucket'],
'Key' => $key,
'Body' => $Body,
];
// 水印处理
if ($watermarkOptions) {
$options['PicOperations'] = json_encode([
'is_pic_info' => 1,
'rules' => [
[
'fileid' => $key, // 使用相同的文件名保存
'rule' => $watermarkOptions,
]
]
]
], true);
], true);
}
$cosClient->putObject($options);
} catch (\Exception $e) {
// 记录上传失败日志
outMessage('upload_images',$e->getMessage());
return false;
} finally {
// 确保非二进制模式下关闭文件资源
if (!$binary && is_resource($Body)) {
fclose($Body);
}
}
$res = $cosClient->putObject($options);
return $key;
}
/**
* @param $image_name
* @remark :获取图片访问链接
... ...