Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
L
loveisland
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘小敏
loveisland
Commits
056d3466
Commit
056d3466
authored
Apr 30, 2026
by
刘小敏
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
AI试戴生成视频队列文件
parent
c4c76bf1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
161 additions
and
0 deletions
+161
-0
AiVideoGen.php
addons/shopro/job/AiVideoGen.php
+161
-0
No files found.
addons/shopro/job/AiVideoGen.php
0 → 100644
View file @
056d3466
<?php
namespace
addons\shopro\job
;
use
addons\shopro\library\activity\getter\Db
;
use
addons\shopro\library\HttpClient
as
Http
;
use
app\admin\model\shopro\AiTryon
as
AiTryOnModel
;
use
think\Log
;
use
think\queue\Job
;
//use think\Db;
//use think\exception\HttpResponseException;
//use app\admin\model\shopro\order\Order;
//use addons\shopro\service\StockSale;
//use app\admin\model\shopro\user\User;
//use app\admin\model\shopro\order\Invoice as OrderInvoice;
//use addons\shopro\service\order\OrderOper;
//use addons\shopro\facade\Activity as ActivityFacade;
/**
* 订单自动操作
*/
class
AiVideoGen
extends
BaseJob
{
// 火山引擎方舟配置
private
$ark_host
=
'https://ark.cn-beijing.volces.com'
;
private
function
saveVideoLoc
(
$videoUrl
){
// 1生成存储目录(fastadmin标准uploads目录)
$public_dir
=
ROOT_PATH
.
'public'
;
$upload_dir
=
'/uploads/ai_video/'
.
date
(
'Ymd'
)
.
'/'
;
$dir
=
$public_dir
.
$upload_dir
;
if
(
!
is_dir
(
$dir
))
{
mkdir
(
$dir
,
0755
,
true
);
}
// 2 生成唯一文件名
$filename
=
md5
(
time
()
.
uniqid
())
.
'.mp4'
;
$full_path
=
$public_dir
.
$upload_dir
.
$filename
;
// 视频地址
$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
);
curl_exec
(
$ch
);
$error
=
curl_error
(
$ch
);
curl_close
(
$ch
);
fclose
(
$fp
);
// 5. 检查是否下载成功
if
(
$error
)
{
return
0
;
}
if
(
!
file_exists
(
$full_path
))
{
return
0
;
}
return
$upload_dir
.
$filename
;
}
/**
* AI视频结果存
*/
public
function
save
(
Job
$job
,
$data
)
{
try
{
// 保存远程视频到本地
// $videoUrl = "https://ark-content-generation-cn-beijing.tos-cn-beijing.volces.com/doubao-seedance-1-5-pro/02177754334120900000000000000000000ffffac15a695855f2b.mp4?X-Tos-Algorithm=TOS4-HMAC-SHA256&X-Tos-Credential=AKLTYWJkZTExNjA1ZDUyNDc3YzhjNTM5OGIyNjBhNDcyOTQ%2F20260430%2Fcn-beijing%2Ftos%2Frequest&X-Tos-Date=20260430T100229Z&X-Tos-Expires=86400&X-Tos-Signature=c50b93d2f98c3865b9ac4a2bb5607f9c3dba01d516f8d20f496285a09b04e9d7&X-Tos-SignedHeaders=host";
$taskid
=
$data
[
'taskid'
];
// $taskid = 'cgt-20260430184545-tghsw';
$user
=
$data
[
'user'
];
// echo "===== begin queue ai video save =====" . PHP_EOL;
$url
=
$this
->
ark_host
.
'/api/v3/contents/generations/tasks/'
.
$taskid
;
echo
'url: '
.
$url
.
PHP_EOL
;
$params
=
[
'headers'
=>
[
'Authorization'
=>
'Bearer '
.
config
(
'shopro.ai_api_key'
),
'Content-Type'
=>
'application/json'
],
'verify'
=>
false
,
// 关闭 SSL 证书验证
'allow_redirects'
=>
true
];
// 发送请求
$client
=
new
Http
();
$response
=
$client
->
get
(
$url
,
$params
);
// echo 'response:';
// print_r($response);
$content
=
$response
->
getBody
()
->
getContents
();
$content
=
trim
(
$content
);
$content
=
preg_replace
(
'/[^\x20-\x7E]/'
,
''
,
$content
);
$result
=
json_decode
(
$content
,
true
);
// 失败
if
(
isset
(
$result
[
'error'
])){
$code
=
$result
[
'error'
][
'code'
]
??
''
;
$message
=
$result
[
'error'
][
'message'
]
??
'未知错误'
;
AiTryOnModel
::
where
(
'user_id'
,
$user
[
'id'
])
->
where
(
'ai_task_id'
,
$taskid
)
->
update
([
'ai_status'
=>
2
,
'ai_err_msg'
=>
$message
]);
// 记录错误日志
Log
::
error
(
'AI生成视频队列返回:taskId: '
.
$taskid
.
'code '
.
$code
.
'message: '
.
$message
.
' result:'
.
$content
.
PHP_EOL
);
}
if
(
isset
(
$result
[
'status'
])){
switch
(
$result
[
'status'
])
{
case
'succeeded'
:
// 保存远程视频到本地
$video_url
=
$this
->
saveVideoLoc
(
isset
(
$result
[
'content'
][
'video_url'
])
?
$result
[
'content'
][
'video_url'
]
:
''
);
echo
'--video_url--'
;
var_dump
(
$video_url
);
if
(
$video_url
===
0
){
AiTryOnModel
::
where
(
'user_id'
,
$user
[
'id'
])
->
where
(
'ai_task_id'
,
$taskid
)
->
update
([
'ai_status'
=>
2
,
'ai_err_msg'
=>
'视频保存到本地失败'
]);
break
;
}
// 更新我的试戴
AiTryOnModel
::
where
(
'user_id'
,
$user
[
'id'
])
->
where
(
'ai_task_id'
,
$taskid
)
->
update
([
'ai_status'
=>
1
,
'ai_url'
=>
$video_url
]);
// echo 'sql:' . PHP_EOL;
// print_r( db()->getLastSql() );
break
;
case
'cancelled'
:
case
'failed'
:
case
'expired'
:
AiTryOnModel
::
where
(
'user_id'
,
$user
[
'id'
])
->
where
(
'ai_task_id'
,
$taskid
)
->
update
([
'ai_status'
=>
2
,
'ai_err_msg'
=>
'视频生成失败'
]);
// Log::error('AI生成视频队列返回:taskId: ' . $taskid . 'code '.$code . 'message: ' . $message . ' result:' . $content . PHP_EOL);
break
;
case
'queued'
:
case
'running'
:
break
;
}
}
// echo "===== End queue ai video save =====" . PHP_EOL ;
// Log::info('用户ID:'. $user .' AI生成视频接口返回:'.json_encode($result));
// 删除 job
$job
->
delete
();
}
catch
(
\Exception
$e
)
{
// echo '---------------save video Exception---------------------'.PHP_EOL;
// print_r($e->getMessage());
// echo '---------------save video Exception---------------------'.PHP_EOL;
// 队列执行失败
format_log_error
(
$e
,
'AiVideoGen.save'
);
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment