From b525fd1b49165598f3b4e0a72ef8382485ffab0f Mon Sep 17 00:00:00 2001 From: xingchao <1363688001@qq.com> Date: Mon, 7 May 2018 11:50:39 +0800 Subject: [PATCH] =?UTF-8?q?'=E6=9C=89=E7=9B=B4=E6=92=AD=E6=B5=81=E5=8F=AF?= =?UTF-8?q?=E4=BB=A5=E7=9B=B4=E6=92=AD'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/api/controller/Live.php | 67 ++++++++++++++++++----------- 1 file changed, 42 insertions(+), 25 deletions(-) diff --git a/application/api/controller/Live.php b/application/api/controller/Live.php index 81f665cf..cf98ac78 100644 --- a/application/api/controller/Live.php +++ b/application/api/controller/Live.php @@ -53,49 +53,66 @@ class Live extends Api ); } - if ($this->request->request("username")) { - $username = $this->request->request("username"); -// $username = 'qq'; - $sql = "select b.* +// if ($this->request->request("username")) { +// $username = $this->request->request("username"); + $username = 'xingchao'; + $sql = "select b.* from fa_user as a,fa_live as b where a.id=b.user_id and a.username = '$username'"; - $list = Db::query($sql); - if (!empty($list)) { - return true; - } else { - //创建直播流 - $sql = "select id + $list = Db::query($sql); + if (!empty($list)) { + + $code = trim(strrchr($list[0]['push_url'], '/'), '/'); + + $len1 = strlen($list[0]['push_url']); + $len2 = strlen($code); + + $base_url = substr($list[0]['push_url'],0,$len1 - $len2); +// echo $base_url; + + $list = array( + 'base_url' => $base_url, + 'code' => $code, + ); + + $result = array("rows" => $list); + + return (json($result)); + + } else { + //创建直播流 + $sql = "select id from fa_user where username = '$username'"; - $list = Db::query($sql); - $user_id = $list[0]['id']; + $list = Db::query($sql); + $user_id = $list[0]['id']; - $code = time(); - $base_url = "rtmp://47.104.165.49:1935/live/"; - $push_url = $base_url . $code; - $pull_url = $push_url; - $sql = "INSERT INTO fa_live(push_url,pull_url,user_id,status) VALUES ('$push_url','$pull_url','$user_id','1')"; + $code = time(); + $base_url = "rtmp://47.104.165.49:1935/live/"; + $push_url = $base_url . $code; + $pull_url = $push_url; + $sql = "INSERT INTO fa_live(push_url,pull_url,user_id,status) VALUES ('$push_url','$pull_url','$user_id','1')"; // echo $sql; // exit(); - $rs = Db::execute($sql); + $rs = Db::execute($sql); // if ($rs === false) { // echo '添加直播流失败'; // } else { // echo '添加直播流成功'; // } - $list = array( - 'base_url'=>$base_url, - 'code'=>$code, - ); + $list = array( + 'base_url' => $base_url, + 'code' => $code, + ); - $result = array( "rows" => $list); - return json($result); - } + $result = array("rows" => $list); + return json($result); } +// } $total = $this->model