Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
数据应用
ThinkLibrary
提交
ad980a71
T
ThinkLibrary
项目概览
数据应用
/
ThinkLibrary
通知
2
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
代码片段
项目成员
Pages
T
ThinkLibrary
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
代码片段
代码片段
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
ad980a71
编写于
6月 06, 2020
作者:
李光春
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
- 增加对象存储
上级
b81ede02
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
408 addition
and
1 deletion
+408
-1
src/config.php
src/config.php
+35
-1
src/service/aliyun/OssService.php
src/service/aliyun/OssService.php
+68
-0
src/service/baidu/BosService.php
src/service/baidu/BosService.php
+98
-0
src/service/huaweicloud/ObsService.php
src/service/huaweicloud/ObsService.php
+100
-0
src/service/tencent/CosService.php
src/service/tencent/CosService.php
+107
-0
未找到文件。
src/config.php
浏览文件 @
ad980a71
...
...
@@ -55,6 +55,13 @@ return [
// 地图
'lbs'
=>
[
'ak'
=>
''
],
// 百度云
'bos'
=>
[
'access_key_id'
=>
''
,
'secret_access_key'
=>
''
,
'endpoint'
=>
''
,
'bucket'
=>
''
,
]
],
// 高德地图
...
...
@@ -100,5 +107,32 @@ return [
// 服务器IP(节点)
'ip'
=>
''
]
]
],
// 阿里云
'aliyun'
=>
[
'oss'
=>
[
'access_key_id'
=>
''
,
'access_key_secret'
=>
''
,
'endpoint'
=>
''
,
'bucket'
=>
''
,
]
],
// 腾讯云
'tencent'
=>
[
'cos'
=>
[
'secret_id'
=>
''
,
'secret_key'
=>
''
,
'region'
=>
''
,
'bucket'
=>
''
,
]
],
// 华为云
'huaweicloud'
=>
[
'obs'
=>
[
'key'
=>
''
,
'secret'
=>
''
,
'endpoint'
=>
''
,
'bucket'
=>
''
,
]
],
];
src/service/aliyun/OssService.php
浏览文件 @
ad980a71
...
...
@@ -17,8 +17,76 @@
namespace
DtApp\ThinkLibrary\service\aliyun
;
use
DtApp\ThinkLibrary\Service
;
use
OSS\Core\OssException
;
use
OSS\OssClient
;
/**
* 阿里云对象存储
* Class OssService
* @package DtApp\ThinkLibrary\service\aliyun
*/
class
OssService
extends
Service
{
private
$accessKeyId
;
private
$accessKeySecret
;
private
$endpoint
;
private
$bucket
;
public
function
accessKeyId
(
string
$accessKeyId
)
{
$this
->
accessKeyId
=
$accessKeyId
;
return
$this
;
}
public
function
accessKeySecret
(
string
$accessKeySecret
)
{
$this
->
accessKeySecret
=
$accessKeySecret
;
return
$this
;
}
public
function
endpoint
(
string
$endpoint
)
{
$this
->
endpoint
=
$endpoint
;
return
$this
;
}
public
function
bucket
(
string
$bucket
)
{
$this
->
bucket
=
$bucket
;
return
$this
;
}
/**
* 获取配置信息
* @return $this
*/
private
function
getConfig
()
{
$this
->
accessKeyId
=
$this
->
app
->
config
->
get
(
'dtapp.aliyun.oss.access_key_id'
);
$this
->
accessKeySecret
=
$this
->
app
->
config
->
get
(
'dtapp.aliyun.oss.access_key_secret'
);
$this
->
endpoint
=
$this
->
app
->
config
->
get
(
'dtapp.aliyun.oss.endpoint'
);
$this
->
bucket
=
$this
->
app
->
config
->
get
(
'dtapp.aliyun.oss.bucket'
);
return
$this
;
}
/**
* 上传文件
* @param $object
* @param $filePath
* @return bool|string
*/
public
function
upload
(
$object
,
$filePath
)
{
if
(
empty
(
$this
->
accessKeySecret
))
$this
->
getConfig
();
if
(
empty
(
$this
->
accessKeySecret
))
$this
->
getConfig
();
if
(
empty
(
$this
->
endpoint
))
$this
->
getConfig
();
if
(
empty
(
$this
->
bucket
))
$this
->
getConfig
();
try
{
$ossClient
=
new
OssClient
(
$this
->
accessKeyId
,
$this
->
accessKeySecret
,
$this
->
endpoint
);
$ossClient
->
uploadFile
(
$this
->
bucket
,
$object
,
$filePath
);
return
true
;
}
catch
(
OssException
$e
)
{
return
$e
->
getMessage
();
}
}
}
src/service/baidu/BosService.php
0 → 100644
浏览文件 @
ad980a71
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace
DtApp\ThinkLibrary\service\baidu
;
use
BaiduBce\Services\Bos\BosClient
;
use
DtApp\ThinkLibrary\Service
;
use
Exception
;
/**
* 百度云对象存储
* Class BosService
* @package DtApp\ThinkLibrary\service\baidu
*/
class
BosService
extends
Service
{
private
$accessKeyId
;
private
$secretAccessKey
;
private
$endpoint
;
private
$bucket
;
public
function
accessKeyId
(
string
$accessKeyId
)
{
$this
->
accessKeyId
=
$accessKeyId
;
return
$this
;
}
public
function
secretAccessKey
(
string
$secretAccessKey
)
{
$this
->
secretAccessKey
=
$secretAccessKey
;
return
$this
;
}
public
function
endpoint
(
string
$endpoint
)
{
$this
->
endpoint
=
$endpoint
;
return
$this
;
}
public
function
bucket
(
string
$bucket
)
{
$this
->
bucket
=
$bucket
;
return
$this
;
}
/**
* 获取配置信息
* @return $this
*/
private
function
getConfig
()
{
$this
->
accessKeyId
=
$this
->
app
->
config
->
get
(
'dtapp.baidu.bos.access_key_id'
);
$this
->
secretAccessKey
=
$this
->
app
->
config
->
get
(
'dtapp.baidu.bos.secret_access_key'
);
$this
->
endpoint
=
$this
->
app
->
config
->
get
(
'dtapp.baidu.bos.endpoint'
);
$this
->
bucket
=
$this
->
app
->
config
->
get
(
'dtapp.baidu.bos.bucket'
);
return
$this
;
}
/**
* 上传文件
* @param $object
* @param $filePath
* @return bool
* @throws Exception
*/
private
function
upload
(
$object
,
$filePath
)
{
if
(
empty
(
$this
->
accessKeyId
))
$this
->
getConfig
();
if
(
empty
(
$this
->
secretAccessKey
))
$this
->
getConfig
();
if
(
empty
(
$this
->
endpoint
))
$this
->
getConfig
();
// 设置BosClient的Access Key ID、Secret Access Key和ENDPOINT
$BOS_TEST_CONFIG
=
array
(
'credentials'
=>
array
(
'accessKeyId'
=>
$this
->
accessKeyId
,
'secretAccessKey'
=>
$this
->
secretAccessKey
,
),
'endpoint'
=>
$this
->
endpoint
,
);
$client
=
new
BosClient
(
$BOS_TEST_CONFIG
);
// 从文件中直接上传Object
if
(
empty
(
$this
->
bucket
))
$this
->
getConfig
();
$client
->
putObjectFromFile
(
$this
->
bucket
,
$object
,
$filePath
);
return
true
;
}
}
src/service/huaweicloud/ObsService.php
0 → 100644
浏览文件 @
ad980a71
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace
DtApp\ThinkLibrary\service\huaweicloud
;
use
DtApp\ThinkLibrary\Service
;
use
Obs\ObsClient
;
/**
* 华为云对象存储
* Class ObsService
* @package DtApp\ThinkLibrary\service\huaweicloud
*/
class
ObsService
extends
Service
{
private
$key
;
private
$secret
;
private
$endpoint
;
private
$bucket
;
public
function
key
(
string
$key
)
{
$this
->
key
=
$key
;
return
$this
;
}
public
function
secret
(
string
$secret
)
{
$this
->
secret
=
$secret
;
return
$this
;
}
public
function
endpoint
(
string
$endpoint
)
{
$this
->
endpoint
=
$endpoint
;
return
$this
;
}
public
function
bucket
(
string
$bucket
)
{
$this
->
bucket
=
$bucket
;
return
$this
;
}
/**
* 获取配置信息
* @return $this
*/
private
function
getConfig
()
{
$this
->
key
=
$this
->
app
->
config
->
get
(
'dtapp.huaweicloud.obs.key'
);
$this
->
secret
=
$this
->
app
->
config
->
get
(
'dtapp.huaweicloud.obs.secret'
);
$this
->
endpoint
=
$this
->
app
->
config
->
get
(
'dtapp.huaweicloud.obs.endpoint'
);
$this
->
bucket
=
$this
->
app
->
config
->
get
(
'dtapp.huaweicloud.obs.bucket'
);
return
$this
;
}
/**
* 上传到华为云
* @param $object
* @param $filePath
* @return bool
*/
private
function
upload
(
$object
,
$filePath
)
{
if
(
empty
(
$this
->
key
))
$this
->
getConfig
();
if
(
empty
(
$this
->
secret
))
$this
->
getConfig
();
if
(
empty
(
$this
->
endpoint
))
$this
->
getConfig
();
// 创建ObsClient实例
$obsClient
=
new
ObsClient
([
'key'
=>
$this
->
key
,
'secret'
=>
$this
->
secret
,
'endpoint'
=>
$this
->
endpoint
]);
if
(
empty
(
$this
->
bucket
))
$this
->
getConfig
();
$resp
=
$obsClient
->
putObject
([
'Bucket'
=>
$this
->
bucket
,
'Key'
=>
$object
,
'SourceFile'
=>
$filePath
// localfile为待上传的本地文件路径,需要指定到具体的文件名
]);
if
(
isset
(
$resp
[
'RequestId'
]))
{
return
true
;
}
else
{
return
false
;
}
}
}
src/service/tencent/CosService.php
0 → 100644
浏览文件 @
ad980a71
<?php
// +----------------------------------------------------------------------
// | ThinkLibrary 6.0 for ThinkPhP 6.0
// +----------------------------------------------------------------------
// | 版权所有 2017~2020 [ https://www.dtapp.net ]
// +----------------------------------------------------------------------
// | 官方网站: https://gitee.com/liguangchun/ThinkLibrary
// +----------------------------------------------------------------------
// | 开源协议 ( https://mit-license.org )
// +----------------------------------------------------------------------
// | gitee 仓库地址 :https://gitee.com/liguangchun/ThinkLibrary
// | github 仓库地址 :https://github.com/GC0202/ThinkLibrary
// | Packagist 地址 :https://packagist.org/packages/liguangchun/think-library
// +----------------------------------------------------------------------
namespace
DtApp\ThinkLibrary\service\tencent
;
use
DtApp\ThinkLibrary\Service
;
use
Exception
;
use
Qcloud\Cos\Client
;
/**
* 腾讯云对象存储
* Class CosService
* @package DtApp\ThinkLibrary\service\tencent
*/
class
CosService
extends
Service
{
private
$secretId
;
private
$secretKey
;
private
$region
;
private
$bucket
;
public
function
secretId
(
string
$secretId
)
{
$this
->
secretId
=
$secretId
;
return
$this
;
}
public
function
secretKey
(
string
$secretKey
)
{
$this
->
secretKey
=
$secretKey
;
return
$this
;
}
public
function
region
(
string
$region
)
{
$this
->
region
=
$region
;
return
$this
;
}
public
function
bucket
(
string
$bucket
)
{
$this
->
bucket
=
$bucket
;
return
$this
;
}
/**
* 获取配置信息
* @return $this
*/
private
function
getConfig
()
{
$this
->
secretId
=
$this
->
app
->
config
->
get
(
'dtapp.tencent.cos.secret_id'
);
$this
->
secretKey
=
$this
->
app
->
config
->
get
(
'dtapp.tencent.cos.secret_key'
);
$this
->
region
=
$this
->
app
->
config
->
get
(
'dtapp.tencent.cos.region'
);
$this
->
bucket
=
$this
->
app
->
config
->
get
(
'dtapp.tencent.cos.bucket'
);
return
$this
;
}
/**
* 上传文件
* @param $object
* @param $filePath
* @return bool
* @throws Exception
*/
private
function
upload
(
$object
,
$filePath
)
{
if
(
empty
(
$this
->
secretId
))
$this
->
getConfig
();
if
(
empty
(
$this
->
secretKey
))
$this
->
getConfig
();
if
(
empty
(
$this
->
region
))
$this
->
getConfig
();
$cosClient
=
new
Client
(
array
(
'region'
=>
$this
->
region
,
'schema'
=>
'http'
,
//协议头部,默认为http
'credentials'
=>
array
(
'secretId'
=>
$this
->
secretId
,
'secretKey'
=>
$this
->
secretKey
)
)
);
$key
=
$object
;
$file
=
fopen
(
$filePath
,
"rb"
);
if
(
$file
)
{
if
(
empty
(
$this
->
bucket
))
$this
->
getConfig
();
$result
=
$cosClient
->
putObject
(
array
(
'Bucket'
=>
$this
->
bucket
,
'Key'
=>
$key
,
'Body'
=>
$file
)
);
}
return
true
;
}
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录