作者 lyh

列表页聚合页模式

@@ -51,9 +51,9 @@ class lyhDemo extends Command @@ -51,9 +51,9 @@ class lyhDemo extends Command
51 // $content = "{Introducing the cutting-edge product from Zhejiang Yuexiang Gas Technology Co., Ltd., the Bracket Gas Flowmeter. This innovative gas flowmeter is designed to provide accurate and reliable measurements for a wide range of industrial applications,Equipped with advanced technology and precision components, the Bracket Gas Flowmeter ensures exceptional performance and durability. It offers highly accurate gas flow readings, allowing users to closely monitor and control gas consumption in various processes. The meter's user-friendly interface displays real-time flow rates and totalized flow data, facilitating efficient and convenient data management,With its robust construction and corrosion-resistant materials, the Bracket Gas Flowmeter guarantees long-term reliability, even in harsh operating conditions. It is compatible with various gases such as natural gas, propane, and hydrogen, making it a versatile choice for multiple industries including oil and gas, chemical, and manufacturing,Furthermore, the Bracket Gas Flowmeter is engineered with ease of installation and maintenance in mind. Its compact and space-saving design allows for flexible mounting options, while its modular construction enables quick and hassle-free maintenance. Additionally, it meets international standards for accuracy and safety, ensuring compliance with industry regulations,Choose the Bracket Gas Flowmeter for precise and efficient gas flow measurement, backed by the expertise and commitment of Zhejiang Yuexiang Gas Technology Co., Ltd},{Shop Quality Brackets: Top China Products & Services for Your Needs},4K,高清 --no logo --ar 16:9"; 51 // $content = "{Introducing the cutting-edge product from Zhejiang Yuexiang Gas Technology Co., Ltd., the Bracket Gas Flowmeter. This innovative gas flowmeter is designed to provide accurate and reliable measurements for a wide range of industrial applications,Equipped with advanced technology and precision components, the Bracket Gas Flowmeter ensures exceptional performance and durability. It offers highly accurate gas flow readings, allowing users to closely monitor and control gas consumption in various processes. The meter's user-friendly interface displays real-time flow rates and totalized flow data, facilitating efficient and convenient data management,With its robust construction and corrosion-resistant materials, the Bracket Gas Flowmeter guarantees long-term reliability, even in harsh operating conditions. It is compatible with various gases such as natural gas, propane, and hydrogen, making it a versatile choice for multiple industries including oil and gas, chemical, and manufacturing,Furthermore, the Bracket Gas Flowmeter is engineered with ease of installation and maintenance in mind. Its compact and space-saving design allows for flexible mounting options, while its modular construction enables quick and hassle-free maintenance. Additionally, it meets international standards for accuracy and safety, ensuring compliance with industry regulations,Choose the Bracket Gas Flowmeter for precise and efficient gas flow measurement, backed by the expertise and commitment of Zhejiang Yuexiang Gas Technology Co., Ltd},{Shop Quality Brackets: Top China Products & Services for Your Needs},4K,高清 --no logo --ar 16:9";
52 // $midJourneyService = new MidJourneyService(); 52 // $midJourneyService = new MidJourneyService();
53 // $result = $midJourneyService->imagine($content); 53 // $result = $midJourneyService->imagine($content);
54 - $url = 'https://mjcdn.ttapi.io/attachments/1400347301465165925/1401115681872805918/opalguardian295705_Introducing_the_cutting-edge_product_from_Zh_47ba54d3-f711-43d1-b50e-d6a1d2e743e3.png?ex=688f1a2a&is=688dc8aa&hm=2413d13f40f9023a97804024ed1e526f24fe7573208c9b0660f42da9cdd4d306&'; 54 + $url = 'https://ecdn6-nc.globalso.com/upload/p/1/png/2025-08/688dcebc26a7a59911.png';
55 $cosService = new CosService(); 55 $cosService = new CosService();
56 - $data = $cosService->uploadRemote(1,'png',$url); 56 + $data = $cosService->cropAndUploadToCOS($url);
57 dd($data); 57 dd($data);
58 } 58 }
59 59
@@ -11,6 +11,8 @@ namespace App\Http\Controllers\Api; @@ -11,6 +11,8 @@ namespace App\Http\Controllers\Api;
11 11
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
13 use App\Models\Project\AiVideoAutoLog; 13 use App\Models\Project\AiVideoAutoLog;
  14 +use App\Services\CosService;
  15 +use Illuminate\Support\Facades\Log;
14 16
15 class AiVideoController extends BaseController 17 class AiVideoController extends BaseController
16 { 18 {
@@ -24,11 +26,21 @@ class AiVideoController extends BaseController @@ -24,11 +26,21 @@ class AiVideoController extends BaseController
24 public function ImageCallBack(){ 26 public function ImageCallBack(){
25 $data = $this->param['attachments'] ?? []; 27 $data = $this->param['attachments'] ?? [];
26 $aiVideoAutoLogModel = new AiVideoAutoLog(); 28 $aiVideoAutoLogModel = new AiVideoAutoLog();
27 - if(empty($data)){  
28 - $aiVideoAutoLogModel->edit(['status'=>9],['trigger_id'=>$this->param['id']]); 29 + if(empty($data) || empty($data['url'])){
  30 + $aiVideoAutoLogModel->edit(['status'=>9,'result'=>json_encode($this->param,true)],['trigger_id'=>$this->param['id']]);
  31 + }
  32 + //获取当前数据详情
  33 + $info = $aiVideoAutoLogModel->read(['trigger_id'=>$this->param['id']]);
  34 + if($info === false){
  35 + Log::channel('ai_video')->info('当前数据不存在或已被删除'.$this->param['id']);
  36 + }
  37 + $cosService = new CosService();
  38 + $imagePath = $cosService->uploadRemote(1,'video',$data['url']);
  39 + if($imagePath){
  40 + //裁剪图片为4张
  41 + }else{
  42 + Log::channel('ai_video')->info('上传图片失败');
29 } 43 }
30 - $url = 'https://mjcdn.ttapi.io/attachments/1400347301465165925/1401115681872805918/opalguardian295705_Introducing_the_cutting-edge_product_from_Zh_47ba54d3-f711-43d1-b50e-d6a1d2e743e3.png?ex=688f1a2a&is=688dc8aa&hm=2413d13f40f9023a97804024ed1e526f24fe7573208c9b0660f42da9cdd4d306&';  
31 - @file_put_contents(storage_path('logs/lyh_error.log'), var_export($data, true) . PHP_EOL, FILE_APPEND);  
32 44
33 $this->response('success'); 45 $this->response('success');
34 } 46 }
@@ -376,4 +376,75 @@ class CosService @@ -376,4 +376,75 @@ class CosService
376 } 376 }
377 return []; 377 return [];
378 } 378 }
  379 +
  380 + /**
  381 + * @remark :ai_video裁剪图片为4张
  382 + * @name :cropAndUploadToCOS
  383 + * @author :lyh
  384 + * @method :post
  385 + * @time :2025/8/2 16:52
  386 + */
  387 + public function cropAndUploadToCOS($imageUrl)
  388 + {
  389 + // 1. 下载远程图片内容
  390 + $imageData = file_get_contents($imageUrl);
  391 + if (!$imageData) {
  392 + return false;
  393 + }
  394 + // 2. 保存原图到临时文件
  395 + $tempOriginal = tempnam(sys_get_temp_dir(), 'original_') . '.png';
  396 + file_put_contents($tempOriginal, $imageData);
  397 + // 3. 使用 GD 加载图像
  398 + $src = imagecreatefrompng($tempOriginal);
  399 + if (!$src) {
  400 + return false;
  401 + }
  402 + $width = imagesx($src);
  403 + $height = imagesy($src);
  404 + $halfWidth = intval($width / 2);
  405 + $halfHeight = intval($height / 2);
  406 + // 4. 从原图 URL 提取路径信息
  407 + $parsed = parse_url($imageUrl);
  408 + $pathInfo = pathinfo($parsed['path']); // upload/p/1/png/2025-08/688dcebc26a7a59911.png
  409 + $cosPath = ltrim($pathInfo['dirname'], '/'); // 相对路径:upload/p/1/png/2025-08
  410 + $baseName = $pathInfo['filename']; // 文件名:688dcebc26a7a59911
  411 + $ext = $pathInfo['extension'] ?? 'png'; // 扩展名
  412 + // 5. 初始化 COS 客户端
  413 + $cos = config('filesystems.disks.cos');
  414 + $cosClient = new Client([
  415 + 'region' => $cos['region'],
  416 + 'credentials' => [
  417 + 'secretId' => $cos['credentials']['secretId'],
  418 + 'secretKey' => $cos['credentials']['secretKey'],
  419 + ],
  420 + ]);
  421 + // 6. 循环裁剪并上传
  422 + $resultPaths = [];
  423 + $index = 0;
  424 + for ($y = 0; $y < 2; $y++) {
  425 + for ($x = 0; $x < 2; $x++) {
  426 + $crop = imagecreatetruecolor($halfWidth, $halfHeight);
  427 + imagecopy($crop, $src, 0, 0, $x * $halfWidth, $y * $halfHeight, $halfWidth, $halfHeight);
  428 + $tempCropped = tempnam(sys_get_temp_dir(), 'crop_') . '.png';
  429 + imagepng($crop, $tempCropped);
  430 + imagedestroy($crop);
  431 + // 新文件名,保持路径不变
  432 + $filename = $baseName . '_part' . $index++ . '.' . $ext;
  433 + $objectKey = $cosPath . '/' . $filename;
  434 + // 上传到 COS
  435 + $cosClient->putObject([
  436 + 'Bucket' => $cos['bucket'],
  437 + 'Key' => $objectKey,
  438 + 'Body' => fopen($tempCropped, 'rb'),
  439 + ]);
  440 + // 返回相对路径
  441 + $resultPaths[] = $objectKey;
  442 + unlink($tempCropped);
  443 + }
  444 + }
  445 + // 清理资源
  446 + imagedestroy($src);
  447 + unlink($tempOriginal);
  448 + return $resultPaths; // 相对路径数组
  449 + }
379 } 450 }