accessKey = $config['qnoss_access_key']; $this->secretKey = $config['qnoss_secret_key']; $this->bucket = $config['qnoss_bucket']; $this->domain = $config['qnoss_domain']; $this->auth = new Auth($this->accessKey, $this->secretKey); return $this; } public static function instance($config) { if (is_null(self::$instance)) { self::$instance = new static($config); } return self::$instance; } public function save($objectName, $filePath) { $token = $this->auth->uploadToken($this->bucket); $uploadMgr = new UploadManager(); list($result, $error) = $uploadMgr->putFile($token, $objectName, $filePath); if ($error !== null) { return [ 'save' => false, 'msg' => '保存失败', ]; } else { return [ 'save' => true, 'msg' => '上传成功', 'url' => $this->domain . '/' . $result['key'], ]; } } }