accessKey = $accessKey; return $this; } public function secretKey(string $secretKey) { $this->secretKey = $secretKey; return $this; } public function bucket(string $bucket) { $this->bucket = $bucket; return $this; } /** * 获取配置信息 * @return $this */ private function getConfig() { $this->accessKey = config('dtapp.qiniu.kodo.access_key'); $this->secretKey = config('dtapp.qiniu.kodo.secret_key'); $this->bucket = config('dtapp.qiniu.kodo.bucket'); return $this; } /** * 上传文件 * @param $object * @param $filePath * @return bool * @throws Exception */ public function upload(string $object, string $filePath) { if (empty($this->accessKey) || empty($this->secretKey) || empty($this->bucket)) { $this->getConfig(); } // 初始化签权对象 $auth = new Auth($this->accessKey, $this->secretKey); // 生成上传Token $token = $auth->uploadToken($this->bucket); // 构建 UploadManager 对象 $uploadMgr = new UploadManager(); // 调用 UploadManager 的 putFile 方法进行文件的上传。 [$ret, $err] = $uploadMgr->putFile($token, $object, $filePath); if ($err !== null) { return false; } return config('dtapp.qiniu.kodo.url', '') . $object; } }