_endpoint = Config::get('OSS_ENDPOINT'); $this->_accessKeyId = Config::get('OSS_ACCESS_KEY_ID'); $this->_accessKeySecret = Config::get('ACCESS_KEY_SECRET'); $this->setBucketName(!empty($bucket) ? $bucket : Config::get('ALIYUN_OSS_BUCKET')); if (is_file(EXTEND_PATH.'OSS/autoload.php')) { require_once EXTEND_PATH.'OSS/autoload.php'; } $this->getOssClient(); } /** * 切换OSS Bucket * @param string $bucketName */ public function setBucketName(string $bucketName) { $this->_bucket = $bucketName; } public function getBucketName() { return $this->_bucket; } /** * 根据Config配置,得到一个OssClient实例 * @return OssClient */ public function getOssClient() { if (empty($this->_ossClient)) { try { $this->_ossClient = new OssClient($this->_accessKeyId, $this->_accessKeySecret, $this->_endpoint, false); } catch (Exception $e) { throw new RuntimeException($e->getMessage()); } } return $this->_ossClient; } }