AiVideoController.php
2.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
<?php
/**
* @remark :
* @name :AiVideoController.php
* @author :lyh
* @method :post
* @time :2025/8/2 11:18
*/
namespace App\Http\Controllers\Api;
use App\Enums\Common\Code;
use App\Models\Project\AiVideoAutoLog;
use App\Services\CosService;
use Illuminate\Support\Facades\Redis;
class AiVideoController extends BaseController
{
/**
* @remark :回调方法
* @name :ImageCallBack
* @author :lyh
* @method :post
* @time :2025/8/2 11:19
*/
public function ImageCallBack(){
$this->saveLog('数据详情:'.json_encode($this->param,true));
$count = Redis::decr('ai_video_image');
if ($count < 0) {
Redis::set('ai_video_image', 0);
}
$data = $this->param['attachments'][0] ?? [];
$aiVideoAutoLogModel = new AiVideoAutoLog();
if(empty($data) || empty($data['url'])){
$this->saveLog('未获取到回调数据详情');
$aiVideoAutoLogModel->edit(['status'=>9,'result'=>json_encode($this->param,true)],['trigger_id'=>$this->param['id']]);
}
//获取当前数据详情
$info = $aiVideoAutoLogModel->read(['trigger_id'=>$this->param['id']]);
if($info === false){
$this->saveLog('未获取到当前数据详情。'.$info);
$this->response('success');
}
//上传图片 返回cdn链接
$cosService = new CosService();
$imagePath = $cosService->uploadRemote($info['project_id'],'video',$data['url']);
$this->saveLog($imagePath);
try {
if($imagePath){
$cos = config('filesystems.disks.cos');
$url = $cos['cdn1'].'/'.$imagePath;
//裁剪图片为4张
$images = [];
$cosService = new CosService();
$data = $cosService->cropAndUploadToCOS($url);
if(!empty($data)){
foreach ($data as $item){
$images[] = ['url'=>$item,'alt'=>''];
}
}
$images = array_merge($images,$info['images']);
$this->saveLog('返回的数据详情。'.$images);
$aiVideoAutoLogModel->edit(['images'=>$images,'result'=>json_encode($this->param,true),'status'=>1],['id'=>$info['id']]);
}
}catch (\Exception $e){
$this->saveLog('上传图片失败,获取到数据详情。'.$e->getMessage());
}
$this->response('success');
}
/**
* @remark :保存日志
* @name :saveLog
* @author :lyh
* @method :post
* @time :2025/8/4 11:54
*/
public function saveLog($message){
@file_put_contents(storage_path('logs/ai_video.log'), var_export($message, true) . PHP_EOL, FILE_APPEND);
return true;
}
}