后台:
添加服务逻辑的编辑 接口: 添加服务列表 添加服务详情 添加服务点赞、收藏
This commit is contained in:
@@ -24,6 +24,20 @@ class Aliyun extends Server
|
||||
parent::__construct();
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
/**
|
||||
* 创建并配置 OssClient
|
||||
* @return OssClient
|
||||
*/
|
||||
private function createOssClient()
|
||||
{
|
||||
return new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* 执行上传
|
||||
@@ -33,12 +47,7 @@ class Aliyun extends Server
|
||||
public function upload($save_dir)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
$ossClient = $this->createOssClient();
|
||||
$ossClient->uploadFile(
|
||||
$this->config['bucket'],
|
||||
$save_dir . '/' . $this->fileName,
|
||||
@@ -61,12 +70,7 @@ class Aliyun extends Server
|
||||
public function fetch($url, $key = null)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
$ossClient = $this->createOssClient();
|
||||
|
||||
$content = file_get_contents($url);
|
||||
$ossClient->putObject(
|
||||
@@ -89,12 +93,7 @@ class Aliyun extends Server
|
||||
public function delete($fileName)
|
||||
{
|
||||
try {
|
||||
$ossClient = new OssClient(
|
||||
$this->config['access_key_id'],
|
||||
$this->config['access_key_secret'],
|
||||
$this->config['domain'],
|
||||
true
|
||||
);
|
||||
$ossClient = $this->createOssClient();
|
||||
$ossClient->deleteObject($this->config['bucket'], $fileName);
|
||||
} catch (OssException $e) {
|
||||
$this->error = $e->getMessage();
|
||||
|
||||
Reference in New Issue
Block a user