getBody()->getContents(); $queries = $request->getQueryParams(); $method = $request->getMethod(); $headers = $request->getHeaders(); $path = $request->getAttribute('path'); $requestURI = $request->getAttribute('requestURI'); $clientIP = $request->getAttribute('clientIP'); */ $queries = $request->getQueryParams(); $path = $queries['path']; if(strlen($path)<2) { return new Response( 200, array( 'custom_header1' => 'v1', 'custom_header2' => ['v2', 'v3'], 'Content-Type' => 'text/plain', ), json_encode([ 'msg' => 'errorPath:'.$path ]) ); } $path = trim($path, '/') .'/'; $accessKeyId = $context["credentials"]["accessKeyId"]; $accessKeySecret = $context["credentials"]["accessKeySecret"]; $securityToken = $context["credentials"]["securityToken"]; $endpoint = "oss-cn-hongkong.aliyuncs.com"; $ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint, false, $securityToken); $bucket = "kapianwang"; $keys = []; $savePicPath = '/tmp/'; $ramdonName_ = MD5($path); //清除之前下载的临时文件 $clearLocalPath = function()use($savePicPath , $ramdonName_) { foreach (glob($savePicPath. $ramdonName_ .'/*') as $start_file) { unlink($start_file); } }; try { $zip= new Zip(); $zip::creatdir($savePicPath . $ramdonName_); $saveZipPath = $savePicPath . $ramdonName_ .'/download.zip'; $array_ = explode('/', rtrim($path, '/')); $lastAlbumId = end($array_); if(!$lastAlbumId) throw new \Exception('nolastAlbumId:'. $path); array_pop($array_); $pathUp = join('/', $array_); $remoteZipPath = ltrim($pathUp, '/') . '/packet_'. $lastAlbumId .'.zip'; $fileList = $zip::scanDir($path, $bucket, $ossClient); foreach($fileList as $key_) { $fileContent = $ossClient->getObject($bucket, $key_); $array_ = explode('/', $key_); $fileName_ = end($array_); file_put_contents($savePicPath . $ramdonName_ . '/'. $fileName_ , $fileContent); } $status = $zip->zip($saveZipPath, $savePicPath); $ossClient->uploadFile($bucket, $remoteZipPath, $saveZipPath); } catch (\Exception $e) { $clearLocalPath(); return new Response( 200, array( 'custom_header1' => 'v1', 'custom_header2' => ['v2', 'v3'], 'Content-Type' => 'text/plain', ), $e->getMessage() ); } $clearLocalPath(); return new Response( 200, array( 'custom_header1' => 'v1', 'custom_header2' => ['v2', 'v3'], 'Content-Type' => 'text/plain', ), json_encode([ 'msg' => 'success' ]) ); }