初始化项目:添加后端代码、ThinkPHP框架、前端资源
This commit is contained in:
@@ -0,0 +1,136 @@
|
||||
<?php
|
||||
|
||||
namespace app\callback\controller;
|
||||
use app\common\model\live\Room;
|
||||
/**
|
||||
* 直播回调
|
||||
*/
|
||||
class Live
|
||||
{
|
||||
/**
|
||||
* 阿里云视频点播HTTP回调回调鉴权
|
||||
* @return bool
|
||||
*/
|
||||
public function checkVodCallbackAuth(){
|
||||
|
||||
$timestamp = request()->header('X-VOD-TIMESTAMP');
|
||||
$signature = request()->header('X-VOD-SIGNATURE');
|
||||
|
||||
$callbackUrl = \app\common\library\live\Url::getCallbackUrl();
|
||||
|
||||
$vodConfig = \app\common\model\config\System::getConfig('alivod');
|
||||
$authKey = $vodConfig['auth_key'];
|
||||
|
||||
if(md5($callbackUrl."|".$timestamp."|".$authKey) != $signature){
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 直播回放录制文件回调接口
|
||||
* 这里回调分为两种
|
||||
* 一个是阿里云直播自动录制中在OSS录制中设置的回调接口 用$backData接收
|
||||
* 另一种是在视频点播中设置的回调接口 用@$postData 参数接受
|
||||
* @return void
|
||||
*/
|
||||
public function playback(){
|
||||
|
||||
$uniacid = input('i');
|
||||
$postData = input('post.');
|
||||
|
||||
\think\Log::info('playback data:'.json_encode($postData));
|
||||
|
||||
if(isset($postData['oss_bucket'])){
|
||||
return 'error_no_vod_data';
|
||||
}
|
||||
|
||||
if(isset($postData['EventType']) && isset($postData['VideoId'])){
|
||||
$sourceType = 'alivod';
|
||||
}else{
|
||||
$sourceType = 'alioss';
|
||||
}
|
||||
|
||||
if($sourceType == 'alioss' && (!isset($postData['push_args']) || !isset($postData['push_args']['callback_record_key']))){
|
||||
return 'error_no_data';
|
||||
}
|
||||
|
||||
if($sourceType == 'alivod'){
|
||||
if(!$this->checkVodCallbackAuth()){
|
||||
return 'false_fail_auth';
|
||||
}
|
||||
if($postData['EventType'] != 'AddLiveRecordVideoComplete'){
|
||||
return 'error_event_type';
|
||||
}
|
||||
|
||||
$roomCondition = [
|
||||
'stream_name'=>$postData['StreamName'],
|
||||
'uniacid'=>$uniacid
|
||||
];
|
||||
}else{
|
||||
$roomCondition = [
|
||||
'live_record_key'=>$postData['push_args']['callback_record_key'],
|
||||
'uniacid'=>$uniacid
|
||||
];
|
||||
}
|
||||
|
||||
$roomData = \app\common\model\live\Room::where($roomCondition)->find();
|
||||
|
||||
if(!$roomData){
|
||||
return 'error_no_room';
|
||||
}
|
||||
|
||||
//写入回放视频列表
|
||||
if($sourceType == 'alivod'){
|
||||
$playbackCondition = [
|
||||
'course_id'=>$roomData['course_id'],
|
||||
'file_path'=>'<alivod>'.$postData['VideoId'].'</alivod>'
|
||||
];
|
||||
}else{
|
||||
$playbackCondition = [
|
||||
'file_path'=>'/'.$postData['uri'],
|
||||
'course_id'=>$roomData['course_id'],
|
||||
];
|
||||
}
|
||||
|
||||
if(\app\common\model\live\Playback::where($playbackCondition)->find()){
|
||||
return 'error_repeat';
|
||||
}
|
||||
|
||||
$data = [
|
||||
'uniacid'=>$roomData['uniacid'],
|
||||
'course_id'=>$roomData['course_id'],
|
||||
'status'=>1,
|
||||
'createtime'=>time()
|
||||
];
|
||||
|
||||
if($sourceType == 'alivod'){
|
||||
$data['start_time'] = strtotime($postData['RecordStartTime']);
|
||||
$data['end_time'] = strtotime($postData['RecordEndTime']);
|
||||
}else{
|
||||
$data['start_time'] = $postData['start_time'];
|
||||
$data['end_time'] = $postData['stop_time'];
|
||||
}
|
||||
$data['file_name'] = date('h:i',$data['start_time']) . '~' . date('h:i',$data['end_time'])."录制";
|
||||
|
||||
|
||||
$data['source'] = $sourceType;
|
||||
|
||||
if($sourceType == 'alioss'){
|
||||
$data['file_path'] = '/'.$postData['uri'];
|
||||
}else{
|
||||
$data['file_path'] = '<alivod>'.$postData['VideoId'].'</alivod>';
|
||||
$vodConfig = \app\common\model\config\System::getConfig('alivod');
|
||||
if($vodConfig && $vodConfig['status'] == 'open'){
|
||||
try{
|
||||
\addons\alivod\library\Alivod::submitTranscodeJobs($postData['VideoId'],$vodConfig['template_group_id']);
|
||||
}catch (\Exception $e){}
|
||||
}
|
||||
}
|
||||
|
||||
\app\common\model\live\Playback::insert($data);
|
||||
|
||||
return 'success';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user