VideoPlaybackAction.class.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | Fanwe 方维直播系统
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2011 http://www.fanwe.com All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: 云淡风轻(1956838968@qq.com)
  8. // +----------------------------------------------------------------------
  9. class VideoPlaybackAction extends CommonAction{
  10. //回播列表
  11. public function playback_index() {
  12. $now=get_gmtime();
  13. if(strim($_REQUEST['nick_name'])!=''){//name
  14. $user=M("User")->where("nick_name like '%".strim($_REQUEST['nick_name'])."%' ")->findAll();
  15. $user_arr_id = array();
  16. foreach($user as $k=>$v){
  17. $user_arr_id[$k] =intval($v['id']);
  18. }
  19. //$user_str_id = implode(',',$user_arr_id);
  20. $map['user_id'] = array('in',$user_arr_id);
  21. }
  22. if(intval($_REQUEST['cate_id'])>0)
  23. {
  24. $map['cate_id'] = intval($_REQUEST['cate_id']);
  25. }
  26. if($_REQUEST['live_in']!='')
  27. {
  28. $map['live_in'] = intval($_REQUEST['live_in']);
  29. }
  30. if(intval($_REQUEST['room_id'])>0)
  31. {
  32. $map['id'] = intval($_REQUEST['room_id']);
  33. }
  34. if(intval($_REQUEST['user_id'])>0)
  35. {
  36. $map['user_id'] = intval($_REQUEST['user_id']);
  37. }
  38. $create_time_2=empty($_REQUEST['create_time_2'])?to_date($now,'Y-m-d'):strim($_REQUEST['create_time_2']);
  39. $create_time_2=to_timespan($create_time_2)+24*3600;
  40. if(trim($_REQUEST['create_time_1'])!='')
  41. {
  42. $map['create_time'] = array('between',array(to_timespan($_REQUEST['create_time_1']),$create_time_2));
  43. }
  44. $map['is_delete'] = 0;
  45. $map['is_del_vod'] = 0;
  46. $map['room_type'] = array('in',array(0,2,3));
  47. //$map['video_vid'] =array("neq",NULL);
  48. if (method_exists ( $this, '_filter' )) {
  49. $this->_filter ( $map );
  50. }
  51. //$name=$this->getActionName();
  52. $model = D ('VideoHistory');
  53. if (! empty ( $model )) {
  54. $this->_list ( $model, $map );
  55. }
  56. $list = $this->get("list");
  57. foreach($list as &$v){
  58. if(function_exists('time_len')) {
  59. $v['len_time'] = time_len(intval($v['len_time']));
  60. }
  61. $v['pay_editable'] = 0;
  62. if(defined('OPEN_LIVE_PAY')&&OPEN_LIVE_PAY==1){
  63. $v['pay_editable'] = 1;
  64. if($v['is_live_pay']==1&&$v['live_pay_type']==0){
  65. $v['pay_editable'] = 0;
  66. }
  67. }
  68. }
  69. $this->assign ( 'list', $list );
  70. if(defined('OPEN_LIVE_PAY')&&OPEN_LIVE_PAY==1&&intval(LIVE_PAY_SCENE)){
  71. $this->assign ( 'is_pay_live', 1 );
  72. }else{
  73. $this->assign ( 'is_pay_live', 0 );
  74. }
  75. $cate_list = M("VideoCate")->findAll();
  76. $this->assign("cate_list",$cate_list);
  77. //服务端开启类型
  78. $sql = "select val from ".DB_PREFIX."m_config where code= 'video_type'";
  79. $video_type = $GLOBALS['db']->getOne($sql);
  80. $this->assign("video_type",intval($video_type));
  81. $this->display ();
  82. }
  83. public function set_live_pay()
  84. {
  85. fanwe_require( APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  86. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  87. $video_id = intval($_REQUEST['id']);
  88. $video_redis = new VideoRedisService($video_id);
  89. $video = $video_redis->getRow_db($video_id,array('id','is_live_pay','live_fee'));
  90. $this->assign("video",$video);
  91. $this->display();
  92. }
  93. public function modify_live_pay(){
  94. $video_id = intval($_REQUEST['id']);
  95. $video['id'] = $video_id;
  96. $video['live_pay_type'] = 0;
  97. $video['live_fee'] = 0;
  98. $video['is_live_pay'] = intval($_REQUEST['is_live_pay']);//是否付费
  99. $live_fee = intval($_REQUEST['live_fee']);//观看费用
  100. if($video['is_live_pay']){
  101. $video['live_pay_type'] = 1;
  102. $video['live_fee'] = $live_fee;
  103. }
  104. if($video['live_fee'] && !preg_match('/^[0-9]*[1-9][0-9]*$/', $video['live_fee']))
  105. {
  106. $this->error("观看费用必须为大于0的整数");
  107. }
  108. $list=M("VideoHistory")->save ($video);
  109. if (false !== $list) {
  110. //redis同步
  111. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  112. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  113. sync_video_to_redis($video_id, '*', false);
  114. save_log($video_id.L("UPDATE_SUCCESS"),1);
  115. $this->success(L("UPDATE_SUCCESS"));
  116. } else {
  117. //错误提示
  118. save_log($video_id.L("UPDATE_FAILED"),0);
  119. $this->error(L("UPDATE_SUCCESS"));
  120. }
  121. }
  122. /*public function play_bak(){
  123. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  124. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  125. $m_config = load_auto_cache("m_config");//初始化手机端配置
  126. $app_id = $m_config['vodset_app_id'];
  127. $this->assign('app_id',$app_id);
  128. $id = $_REQUEST['id'];
  129. $condition['id'] = $id;
  130. $video = M('VideoHistory')->where($condition)->find();
  131. if(!empty($video)){
  132. $root = get_vodset_by_video_id($id);
  133. if(isset($root['vodset'])){
  134. $play_list = array();
  135. $vodset = $root['vodset'];
  136. foreach($vodset as $k=>$v){
  137. $playSet = $v['fileSet'];
  138. for($i=sizeof($playSet)-1;$i>=0;$i--){
  139. if($playSet[$i]['duration']>1){
  140. $play_list[] = $playSet[$i]['fileId'];
  141. }
  142. }
  143. }
  144. $this->assign("playlist",implode(',',$play_list));
  145. $this->assign("video_url",$play_list[0]);
  146. $this->assign("poster",$vodset[0]['fileSet'][sizeof($vodset[0]['fileSet'])-1]['image_url']);
  147. }else{
  148. $this->assign("error",$root['error']);
  149. }
  150. }
  151. $this->assign("video",$video);
  152. $this->display();
  153. }*/
  154. public function play(){
  155. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  156. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  157. $m_config = load_auto_cache("m_config");//初始化手机端配置
  158. $app_id = $m_config['vodset_app_id'];
  159. $this->assign('app_id',$app_id);
  160. $id = $_REQUEST['id'];
  161. $condition['id'] = $id;
  162. $video = M('VideoHistory')->where($condition)->find();
  163. if(!empty($video)&&$video['play_url']==''){
  164. $root = get_vodset_by_video_id($id);
  165. if(isset($root['vodset'])){
  166. $play_list = array();
  167. $vodset = $root['vodset'];
  168. foreach($vodset as $k=>$v){
  169. $playSet = $v['fileSet'];
  170. for($i=sizeof($playSet)-1;$i>=0;$i--){
  171. $play_list[] = $playSet[$i]['fileId'];
  172. $play_url_list[] = $playSet[$i]['playSet'];
  173. }
  174. }
  175. foreach($play_url_list as $k2=>$v2){
  176. foreach($v2 as $kk=>$vv) {
  177. //mp4
  178. if ($vv['definition'] == 0&&strpos($vv['url'], '.mp4')) {//原画mp4 播放URL
  179. $video['mp4_url'] = $vv['url'];
  180. }
  181. if ($vv['definition'] == 10) {//手机mp4 播放URL
  182. $video['mp4_sj_url'] = $vv['url'];
  183. }
  184. if ($vv['definition'] == 20) {//标清mp4 播放URL
  185. $video['mp4_sd_url'] = $vv['url'];
  186. }
  187. if ($vv['definition'] == 40 || $vv['definition'] == 30) {//高清mp4 播放URL
  188. $video['mp4_hd_url'] = $vv['url'];
  189. }
  190. //m3u8
  191. if ($vv['definition'] == 0 &&strpos($vv['url'], '.m3u8')) {//原画m3u8 播放URL
  192. $video['m3u8_url'] = $vv['url'];
  193. }
  194. if (($vv['definition'] == 210)&&strpos($vv['url'], '.m3u8')) {//手机m3u8 播放URL
  195. $video['m3u8_url'] = $vv['url'];
  196. }
  197. if (($vv['definition'] == 220)&&strpos($vv['url'], '.m3u8')) {//标清m3u8 播放URL
  198. $video['m3u8_sd_url'] = $vv['url'];
  199. }
  200. if (($vv['definition'] == 230)&&strpos($vv['url'], '.m3u8')) {//高清m3u8 播放URL
  201. $video['m3u8_hd_url'] = $vv['url'];
  202. }
  203. //flv
  204. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//原画flv 播放URL
  205. $video['flv_url'] = $vv['url'];
  206. }
  207. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//手机flv 播放URL
  208. $video['flv_sj_url'] = $vv['url'];
  209. }
  210. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//标清flv 播放URL
  211. $video['flv_sd_url'] = $vv['url'];
  212. }
  213. if (strpos($vv['url'], '.flv')&&$vv['definition'] == 0) {//高清flv 播放URL
  214. $video['flv_hd_url'] = $vv['url'];
  215. }
  216. //rtmp
  217. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//原画rtmp 播放URL
  218. $video['rtmp_url'] = $vv['url'];
  219. }
  220. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//手机rtmp 播放URL
  221. $video['rtmp_sj_url'] = $vv['url'];
  222. }
  223. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//标清rtmp 播放URL
  224. $video['rtmp_sd_url'] = $vv['url'];
  225. }
  226. if (!strpos($vv['url'], '.flv')&&!strpos($vv['url'], '.mp4')&&!strpos($vv['url'], '.m3u8')&&$vv['definition'] == 0) {//高清rtmp 播放URL
  227. $video['rtmp_hd_url'] = $vv['url'];
  228. }
  229. }
  230. }
  231. $this->assign("poster",$vodset[0]['fileSet'][sizeof($vodset[0]['fileSet'])-1]['image_url']);
  232. }else{
  233. $this->assign("error",$root['error']);
  234. }
  235. }else{
  236. //直播
  237. $video['mp4_url'] = $video['play_mp4'];
  238. if($video['play_url']) $video['mp4_url'] = $video['play_url'];
  239. $video['m3u8_url'] = $video['play_hls'];
  240. $video['flv_url'] = $video['play_flv'];
  241. $video['rtmp_url'] = $video['play_rtmp'];
  242. }
  243. $this->assign("video",$video);
  244. $this->display();
  245. }
  246. //删除视频
  247. public function del_video(){
  248. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  249. $ajax = intval($_REQUEST['ajax']);
  250. $id = $_REQUEST['id'];
  251. $result['status'] = 0;
  252. if (isset ( $id )) {
  253. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  254. $rel_data = M('VideoHistory')->where($condition)->findAll();
  255. $success_info = array();
  256. $fail_info = array();
  257. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  258. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  259. $video_redis = new VideoRedisService();
  260. foreach($rel_data as $video)
  261. {
  262. if($video['live_in']==0){
  263. $root = del_vodset($video,true);
  264. $sql = "update ".DB_PREFIX."video_history set is_delete = 1 where id =".$video['id'];
  265. $GLOBALS['db']->query($sql);
  266. if($GLOBALS['db']->affected_rows()){
  267. $success_info[] = $video['id'];
  268. $user_id = intval($video['user_id']);
  269. $sql = "select count(*) as num from ".DB_PREFIX."video_history where is_delete = 0 and is_del_vod = 0 and user_id = '".$user_id."'";
  270. $video_count = $GLOBALS['db']->getOne($sql);
  271. $sql = "update ".DB_PREFIX."user set video_count = ".$video_count." where id = ".$user_id;
  272. $GLOBALS['db']->query($sql);
  273. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/UserRedisService.php');
  274. $user_redis = new UserRedisService();
  275. $user_data = array();
  276. $user_data['video_count'] = $video_count;
  277. $user_redis->update_db($user_id, $user_data);
  278. $result['status'] = 1;
  279. }else{
  280. $fail_info[] = $video['id'];
  281. }
  282. }else{
  283. $fail_info[] = $video['id'].':不是历史状态,不能删除';
  284. }
  285. }
  286. if($success_info) $success_info = implode(",",$success_info);
  287. if($fail_info) $fail_info = implode(",",$fail_info);
  288. if (!$fail_info) {
  289. save_log($success_info.l("FOREVER_DELETE_SUCCESS"),1);
  290. clear_auto_cache("get_help_cache");
  291. $result['info'] = '删除成功!';
  292. //$this->success (l("FOREVER_DELETE_SUCCESS"),$ajax);
  293. } else {
  294. if($success_info){
  295. save_log($success_info.l("FOREVER_DELETE_SUCCESS"),1);
  296. }
  297. save_log($fail_info.l("FOREVER_DELETE_FAILED"),0);
  298. $result['info'] = $fail_info.' 删除失败!';
  299. //$this->error (l($fail_info),$ajax);
  300. }
  301. } else {
  302. $result['status'] = 0;
  303. $result['info'] = '编号错误';
  304. //$this->error (l("INVALID_OPERATION"),$ajax);
  305. }
  306. admin_ajax_return($result);
  307. }
  308. //修改上线状态
  309. public function set_demand_video_status(){
  310. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  311. $ajax = intval($_REQUEST['ajax']);
  312. $id = $_REQUEST['id'];
  313. $result['status'] = 0;
  314. if (isset ( $id )) {
  315. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  316. $rel_data = M('VideoHistory')->where($condition)->findAll();
  317. $success_info = array();
  318. $fail_info = array();
  319. $live_pay_id = '';
  320. foreach($rel_data as $data)
  321. {
  322. if ($data['live_in'] == 0&&(($data['is_live_pay']==1&&$data['live_pay_type'] != 0)||$data['is_live_pay']==0)){
  323. //上架
  324. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  325. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  326. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/VideoRedisService.php');
  327. $video_factory = new VideoFactory();
  328. /*if($data['video_type'] == 1 && $data['channelid']&& strpos($data['channelid'],'_'))
  329. {
  330. $ret = $video_factory->GetVodRecordFiles($data['channelid'], $data['create_time']);
  331. } else {
  332. $fileName = $data['id'] . '_' . to_date($data['begin_time'],'Y-m-d-H');
  333. if($data['video_type'] == 1){
  334. $fileName = 'live'.$data['id'] . '_' . to_date($data['begin_time'],'Y-m-d-H');
  335. }
  336. $ret = $video_factory->DescribeVodPlayInfo($fileName);
  337. }*/
  338. $ret = get_vodset_by_video_id($data['id']);
  339. /*if ($ret['totalCount'] > 0){*/
  340. if ($ret['total_count'] > 0||$data['play_url']!=''){
  341. require_once(APP_ROOT_PATH.'system/tim/TimApi.php');
  342. $api = createTimAPI();
  343. $ret = $api->group_get_group_info2(array('0'=>$data['user_id']));
  344. if ($ret['GroupInfo'][0]['ErrorCode']){
  345. //重新创建聊天组
  346. $ret = $api->group_create_group('AVChatRoom', (string)$data['user_id'], (string)$data['user_id'], (string)$data['id']);
  347. if ($ret['ActionStatus'] == 'OK'){
  348. $sql = "update ".DB_PREFIX."video_history set destroy_group_status = 1,group_id=id where id =".$data['id'];
  349. $GLOBALS['db']->query($sql);
  350. }
  351. }
  352. $re = video_status($data['id'],0);
  353. }else{
  354. $sql = "update ".DB_PREFIX."video_history set is_del_vod = 1 where id = ".$data['id'];
  355. $GLOBALS['db']->query($sql);
  356. $video_redis = new VideoRedisService();
  357. $n_data = array();
  358. $n_data['is_del_vod'] = 1;
  359. $video_redis->update_db($data['id'], $n_data);
  360. $result['status'] = 1;
  361. $result['info'] = '视频不存在';
  362. admin_ajax_return($result);
  363. }
  364. }else{
  365. $live_pay_id .= $data['id'].",";
  366. if($data['is_live_pay']==1&&$data['live_pay_type'] != 0){
  367. $fail_live_info = $live_pay_id."按时付费直播无法上线";
  368. }else{
  369. $fail_live_info = $live_pay_id."付费直播上线失败";
  370. }
  371. }
  372. $success_info[] = $data['id'];
  373. if($re){
  374. $result['status'] = 1;
  375. }else{
  376. $fail_info[] = $data['id'];
  377. }
  378. /*}else{
  379. $fail_info[] = $data['id'];
  380. }*/
  381. }
  382. if($success_info) $success_info = implode(",",$success_info);
  383. if($fail_info) $fail_info = implode(",",$fail_info);
  384. if ($re) {
  385. save_log($success_info.l("DEMAND_VIDEO_STATUS_SUCCESS"),1);
  386. $result['info'] = '修改成功!'.$fail_live_info;
  387. }else {
  388. if($success_info){
  389. save_log($success_info.l("DEMAND_VIDEO_STATUS_SUCCESS"),1);
  390. }
  391. if(empty($fail_info))$fail_info='';
  392. save_log($fail_info.l("DEMAND_VIDEO_STATUS_FAILED"),0);
  393. $result['info'] = $fail_info.'修改失败!'.$fail_live_info;
  394. }
  395. } else {
  396. $result['status'] = 0;
  397. $result['info'] = '编号错误';
  398. }
  399. admin_ajax_return($result);
  400. }
  401. public function add_tecent_video(){
  402. if(!TECENT_VIDEO){
  403. admin_ajax_return(array(
  404. 'status' => 0,
  405. 'error' => "模块开关未打开"
  406. ));
  407. }
  408. $m_config = load_auto_cache("m_config");
  409. $this->assign('secret_id', $m_config['qcloud_secret_id']);
  410. $this->display();
  411. }
  412. /**
  413. * 上传视频签名接口
  414. *
  415. * @return 签名
  416. */
  417. public function sign()
  418. {
  419. $args = $_REQUEST['args'];
  420. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  421. $video_factory = new VideoFactory();
  422. $result = $video_factory->Sign($args);
  423. $root = array('status' => 1, 'result' => $result);
  424. ajax_file_return($root);
  425. }
  426. /**
  427. * 新上传视频SDK签名接口
  428. *
  429. * @return 签名
  430. */
  431. public function new_sign(){
  432. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  433. $video_factory = new VideoFactory();
  434. $result = $video_factory->NewSign();
  435. $root = array('status' => 1, 'signature' => $result);
  436. ajax_file_return($root);
  437. }
  438. public function insert_tecent_video(){
  439. if(!TECENT_VIDEO){
  440. admin_ajax_return(array(
  441. 'status' => 0,
  442. 'error' => "模块开关未打开"
  443. ));
  444. }
  445. $result = array('status'=>1,'error'=>'添加回播视频成功,视频转码需要几分钟,请耐心等待');
  446. $create_type = intval($_REQUEST['create_type']);
  447. $user_id = intval($_REQUEST['user_id']);
  448. $title = trim($_REQUEST['title']);
  449. $video_vid = trim($_REQUEST['file_id']);
  450. $live_image = trim($_REQUEST['live_image']);
  451. if($user_id == 0)
  452. {
  453. admin_ajax_return(array('status'=>'0','error'=>'请输入用户id'));
  454. }
  455. if(!check_empty($title))
  456. {
  457. admin_ajax_return(array('status'=>'0','error'=>'请输入直播标题'));
  458. }
  459. if(!check_empty($video_vid))
  460. {
  461. admin_ajax_return(array('status'=>'0','error'=>'请添加文件'));
  462. }
  463. $is_private = false;
  464. $monitor_time = to_date(NOW_TIME+3600,'Y-m-d H:i:s');
  465. $data = $this->create_video($user_id,$title,$is_private,$monitor_time);//视频信息写入user表
  466. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/video_factory.php');
  467. $video_factory = new VideoFactory();
  468. $ret = $video_factory->ModifyVodInfo($video_vid, $data);
  469. if(! $ret['status'])
  470. {
  471. admin_ajax_return($ret);
  472. }
  473. // 新上传的视频未生成地址
  474. $data['is_del_vod'] = 1;
  475. $data['video_vid'] = $video_vid;
  476. $data['live_in'] = 2;//定时器通过2判断是否是上传到腾讯云
  477. $data['live_image'] = $live_image;
  478. $data['create_type'] = $create_type;
  479. $list = $GLOBALS['db']->autoExecute(DB_PREFIX . "video_history", $data, 'INSERT');
  480. if ($list !== false){
  481. save_log("回播视频上传成功",1);
  482. }else{
  483. save_log("回播视频上传失败",0);
  484. }
  485. //同步到redis
  486. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  487. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  488. sync_video_to_redis($data['id'],'*',false);
  489. admin_ajax_return($result);
  490. }
  491. public function create_video($user_id, $title, $is_private, $monitor_time, $cate_id = '', $province = '', $city = '', $share_type = '')
  492. {
  493. $condition['title'] = $title;
  494. if ($cate_id == 0 && $title != '') {
  495. $cate_id = M('video_cate')->where($condition)->getfield('id');
  496. if ($cate_id) {
  497. $is_newtitle = 0;
  498. } else {
  499. $is_newtitle = 1;
  500. }
  501. }
  502. if ($is_newtitle&&0) {
  503. $data_cate = array();
  504. $data_cate['title'] = $title;
  505. $data_cate['is_effect'] = 1;
  506. $data_cate['is_delete'] = 0;
  507. $data_cate['create_time'] = NOW_TIME;
  508. M('video_cate')->add($data_cate);
  509. $cate_id = M('video_cate')->where($condition)->getfield('id');
  510. }
  511. if ($province == '') {
  512. $province = '火星';
  513. }
  514. if ($city == '') {
  515. $city = '火星';
  516. }
  517. fanwe_require(APP_ROOT_PATH . 'mapi/lib/core/common.php');
  518. $v_id = get_max_room_id(0);//视频ID
  519. $data = array();
  520. $data['id'] = $v_id;
  521. //room_type 房间类型 : 1私有群(Private),0公开群(Public),2聊天室(ChatRoom),3互动直播聊天室(AVChatRoom)
  522. $data['room_type'] = 3;
  523. $m_config = load_auto_cache("m_config");
  524. $data['virtual_number'] = intval($m_config['virtual_number']);
  525. $data['max_robot_num'] = intval($m_config['robot_num']);//允许添加的最大机器人数;
  526. $sql = "select sex,ticket,refund_ticket,user_level,fans_count,head_image,thumb_head_image from " . DB_PREFIX . "user where id = " . $user_id;
  527. $user = $GLOBALS['db']->getRow($sql, true, true);
  528. if (!$user){
  529. admin_ajax_return(array(
  530. 'status' => 0,
  531. 'error' =>'用户ID不存在'
  532. ));
  533. }
  534. $info = origin_image_info($user['head_image']);
  535. $data['head_image'] = get_spec_image($info['file_name']);
  536. $data['thumb_head_image'] = $user['thumb_head_image'];
  537. $data['sex'] = intval($user['sex']);//性别 0:未知, 1-男,2-女
  538. $data['video_type'] = 1;//0:腾讯云互动直播;1:腾讯云直播
  539. require_once(APP_ROOT_PATH . 'system/tim/TimApi.php');
  540. $api = createTimAPI();
  541. $ret = $api->group_create_group('AVChatRoom', (string)$user_id, (string)$user_id, (string)$v_id);
  542. if ($ret['ActionStatus'] != 'OK') {
  543. admin_ajax_return(array(
  544. 'status' => 0,
  545. 'error' => $ret['ErrorCode'] . $ret['ErrorInfo']
  546. ));
  547. }
  548. $data['group_id'] = $ret['GroupId'];
  549. $data['monitor_time'] = $monitor_time;
  550. $data['create_type'] = 0;// 0:APP端创建的直播;1:PC端创建的直播
  551. $data['push_url'] = '';//video_type=1;1:腾讯云直播推流地址
  552. $data['play_url'] = '';//video_type=1;1:腾讯云直播播放地址(rmtp,flv)
  553. $data['share_type'] = $share_type;
  554. $data['title'] = $title;
  555. $data['cate_id'] = $cate_id;
  556. $data['user_id'] = $user_id;
  557. $data['live_in'] = 0;//live_in:是否直播中 1-直播中 0-已停止;2:正在创建直播;
  558. $data['watch_number'] = '';//'当前观看人数';
  559. $data['vote_number'] = '';//'获得票数';
  560. $data['province'] = $province;//'省';
  561. $data['city'] = $city;//'城市';
  562. $data['create_time'] = NOW_TIME;//'创建时间';
  563. $data['begin_time'] = NOW_TIME;//'开始时间';
  564. $data['end_time'] = '';//'结束时间';
  565. $data['is_hot'] = 1;//'1热门; 0:非热门';
  566. $data['is_new'] = 1; //'1新的; 0:非新的,直播结束时把它标识为:0?'
  567. $data['online_status'] = 1;//主播在线状态;1:在线(默认); 0:离开
  568. //sort_init(初始排序权重) = (用户可提现印票:fanwe_user.ticket - fanwe_user.refund_ticket) * 保留印票权重+ 直播/回看[回看是:0; 直播:9000000000 直播,需要排在最上面 ]+ fanwe_user.user_level * 等级权重+ fanwe_user.fans_count * 当前有的关注数权重
  569. $sort_init = (intval($user['ticket']) - intval($user['refund_ticket'])) * floatval($m_config['ticke_weight']);
  570. $sort_init += intval($user['user_level']) * floatval($m_config['level_weight']);
  571. $sort_init += intval($user['fans_count']) * floatval($m_config['focus_weight']);
  572. $data['sort_init'] = 200000000 + $sort_init;
  573. $data['sort_num'] = $data['sort_init'];
  574. return $data;
  575. }
  576. //合并视频
  577. public function vod_concatvideo(){
  578. $id = $_REQUEST['id'];
  579. $result['status'] = 0;
  580. if (isset ( $id )) {
  581. require_once APP_ROOT_PATH . "/mapi/lib/core/common.php";
  582. $condition = array ('id' => array ('in', explode ( ',', $id ) ) );
  583. $rel_data = M('VideoHistory')->where($condition)->findAll();
  584. $success_info = array();
  585. $fail_info = array();
  586. foreach($rel_data as $data) {
  587. $channel_id =$data['channelid'];
  588. $new_file_name = $data['channelid'].'99';
  589. if($data['is_concatvideo']==0){
  590. $result = Com_ConcatVideo($channel_id,$new_file_name);
  591. }else{
  592. $result['status'] = 1;
  593. $result['error'] = '视频已经合并,请勿重复操作';
  594. }
  595. //更新
  596. if(intval($result['status'])==1){
  597. $sql = "update ".DB_PREFIX."video_history set is_concatvideo = 1 where id =".$data['id'];
  598. $GLOBALS['db']->query($sql);
  599. $success_info[] = $data['id'];
  600. }else{
  601. $fail_info[] = $data['id'];
  602. }
  603. }
  604. $msg = '';
  605. if(!empty($success_info)){
  606. $success_info=implode(',',$success_info);
  607. }
  608. if(!empty($fail_info)){
  609. $fail_info=implode(',',$fail_info);
  610. }
  611. if(intval($result['status'])==1){
  612. if($result['error']==''){
  613. if($success_info!=''){
  614. $result['info'] = $success_info.'合并成功;';
  615. $msg = $result['info'];
  616. }
  617. }else{
  618. $result['info'] = $result['error'];
  619. }
  620. }else{
  621. if($fail_info!=''){
  622. $result['info'] = $fail_info.'合并失败';
  623. $msg .= $result['info'];
  624. }
  625. }
  626. save_log($msg,0);
  627. }else {
  628. $result['status'] = 0;
  629. $result['info'] = '编号错误';
  630. }
  631. admin_ajax_return($result);
  632. }
  633. public function add_video(){
  634. $this->assign('max_size', conf('MAX_IMAGE_SIZE') / 1000);
  635. $this->display();
  636. }
  637. //上传OSS
  638. function upload_oss(){
  639. $result = array('status'=>1,'error'=>'添加回播视频成功,视频转码需要几分钟,请耐心等待');
  640. $create_type = intval($_REQUEST['create_type']);
  641. $kefile_url = trim($_REQUEST['kefile_url']);
  642. $kefile_url = urldecode($kefile_url);
  643. $title = trim($_REQUEST['title']);
  644. $user_id = trim($_REQUEST['user_id']);
  645. $live_image = trim($_REQUEST['live_image']);
  646. if($user_id == 0)
  647. {
  648. admin_ajax_return(array('status'=>'0','error'=>'请输入用户id'));
  649. }
  650. if(!check_empty($title))
  651. {
  652. admin_ajax_return(array('status'=>'0','error'=>'请输入直播标题'));
  653. }
  654. if(!check_empty($kefile_url))
  655. {
  656. admin_ajax_return(array('status'=>'0','error'=>'文件链接不能为空'));
  657. }
  658. $is_private = false;
  659. $monitor_time = to_date(NOW_TIME+3600,'Y-m-d H:i:s');
  660. $data = $this->create_video($user_id,$title,$is_private,$monitor_time);//视频信息写入user表
  661. if($GLOBALS['distribution_cfg']['OSS_TYPE']&&$GLOBALS['distribution_cfg']['OSS_TYPE']=='ALI_OSS'){
  662. $file_url=get_spec_image($kefile_url);
  663. }else{
  664. $file_url=str_replace("./public/",file_domain()."/public/",$kefile_url);
  665. }
  666. // 新上传的视频未生成地址
  667. $data['is_del_vod'] = 0;
  668. $data['play_url'] = $file_url;
  669. $data['live_image'] = $live_image;
  670. $data['create_type'] = $create_type;
  671. $list = $GLOBALS['db']->autoExecute(DB_PREFIX . "video_history", $data, 'INSERT');
  672. if ($list !== false){
  673. save_log("回播视频上传成功",1);
  674. }else{
  675. save_log("回播视频上传失败",0);
  676. }
  677. //同步到redis
  678. require_once APP_ROOT_PATH."/mapi/lib/core/common.php";
  679. fanwe_require(APP_ROOT_PATH.'mapi/lib/redis/BaseRedisService.php');
  680. sync_video_to_redis($data['id'],'*',false);
  681. admin_ajax_return($result);
  682. }
  683. }
  684. ?>