$maxRecordTime ? $maxRecordTime : $cycleDuration); $aliLiveConfig = \app\common\model\config\System::getConfig('ali_live'); $liveConfig = \app\common\model\app\Config::getConfig('live'); if($roomConfig){ $liveConfig = array_merge($liveConfig,$roomConfig); } if(isset($liveConfig['play_back_save_type']) && $liveConfig['play_back_save_type'] == 'oss'){ $ossConfig = \app\common\model\config\System::getConfig('alioss'); if(!$ossConfig || $ossConfig['status'] != 'open'){ return false; } try{ $client = \app\common\library\live\AliLiveClient::createClient(); //源流配置 $recordFormat0 = new recordFormat([ // String, 可选, OSS存储的录制文件名。 - 文件名小于256字节,支持变量匹配,包含 {AppName}、{StreamName}、{Sequence}、{StartTime}、{EndTime}、{EscapedStartTime}、{EscapedEndTime}。 - 参数值必须要有{StartTime}或{EscapedStartTime}和{EndTime}或{EscapedEndTime}。 "ossObjectPrefix" => "record/{AppName}/{StreamName}/{Sequence}{EscapedStartTime}{EscapedEndTime}", // String, 可选, 格式。目前支持M3U8、FLV、MP4。取值: >RecordFormat和TranscodeRecordFormat两者至少需要设置一个。 > - m3u8。如果选择m3u8格式,必须同时设置请求参数RecordFormat.N.SliceOssObjectPrefix和RecordFormat.N.SliceDuration。 - flv。 - mp4。 "format" => "mp4", "cycleDuration"=>$cycleDuration ]); $addLiveAppRecordConfigRequest = new AddLiveAppRecordConfigRequest([ "domainName" => $aliLiveConfig['play_domain'], "appName" => $appName, "ossEndpoint" => $ossConfig['endpoint'], "streamName" => $streamName, "ossBucket" => $ossConfig['bucket'], // Array, 可选 "recordFormat" => [ $recordFormat0 ], ]); $runtime = new RuntimeOptions([]); $client->addLiveAppRecordConfigWithOptions($addLiveAppRecordConfigRequest, $runtime); return true; }catch (\Exception $e){ return $e->getMessage(); } } if(isset($liveConfig['play_back_save_type']) && $liveConfig['play_back_save_type'] == 'vod'){ $vodConfig = \app\common\model\config\System::getConfig('alivod'); if(!$vodConfig || $vodConfig['status'] != 'open'){ return false; } try{ AlibabaCloud::accessKeyClient($aliLiveConfig['access_key_id'], $aliLiveConfig['access_key_secret']) ->regionId($vodConfig['region_id']) ->asDefaultClient() ->options([]); $request = Live::v20161101()->addLiveRecordVodConfig(); $request ->withAppName($appName) ->withVodTranscodeGroupId($vodConfig['template_group_id']) ->withDomainName($aliLiveConfig['play_domain']) ->withStreamName($streamName) ->request(); return true; }catch (\Exception $e){ return $e->getMessage(); } } } /** * 解除直播录制配置 * @return void */ public static function delRecordConfig($appName,$streamName = '',$roomConfig=[]){ $aliLiveConfig = \app\common\model\config\System::getConfig('ali_live'); $liveConfig = \app\common\model\app\Config::getConfig('live'); if($roomConfig){ $liveConfig = array_merge($liveConfig,$roomConfig); } if(isset($liveConfig['play_back_save_type']) && $liveConfig['play_back_save_type'] == 'oss'){ try { $client = \app\common\library\live\AliLiveClient::createClient(); $params = [ "domainName" => $aliLiveConfig['play_domain'], "appName" => $appName ]; if($streamName){ $params['streamName'] = $streamName; } $deleteLiveAppRecordConfigRequest = new DeleteLiveAppRecordConfigRequest($params); $runtime = new RuntimeOptions([]); // 复制代码运行请自行打印 API 的返回值 $client->deleteLiveAppRecordConfigWithOptions($deleteLiveAppRecordConfigRequest, $runtime); return true; }catch (\Exception $error) { return $error->getMessage(); } } if(isset($liveConfig['play_back_save_type']) && $liveConfig['play_back_save_type'] == 'vod'){ $vodConfig = \app\common\model\config\System::getConfig('alivod'); if(!$vodConfig || $vodConfig['status'] != 'open'){ return false; } try { AlibabaCloud::accessKeyClient($aliLiveConfig['access_key_id'], $aliLiveConfig['access_key_secret']) ->regionId($vodConfig['region_id']) ->asDefaultClient() ->options([]); $request = Live::v20161101()->deleteLiveRecordVodConfig(); $request ->withAppName($appName) ->withDomainName($aliLiveConfig['play_domain']) ->withStreamName($streamName) ->request(); }catch (\Exception $error) { return $error->getMessage(); } } } }