Commit 1ebb5b3c authored by 刘小敏's avatar 刘小敏

3D试戴 调试11

parent cf1f48d1
...@@ -164,7 +164,7 @@ class AiTryon extends Common ...@@ -164,7 +164,7 @@ class AiTryon extends Common
} else { } else {
// 保存图片到本地 // 保存图片到本地
$aiService = new Ai(); $aiService = new Ai();
$attachment = $aiService->saveFileLoc(isset($res['data']) ? $res['data'] : '', 'gen_ai'); $attachment = $aiService->saveFileLoc(isset($res['data']) ? $res['data'] : '', '.png', 'gen_ai');
// $upload = new Upload(); // $upload = new Upload();
// $attachment = $upload->uploadBase64($res['data']); // $attachment = $upload->uploadBase64($res['data']);
......
...@@ -39,90 +39,6 @@ class AiVideoGen extends BaseJob ...@@ -39,90 +39,6 @@ class AiVideoGen extends BaseJob
} }
/** /**
* 保存远端视频文件到本地
* 暂时无用了
*/
private function saveVideoLoc ($videoUrl){
$this->debug_log('videoUrl: '.$videoUrl);
// 1 生成存储目录(fastadmin标准uploads目录)
$upload_dir = '/uploads/ai_video/' . date('Ymd') . '/';
$dir = $this->public_dir . $upload_dir;
if (!is_dir($dir)) {
mkdir($dir, 0755, true);
}
// 2 生成唯一文件名
$filename = md5(time() . uniqid()) . '.mp4';
$full_path = $this->public_dir . $upload_dir . $filename;
// 3 加载视频地址
$ch = curl_init($videoUrl);
$fp = fopen($full_path, 'wb');
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/120.0.0.0 Safari/537.36');
curl_setopt($ch, CURLOPT_TIMEOUT, 300);
// 4 写入文件
curl_exec($ch);
$error = curl_error($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE); // 获取HTTP状态码
curl_close($ch);
fclose($fp);
// 5 严格判断:网络错误 / HTTP状态码异常 / 文件为空
if ($error || $http_code >= 400 || filesize($full_path) === 0) {
// 下载失败,删除产生的空文件
if (file_exists($full_path)) {
unlink($full_path);
}
$this->debug_log('视频下载失败:' . $error . "HTTP状态码:{$http_code},文件为空");
return 0; // 统一失败返回值
}
if (!file_exists($full_path)) {
return 0;
}
return $upload_dir . $filename;
}
/**
* 删除本地保存的视频文件
* @param string $videoPath 绝对路径(就是 saveVideoLoc 方法返回的路径,如:/uploads/ai_video/20250820/xxx.mp4)
* @return bool 删除成功返回 true,失败/文件不存在返回 false
*/
private function deleteLocalVideo($videoPath)
{
// 拼接完整物理路径(和保存时一致)
$fullPath = $this->public_dir . ltrim($videoPath, '/');
// 1. 判断文件是否存在
if (!file_exists($fullPath)) {
return false;
}
// 2. 判断是否是文件(防止误删目录)
if (!is_file($fullPath)) {
return false;
}
// 3. 尝试删除文件
try {
$deleted = unlink($fullPath);
return $deleted;
} catch (\Exception $e) {
// 删除失败(权限不足、文件被占用等)
return false;
}
}
/**
* AI视频结果处理 * AI视频结果处理
*/ */
public function save(Job $job, $data) public function save(Job $job, $data)
...@@ -196,7 +112,7 @@ class AiVideoGen extends BaseJob ...@@ -196,7 +112,7 @@ class AiVideoGen extends BaseJob
case 'succeeded': case 'succeeded':
// 保存远程视频到本地 // 保存远程视频到本地
$aiService = new Ai(); $aiService = new Ai();
$video_url = $aiService->saveFileLoc(isset($result['content']['video_url']) ? $result['content']['video_url'] : '', 'gen_ai'); $video_url = $aiService->saveFileLoc(isset($result['content']['video_url']) ? $result['content']['video_url'] : '', '.mp4', 'gen_ai');
// $video_url = $this->saveVideoLoc(isset($result['content']['video_url']) ? $result['content']['video_url'] : ''); // $video_url = $this->saveVideoLoc(isset($result['content']['video_url']) ? $result['content']['video_url'] : '');
......
...@@ -60,7 +60,7 @@ class Ai ...@@ -60,7 +60,7 @@ class Ai
* 保存远端文件到本地 * 保存远端文件到本地
* 主要用于3D试戴 2026.05.19 * 主要用于3D试戴 2026.05.19
*/ */
public function saveFileLoc ($file_url, $log_name = 'gen_ai'){ public function saveFileLoc ($file_url, $file_suffix = '.png' ,$log_name = 'gen_ai'){
if (empty($file_url)) { if (empty($file_url)) {
return 0; return 0;
} }
...@@ -76,7 +76,7 @@ class Ai ...@@ -76,7 +76,7 @@ class Ai
} }
// 2 生成唯一文件名 // 2 生成唯一文件名
$filename = md5(time() . uniqid()) . '.mp4'; $filename = md5(time() . uniqid()) . $file_suffix;
$full_path = $this->public_dir . $upload_dir . $filename; $full_path = $this->public_dir . $upload_dir . $filename;
// 3 加载视频地址 // 3 加载视频地址
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment