public static function uploadFile($tmpName, $sourceInfo) { $uploadUrlCacheName = 'uploadCtUrlCacheName'; $uploadUrlCacheTime = 'uploadCtUrlCacheTime'; $lastUrl = RDS::get($uploadUrlCacheName); $getUrl = true; if($lastUrl) { $lastTime = RDS::get($uploadUrlCacheTime); if($lastTime > time()-6000) { $getUrl = false; } } $fileSize = $sourceInfo['size']; if($getUrl) { $getUploadUrl = 'https://rest.ctfile.com/v1/public/file/upload'; $res = File::post_nr($getUploadUrl, [ "session"=> "城通网盘身份", //城通网盘->设置->开发接口设置->获取token 'folder_id' => 56881979,//城通网盘保存的文件夹id 'checksum' => hash_file('md5', $tmpName),//文件hash 'size' => $fileSize, 'name' => 'test.jpg', ]); $data_ = json_decode($res, 1); if($data_['code'] != 200) { throw new \Exception($data_['message']); } $upload_url = $data_['upload_url']; RDS::set($uploadUrlCacheName, $upload_url); RDS::set($uploadUrlCacheTime, time()); } else { $upload_url = $lastUrl; } // echo $upload_url .'|'; $res = File::formFilePost2($upload_url, $sourceInfo); if(is_array($res) && isset($res['msg'])) { throw new \Exception($res['msg']); } $fileId = $res; }