126 lines
3.0 KiB
PHP
Executable File
126 lines
3.0 KiB
PHP
Executable File
<?php
|
|
|
|
# @Author: 嗨噜客(三亚) <fm453>
|
|
# @Date: 2022-05-18T16:51:48+08:00
|
|
# @Email: fm453@lukegzs.com
|
|
# @Last modified by: fm453
|
|
# @Last modified time: 2022-05-21T00:20:34+08:00
|
|
# @Copyright: www.hiluker.cn
|
|
|
|
namespace vendor\huawei\obsclient;
|
|
|
|
// 引入依赖库
|
|
require('vendor/autoload.php');
|
|
require('obs-autoloader.php');
|
|
|
|
use Obs\ObsClient;
|
|
use Obs\ObsException;
|
|
use GuzzleHttp\Client;
|
|
use function GuzzleHttp\json_encode;
|
|
|
|
class Common
|
|
{
|
|
protected $ak = '';
|
|
protected $sk = '';
|
|
protected $endpoint = '';
|
|
protected $obsClient;
|
|
public $objectKey = 'my-obs-object-key-demo';
|
|
public $signature = 'obs';
|
|
public function __construct($ak, $sk, $endpoint, $socket_timeout=30, $connect_timeout=10)
|
|
{
|
|
$this->ak = $ak;
|
|
$this->sk = $sk;
|
|
$this->endpoint = $endpoint;
|
|
}
|
|
|
|
public function result($msg, $data, $code)
|
|
{
|
|
return [
|
|
'code'=>$code,
|
|
'msg'=>$msg,
|
|
'data'=>$data
|
|
];
|
|
}
|
|
|
|
public function doAction($msg, $method, $url, $content=null, $headers=null)
|
|
{
|
|
global $httpClient;
|
|
$httpClient = new Client(['verify' => false]);
|
|
try {
|
|
$response = $httpClient -> request($method, $url, ['body' => $content, 'headers'=> $headers]);
|
|
$response -> getBody()-> close();
|
|
return [
|
|
'code'=>200,
|
|
'msg'=>$msg,
|
|
'data'=>[
|
|
'status'=>$response -> getStatusCode(),
|
|
'content'=>$response -> getBody() -> getContents()
|
|
]
|
|
];
|
|
} catch (ClientException $ex) {
|
|
return [
|
|
'code'=>100,
|
|
'msg'=>$ex ->getMessage(),
|
|
];
|
|
}
|
|
}
|
|
}
|
|
|
|
//----bucket related apis---
|
|
// CreateBucket();
|
|
// ListBuckets();
|
|
// DeleteBucket();
|
|
// ListObjects();
|
|
// ListVersions();
|
|
// HeadBucket();
|
|
// GetBucketMetadata();
|
|
// GetBucketLocation();
|
|
// GetBucketStorageInfo();
|
|
// SetBucketQuota();
|
|
// GetBucketQuota();
|
|
// SetBucketStoragePolicy();
|
|
// GetBucketStoragePolicy();
|
|
// SetBucketAcl();
|
|
// GetBucketAcl();
|
|
// SetBucketLogging();
|
|
// GetBucketLogging();
|
|
// SetBucketPolicy();
|
|
// GetBucketPolicy();
|
|
// DeleteBucketPolicy();
|
|
// SetBucketLifecycle();
|
|
// GetBucketLifecycle();
|
|
// DeleteBucketLifecycle();
|
|
// SetBucketWebsite();
|
|
// GetBucketWebsite();
|
|
// DeleteBucketWebsite();
|
|
// SetBucketVersioning();
|
|
// GetBucketVersioning();
|
|
// SetBucketCors();
|
|
// GetBucketCors();
|
|
// DeleteBucketCors();
|
|
// OptionsBucket();
|
|
// SetBucketTagging();
|
|
// GetBucketTagging();
|
|
// DeleteBucketTagging();
|
|
// SetBucketNotification();
|
|
// GetBucketNotification();
|
|
|
|
//-----object related apis--------
|
|
// DeleteObject();
|
|
// OptionsObject();
|
|
// SetObjectAcl();
|
|
// GetObjectAcl();
|
|
// RestoreObject();
|
|
// DeleteObjects();
|
|
// PutObject();
|
|
// GetObject();
|
|
// CopyObject();
|
|
// GetObjectMetadata();
|
|
// InitiateMultipartUpload();
|
|
// ListMultipartUploads();
|
|
// AbortMultipartUpload();
|
|
// UploadPart();
|
|
// ListParts();
|
|
// CompleteMultipartUpload();
|
|
// CopyPart();
|