作者 lyh

Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6

... ... @@ -456,11 +456,11 @@ if (!function_exists('getImageUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getImageUrl($path,$location = 1){
function getImageUrl($path,$location = 0,$storage_type = 0){
if(is_array($path)){
$url =[];
foreach ($path as $v){
$url[] = getImageUrl($v);
$url[] = getImageUrl($v,$location,$storage_type);
}
}else{
if(empty($path)){
... ... @@ -472,9 +472,9 @@ if (!function_exists('getImageUrl')) {
if(substr($path,0,2) == '//'){
return 'https:'.$path;
}
if($location == 1){
if($location == 0){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
$url = $cosCdn.$path;
}else{
$url = url($path);
... ... @@ -483,6 +483,7 @@ if (!function_exists('getImageUrl')) {
return $url;
}
}
if (!function_exists('getFileUrl')) {
/**
* @remark :获取文件链接
... ... @@ -491,11 +492,11 @@ if (!function_exists('getFileUrl')) {
* @method :post
* @time :2023/7/20 16:46
*/
function getFileUrl($path,$location = 1){
function getFileUrl($path,$location = 0,$storage_type = 0){
if(is_array($path)){
$url =[];
foreach ($path as $v){
$url[] = getFileUrl($v);
$url[] = getFileUrl($v,$location,$storage_type);
}
}else{
if(empty($path)){
... ... @@ -507,9 +508,9 @@ if (!function_exists('getFileUrl')) {
if(substr($path,0,2) == '//'){
return 'https:'.$path;
}
if($location == 1){
if($location == 0){
$cos = config('filesystems.disks.cos');
$cosCdn = $cos['cdn'];
$cosCdn = ($storage_type == 0) ? $cos['cdn'] : $cos['cdn1'];
$url = $cosCdn.$path;
}else{
$url = url($path);
... ...
... ... @@ -38,7 +38,7 @@ class BlogController extends BaseController
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['url'] = $this->user['domain'] . getRouteMap(RouteMap::SOURCE_BLOG,$v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['operator_name'] = $user->getName($v['operator_id']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_BLOG,BTemplate::IS_DETAIL,$template_id,$v['id']);
$lists['list'][$k] = $v;
... ... @@ -186,10 +186,8 @@ class BlogController extends BaseController
'id.required' => 'ID不能为空'
]);
$info = $blogLogic->blogInfo();
$template_id = $this->getTemplateId(BTemplate::SOURCE_BLOG,BTemplate::IS_DETAIL);
$info['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_BLOG,BTemplate::IS_DETAIL,$template_id, $info['id']);
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -37,7 +37,7 @@ class CustomModuleContentController extends BaseController
$data = $this->getAllCategoryName();
foreach ($lists['list'] as $k=>$v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['operator_name'] = (new User())->getName($v['operator_id']);
$lists['list'][$k] = $v;
}
... ...
... ... @@ -41,7 +41,7 @@ class NewsController extends BaseController
foreach ($lists['list'] as $k => $v){
$v['category_name'] = $this->categoryName($v['category_id'],$data);
$v['url'] = $this->user['domain'].getRouteMap(RouteMap::SOURCE_NEWS,$v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['operator_name'] = $user->getName($v['operator_id']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL,$template_id,$v['id']);
$lists['list'][$k] = $v;
... ... @@ -175,10 +175,8 @@ class NewsController extends BaseController
'id.required' => 'ID不能为空',
]);
$info = $newsLogic->newsInfo();
$template_id = $this->getTemplateId(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL);//获取模版id
$info['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_NEWS,BTemplate::IS_DETAIL,$template_id, $info['id']);
$this->response('success',Code::SUCCESS,$info);
}
... ...
... ... @@ -41,7 +41,7 @@ class CategoryController extends BaseController
foreach ($list as $k =>$v){
$v['url'] = $this->user['domain'] . $v['route'].'/';
$v['product_num'] = Category::getProductNum($v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_LIST,$template_id,$v['id']);
$list[$k] = $v;
}
... ...
... ... @@ -56,11 +56,12 @@ class ProductController extends BaseController
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);//获取模版id
$userModel = new User();
foreach ($lists['list'] as $k=>$v){
$v['url'] = $this->user['domain'].$v['route'].'/';
$v['category_id_text'] = $this->categoryName($v['category_id'],$cate_data);
$v['keyword_id_text'] = $this->keywordName($v['keyword_id'],$key_data);
$v['created_uid_text'] = $userModel->getName($v['created_uid']);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id']);
$v['url'] = $this->user['domain'].$v['route'].'/';
$v = $this->getHandleFileImage($v);
$lists['list'][$k] = $v;
}
}
... ... @@ -68,7 +69,40 @@ class ProductController extends BaseController
}
/**
* @remark :处理列表返回参数
* @remark :获取时处理图片和文件
* @name :getHandleFileImage
* @author :lyh
* @method :post
* @time :2024/1/23 17:43
*/
public function getHandleFileImage($v){
//ToDo::处理图片及文件
if(!empty($v['thumb']) && !empty($v['thumb']['url'])){
$v['thumb']['url'] = getImageUrl($v['thumb']['url'],$this->user['project_location'],$this->user['storage_type']);
}
if(!empty($v['gallery'])){
foreach ($v['gallery'] as $gallery_k => $gallery_v){
$gallery_v['url'] = getImageUrl($gallery_v['url'],$this->user['project_location'],$this->user['storage_type']);
$v['gallery'][$gallery_k] = $gallery_v;
}
}
if(!empty($v['icon'])){
foreach ($v['icon'] as $icon_k => $icon_v){
$icon_v = getImageUrl($icon_v,$this->user['project_location'],$this->user['storage_type']);
$v['icon'][$icon_k] = $icon_v;
}
}
if(!empty($v['video']) && !empty($v['video']['url'])){
$v['video']['url'] = getImageUrl($v['video']['url'],$this->user['project_location'],$this->user['storage_type']);
}
if(!empty($v['files']) && !empty($v['files']['url'])){
$v['files']['url'] = getImageUrl($v['files']['url'],$this->user['project_location'],$this->user['storage_type']);
}
return $this->success($v);
}
/**
* @remark :搜索参数处理
* @name :handleReturnParam
* @author :lyh
* @method :post
... ... @@ -243,6 +277,8 @@ class ProductController extends BaseController
}else{
$v['status_text'] = '';
}
//ToDo::处理图片及文件
$v = $this->getHandleFileImage($v);
$template_id = $this->getTemplateId(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL);
$v['is_renovation'] = $this->getIsRenovation(BTemplate::SOURCE_PRODUCT,BTemplate::IS_DETAIL,$template_id,$v['id'] ?? 0);
$v['url'] = $this->user['domain'].$v['route'];
... ... @@ -251,6 +287,7 @@ class ProductController extends BaseController
return $v;
}
/**
* @remark :获取扩展字段详情
* @name :getExtendInfo
... ... @@ -293,7 +330,7 @@ class ProductController extends BaseController
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url']);
$v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
... ... @@ -302,9 +339,9 @@ class ProductController extends BaseController
foreach ($arr1 as $k1=>$v1){
$v1 = (array)$v1;
if(isset($v1['url'])){
$v1['url'] = getFileUrl($v1['url']);
$v1['url'] = getFileUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
}else{
$v1 = getFileUrl($v1);
$v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
}
$arr1[$k1] = $v1;
}
... ...
... ... @@ -25,7 +25,7 @@ class WebSettingImageController extends BaseController
public function lists(WebSettingImage $webSettingImage){
$list = $webSettingImage->list([],'id',['id','image','type']);
foreach ($list as $k=>$v){
$v['image'] = getImageUrl($v['image']);
$v['image'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$list[$k] = $v;
}
$this->response('success',Code::SUCCESS,$list);
... ...
... ... @@ -22,7 +22,7 @@ class BTemplateController extends BaseController
$lists = $BTemplateLogic->publicTemplateLists($this->map,$this->page,$this->row,$this->order);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => &$v){
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
$lists['list'][$k] = $v;
}
}
... ...
... ... @@ -5,6 +5,7 @@ namespace App\Http\Controllers\File;
use App\Enums\Common\Code;
use App\Models\File\File;
use App\Models\Project\Project;
use App\Services\AmazonS3Service;
use App\Services\CosService;
use Illuminate\Http\Exceptions\HttpResponseException;
use Illuminate\Http\JsonResponse;
... ... @@ -121,14 +122,13 @@ class FileController
$url = $this->config['root'].$this->path;
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
//同步数据到cos
if($this->upload_location == 1){
if($this->upload_location == 0){
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$res = $files->move($url,$fileName);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
$this->saveMysql($fileModel,$files->getSize(),$files->getClientOriginalExtension(),$fileName,$hash,$this->upload_location,$files->getMimeType(),$name);
$this->response('资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
... ... @@ -165,7 +165,9 @@ class FileController
$cosService = new CosService();
$cosService->uploadFile($files, $this->path, $fileName);
} else {
$res = $files->move($url, $fileName);
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$res = $amazonS3Service->uploadFiles($files,$this->path,$fileName);
if ($res === false) {
return [
'message' => $files->getError(),
... ... @@ -196,7 +198,7 @@ class FileController
'hash' => $hash,
'type'=>$image_type,
'refer'=>$this->param['refer'] ?? 1,
'is_cos'=>$is_cos,
'is_cos'=>($is_cos == 0) ? 1 : 0,
'mime'=>$mime,
'project_id'=>$this->cache['project_id'] ?? 0,
'name'=>$name,
... ... @@ -234,14 +236,13 @@ class FileController
$file_type = $file->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$file_type;
//同步数据到cos
if($this->upload_location == 1){
if($this->upload_location == 0){
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$res = $files->move($url,$fileName);
if ($res === false) {
return $this->response($files->getError(), Code::USER_ERROR);
}
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
$size = $file->getSize();
$mime = $file->getMimeType();
... ... @@ -313,7 +314,7 @@ class FileController
$projectModel = new Project();
$project_info = $projectModel->read(['id' => $this->cache['project_id']], ['project_location']);
if ($project_info['project_location'] != 0) {//通项目时 上传到cos
$this->upload_location = 0;//1:上传到本地
$this->upload_location = 1;//1:上传到本地
}
}
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->file_type[$this->param['refer']].'/'.date('Y-m');
... ... @@ -335,7 +336,7 @@ class FileController
$fileModel = new File();
$lists = $fileModel->list($this->map,'id',['id','hash','type','path','created_at','name']);
foreach ($lists as $k => $v){
$v['file_link'] = getFileUrl($v['path']);
$v['file_link'] = getFileUrl($v['path'],$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0);
$lists[$k] = $v;
}
$this->response('success',Code::SUCCESS,$lists);
... ... @@ -351,7 +352,7 @@ class FileController
public function responseData($path, $name){
$data = [
'file'=>$path,
'file_link'=>getFileUrl($path,$this->upload_location),
'file_link'=>getFileUrl($path,$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0),
'name'=>$name,
'file_download'=>url('a/download_files?path='.$path)
];
... ...
... ... @@ -7,6 +7,7 @@ use App\Http\Controllers\Controller;
use App\Http\Controllers\type;
use App\Models\File\Image as ImageModel;
use App\Models\Project\Project;
use App\Services\AmazonS3Service;
use App\Services\CosService;
use App\Services\TencentCosService;
use Illuminate\Http\Exceptions\HttpResponseException;
... ... @@ -36,7 +37,7 @@ class ImageController extends Controller
public $upload_location = 1;//是否同步到cos
public $upload_location = 0;//同步到cos
//上传图片类型
public $image_type = [
1 => 'image_product',
... ... @@ -200,11 +201,13 @@ class ImageController extends Controller
}
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
//上传到cos
if($this->upload_location == 1){
if($this->upload_location == 0){
$cosService = new CosService();
$cosService->uploadFile($files,$this->path,$fileName);
}else{
$files->move($url,$fileName);
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
$this->saveMysql($imageModel,$files->getSize(),$image_type,$fileName,$hash,$this->upload_location,$files->getMimeType(), $name);
return $this->response('图片资源',Code::SUCCESS,$this->responseData($this->path.'/'.$fileName, $name));
... ... @@ -225,7 +228,7 @@ class ImageController extends Controller
'hash' => $hash,
'type'=>$image_type,
'refer'=>$this->param['refer'] ?? 0,
'is_cos'=>$is_cos,
'is_cos'=>($is_cos == 0) ? 1 : 0,
'mime'=>$mime,
'project_id'=>$this->cache['project_id'] ?? 0,
'name'=>$name,
... ... @@ -278,11 +281,13 @@ class ImageController extends Controller
$image_type = $file->getClientOriginalExtension();
$fileName = uniqid().rand(10000,99999).'.'.$image_type;
//同步数据到cos
if($this->upload_location == 1){
if($this->upload_location == 0){
$cosService = new CosService();
$cosService->uploadFile($file,$this->path,$fileName);
}else{
$file->move($url,$fileName);
//TODO::上传亚马逊
$amazonS3Service = new AmazonS3Service();
$amazonS3Service->uploadFiles($files,$this->path,$fileName);
}
//批量存储
$this->saveMysql($imageModel,$file->getSize(),$image_type,$fileName,$hash,$this->upload_location,$file->getMimeType(),$name);
... ... @@ -359,7 +364,7 @@ class ImageController extends Controller
$lists = $imageModel->lists($this->map,$this->page,$this->row);
if(!empty($lists) && !empty($lists['list'])){
foreach ($lists['list'] as $k => $v){
$v['image_link'] = getImageUrl($v['path']);
$v['image_link'] = getImageUrl($v['path'],$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0);
$lists['list'][$k] = $v;
}
}
... ... @@ -408,7 +413,7 @@ class ImageController extends Controller
$projectModel = new Project();
$project_info = $projectModel->read(['id'=>$this->cache['project_id']],['project_location']);
if ($project_info['project_location'] != 0) {//危险项目时 上传到本地
$this->upload_location = 0;//上传到cos
$this->upload_location = 1;//上传到本地
}
}
$this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m');
... ... @@ -425,7 +430,7 @@ class ImageController extends Controller
public function responseData($path = '', $name = ''){
$data = [
'image'=>$path,
'image_link'=>getImageUrl($path),
'image_link'=>getImageUrl($path,$this->cache['project_location'] ?? 0,$this->cache['storage_type'] ?? 0),
'name'=>$name,
'image_download'=>url('a/download_images?path='.$path)
];
... ...
... ... @@ -101,7 +101,7 @@ class BlogLogic extends BaseLogic
//获取标签名称
$blogLabelLogic = new BlogLabelLogic();
$info['label_name'] = $blogLabelLogic->getLabelName($info['label_id']);
$info['image_link'] = getImageUrl($info['image']);
$info['image_link'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
return $this->success($info);
}
... ...
... ... @@ -39,7 +39,7 @@ class CustomModuleContentLogic extends BaseLogic
if($info === false){
$this->fail('当前数据不存在或已被删除');
}
$info['image'] = getImageUrl($info['image']);
$info['image'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
$info['extend'] = $this->getExtendInfo($info['module_id'],$info['id']);
return $this->success($info);
}
... ... @@ -86,14 +86,14 @@ class CustomModuleContentLogic extends BaseLogic
$arr = json_decode($info['values']);
foreach ($arr as $k1=>$v1){
$v1 = (array)$v1;
$v1['url'] = getImageUrl($v1['url']);
$v1['url'] = getImageUrl($v1['url'],$this->user['project_location'],$this->user['storage_type']);
$arr[$k1] = $v1;
}
$v['values'] = $arr;
}elseif($v['type'] == 4){
$arr1 = json_decode($info['values']);
foreach ($arr1 as $k1=>$v1){
$v1 = getFileUrl($v1);
$v1 = getFileUrl($v1,$this->user['project_location'],$this->user['storage_type']);
$arr1[$k1] = $v1;
}
$v['values'] = $arr1;
... ...
... ... @@ -147,7 +147,7 @@ class NewsLogic extends BaseLogic
$this->fail('error');
}
$info['category_id'] = explode(',',trim($info['category_id'],','));
$info['image_link'] = getImageUrl($info['image']);
$info['image_link'] = getImageUrl($info['image'],$this->user['project_location'],$this->user['storage_type']);
return $this->success($info);
}
... ...
... ... @@ -32,7 +32,7 @@ class CategoryLogic extends BaseLogic
foreach ($data as &$v){
$v['url'] = $this->user['domain'] . $v['route'] ;
$v['product_num'] = Category::getProductNum($v['id']);
$v['image_link'] = getImageUrl($v['image']);
$v['image_link'] = getImageUrl($v['image'],$this->user['project_location'],$this->user['storage_type']);
}
if(!$map){
$data = Arr::listToTree($data);
... ...
... ... @@ -171,6 +171,8 @@ class UserLoginLogic
$info['main_lang_id'] = $project['main_lang_id'];
$info['image_max'] = $project['image_max'];
$info['uptime'] = $project['uptime'];
$info['storage_type'] = $project['storage_type'];
$info['project_location'] = $project['project_location'];
$info['is_update_language'] = $project['is_update_language'];
$info['configuration'] = $project['deploy_build']['configuration'];
$info['project_type'] = $project['type'];
... ... @@ -213,6 +215,8 @@ class UserLoginLogic
$info['is_update_language'] = $project['is_update_language'];
$info['configuration'] = $project['deploy_build']['configuration'];
$info['project_type'] = $project['type'];
$info['storage_type'] = $project['storage_type'];
$info['project_location'] = $project['project_location'];
if($info['is_customized'] == 1){
$info['is_visualization'] = json_decode($project['is_visualization']);
}
... ...
... ... @@ -102,51 +102,9 @@ class Product extends Base
3=>'热销产品'
];
/**
* 产品列表
* @param $map
* @param $page
* @param $row
* @param string $order
* @param string[] $fields
* @param string $sort
* @return array
* @author zbj
* @date 2023/10/17
*/
public function product_lists($map, $page, $row, $order = 'id', $fields = ['*'], $sort = 'desc'): array
{
$category_id = $map['category_id'] ?? 0;
$query = $this->where(function ($query) use ($category_id) {
if ($category_id) {
$category_ids = Category::getChildIdsArr($category_id);
$query->whereIn('id', function ($subQuery) use ($category_ids) {
$subQuery->select('product_id')
->from('gl_product_category_related')
->whereIn('cate_id', $category_ids)
->groupBy('product_id');
});
}
});
unset($map['category_id']);
$query = $this->formatQuery($map, $query);
$query = $this->sortOrder($query,$order,$sort);
$lists = $query->select($fields)->paginate($row, ['*'], 'page', $page);
if (empty($lists)) {
return [];
}
$lists = $lists->toArray();
return $lists;
}
public function getThumbAttribute($value){
if(!empty($value)){
$value = json_decode($value,true);
if(!empty($value['url'])){
$value['url'] = getImageUrl($value['url']);
}
$value = Arr::s2a($value);
}
return $value;
}
... ... @@ -155,12 +113,6 @@ class Product extends Base
public function getGalleryAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
if(!empty($v['url'])){
$v['url'] = getImageUrl($v['url']);
}
$value[$k] = $v;
}
}
return $value;
}
... ... @@ -175,9 +127,6 @@ class Product extends Base
public function getFilesAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
if(!empty($value['url'])){
$value['url'] = getImageUrl($value['url']);
}
}
return $value;
}
... ... @@ -192,10 +141,6 @@ class Product extends Base
public function getVideoAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
$value = Arr::s2a($value);
if(!empty($value['url'])){
$value['url'] = getImageUrl($value['url']);
}
}
return $value;
}
... ... @@ -210,10 +155,6 @@ class Product extends Base
public function getIconAttribute($value){
if(!empty($value)){
$value = Arr::s2a($value);
foreach ($value as $k => $v){
$v = getImageUrl($v);
$value[$k] = $v;
}
}
return $value;
}
... ...
... ... @@ -15,10 +15,10 @@ class AmazonS3Service
{
// 替换为你自己的 AWS 访问密钥、区域和存储桶名称
protected $s3;
protected $accessKeyId = '';//key
protected $secretAccessKey = '';//密匙
protected $region = '';//地址
protected $bucket = '';//桶子
protected $accessKeyId = 'AKIAU6YKND7SAWIKBXCZ';//key
protected $secretAccessKey = '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';//密匙
protected $region = 's3://arn:aws:s3:us-west-2:340934860772:accesspoint/globalso-v6';//地址
protected $bucket = 'arn:aws:s3:::globalso-v6';//桶子
public function __construct()
{
... ... @@ -40,13 +40,15 @@ class AmazonS3Service
* @method :post
* @time :2024/1/23 9:20
*/
public function uploadFiles($localFilePath, $s3Key)
public function uploadFiles(&$files, $s3Key,$filename ,$binary = false)
{
$key = $s3Key.'/'.$filename;
$Body = $binary ? $files : fopen($files->getRealPath(), 'r');
try {
$result = $this->s3->putObject([
'Bucket' => $this->bucket,
'Key' => $s3Key,
'SourceFile' => $localFilePath,
'Key' => $key,
'SourceFile' => $Body,
'ACL' => 'public-read', // 设置图片为公共可读,可根据需求修改
]);
return $result['ObjectURL'];
... ...
... ... @@ -78,6 +78,7 @@ return [
],
'bucket' => env('COS_BUCKET'),
'cdn' => env('COS_CDN'),
'cdn1' => env('COS_CDN1'),
'timeout' => 60,
'connect_timeout' => 60,
],
... ...