1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243 |
- <?php
- // +—————————————————————————————————————————————————————————————————————
- // | Created by Yunbao
- // +—————————————————————————————————————————————————————————————————————
- // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
- // +—————————————————————————————————————————————————————————————————————
- // | Author: https://gitee.com/yunbaokeji
- // +—————————————————————————————————————————————————————————————————————
- // | Date: 2022-02-17
- // +—————————————————————————————————————————————————————————————————————
- /**
- * 直播间
- */
- class Api_Live extends PhalApi_Api {
- public function getRules() {
- return array(
- 'getSDK' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
- ),
- 'createRoom' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'title' => array('name' => 'title', 'type' => 'string','default'=>'', 'desc' => '直播标题 url编码'),
- 'province' => array('name' => 'province', 'type' => 'string', 'default'=>'', 'desc' => '省份'),
- 'city' => array('name' => 'city', 'type' => 'string', 'default'=>'', 'desc' => '城市'),
- 'lng' => array('name' => 'lng', 'type' => 'string', 'default'=>'0', 'desc' => '经度值'),
- 'lat' => array('name' => 'lat', 'type' => 'string', 'default'=>'0', 'desc' => '纬度值'),
- 'type' => array('name' => 'type', 'type' => 'int', 'default'=>'0', 'desc' => '直播房间类型,0是普通房间,1是私密房间,2是收费房间,3是计时房间'),
- 'type_val' => array('name' => 'type_val', 'type' => 'string', 'default'=>'', 'desc' => '类型值'),
- 'anyway' => array('name' => 'anyway', 'type' => 'int', 'default'=>'0', 'desc' => '直播类型 1 PC, 0 app'),
- 'liveclassid' => array('name' => 'liveclassid', 'type' => 'int', 'default'=>'0', 'desc' => '直播分类ID'),
- 'deviceinfo' => array('name' => 'deviceinfo', 'type' => 'string', 'default'=>'', 'desc' => '设备信息'),
- 'thumb' => array('name' => 'thumb', 'type' => 'string', 'desc' => '开播封面'),
- ),
- 'changeLive' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- 'status' => array('name' => 'status', 'type' => 'int', 'require' => true, 'desc' => '直播状态 0关闭 1直播'),
- ),
-
- 'stopRoom' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- 'type' => array('name' => 'type', 'type' => 'int', 'default'=>'0', 'desc' => '类型'),
- 'source' => array('name' => 'source', 'type' => 'string', 'desc' => '访问来源 socekt:断联socket,app传值空'),
- 'time' => array('name' => 'time', 'type' => 'string', 'desc' => '当前时间戳'),
- 'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名'),
- ),
-
- 'stopInfo' => array(
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- ),
-
- 'checkLive' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- ),
-
- 'roomCharge' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- ),
- 'timeCharge' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- ),
-
- 'enterRoom' => array(
- 'uid' => array('name' => 'uid', 'type' => 'string', 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- 'city' => array('name' => 'city', 'type' => 'string','default'=>'', 'desc' => '城市'),
- 'mobileid' => array('name' => 'mobileid', 'type' => 'string','default'=>'', 'desc' => '实际唯一识别码'),
- 'usernicename' => array('name' => 'usernicename', 'type' => 'string','default'=>'', 'desc' => '用户名'),
- ),
-
-
- 'getUserLists' => array(
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- 'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1,'desc' => '页数'),
- ),
-
- 'getPop' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'touid' => array('name' => 'touid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '对方ID'),
- ),
-
- 'getGiftList' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- ),
-
- 'sendGift' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- 'giftid' => array('name' => 'giftid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '礼物ID'),
- 'giftcount' => array('name' => 'giftcount', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '礼物数量'),
-
- 'touids' => array('name' => 'touids', 'type' => 'string', 'require' => true, 'desc' => '接收送礼物的麦上用户组'),
- ),
-
- 'sendBarrage' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
- 'content' => array('name' => 'content', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => '弹幕内容'),
- ),
-
- 'getVotes' => array(
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
- ),
-
- 'getCoin' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '会员ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'min' => 1, 'desc' => '会员token'),
- ),
-
- 'checkLiveing' => array(
- 'uid' => array('name' => 'uid', 'type' => 'int','desc' => '会员ID'),
- 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'min' => 1, 'desc' => '会员token'),
- 'stream' => array('name' => 'stream', 'type' => 'string','desc' => '流名'),
- ),
- 'getLiveInfo' => array(
- 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'desc' => '主播ID'),
- ),
-
-
-
-
-
- );
- }
- /**
- * 获取SDK
- * @desc 用于获取SDK类型
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].live_sdk SDK类型,0金山SDK 1腾讯SDK
- * @return object info[0].android 安卓CDN配置
- * @return object info[0].ios IOS CDN配置
- * @return string info[0].isshop 是否有店铺,0否1是
- * @return string msg 提示信息
- */
- public function getSDK() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $uid=checkNull($this->uid);
- $cdnset=include API_ROOT.'/../PhalApi/Config/cdnset.php';
- $rs['info'][0]=$cdnset;
- return $rs;
- }
- /**
- * 创建开播
- * @desc 用于用户开播生成记录
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].userlist_time 用户列表请求间隔
- * @return string info[0].barrage_fee 弹幕价格
- * @return string info[0].votestotal 主播映票
- * @return string info[0].stream 流名
- * @return string info[0].push 推流地址
- * @return string info[0].pull 播流地址
- * @return string info[0].chatserver socket地址
- * @return array info[0].game_switch 游戏开关
- * @return string info[0].game_switch[][0] 开启的游戏类型
- * @return string info[0].game_bankerid 庄家ID
- * @return string info[0].game_banker_name 庄家昵称
- * @return string info[0].game_banker_avatar 庄家头像
- * @return string info[0].game_banker_coin 庄家余额
- * @return string info[0].game_banker_limit 上庄限额
- * @return object info[0].liang 用户靓号信息
- * @return string info[0].liang.name 号码,0表示无靓号
- * @return object info[0].vip 用户VIP信息
- * @return string info[0].vip.type VIP类型,0表示无VIP,1表示有VIP
- * @return string info[0].guard_nums 守护数量
- * @return string info[0].thumb 直播封面
- * @return string msg 提示信息
- */
- public function createRoom() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $uid = checkNull($this->uid);
- $token=checkNull($this->token);
- $configpub=getConfigPub();
- if($configpub['maintain_switch']==1){
- $rs['code']=1002;
- $rs['msg']=$configpub['maintain_tips'];
- return $rs;
- }
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
- $configpri=getConfigPri();
- if($configpri['auth_islimit']==1){
- $isauth=isAuth($uid);
- if(!$isauth){
- $rs['code']=1002;
- $rs['msg']='请先进行身份认证或等待审核';
- return $rs;
- }
- }
- $userinfo=getUserInfo($uid);
-
- if($configpri['level_islimit']==1){
- if( $userinfo['level'] < $configpri['level_limit'] ){
- $rs['code']=1003;
- $rs['msg']='等级小于'.$configpri['level_limit'].'级,不能直播';
- return $rs;
- }
- }
-
- $nowtime=time();
-
- $showid=$nowtime;
- $starttime=$nowtime;
- $title=checkNull($this->title);
- $province=checkNull($this->province);
- $city=checkNull($this->city);
- $lng=checkNull($this->lng);
- $lat=checkNull($this->lat);
- $type=checkNull($this->type);
- $type_val=checkNull($this->type_val);
- $anyway=checkNull($this->anyway);
- $liveclassid=checkNull($this->liveclassid);
- $deviceinfo=checkNull($this->deviceinfo);
- $thumb_str=checkNull($this->thumb);
- $sensitivewords=sensitiveField($title);
- if($sensitivewords==1001){
- $rs['code'] = 10011;
- $rs['msg'] = '输入非法,请重新输入';
- return $rs;
- }
-
-
- if( $type==1 && $type_val=='' ){
- $rs['code']=1002;
- $rs['msg']='密码不能为空';
- return $rs;
- }else if($type > 1 && $type_val<=0){
- $rs['code']=1002;
- $rs['msg']='价格不能小于等于0';
- return $rs;
- }
-
- $stream=$uid.'_'.$nowtime;
- $push=PrivateKeyA('rtmp',$stream,1);
- $pull=PrivateKeyA('rtmp',$stream,0);
- if(!$city){
- $city='好像在火星';
- }
- if(!$lng && $lng!=0){
- $lng='';
- }
- if(!$lat && $lat!=0){
- $lat='';
- }
- //APP原生上传后请求接口保存start
- $thumb="";
- if($thumb_str){
- $cloudtype=$configpri['cloudtype'];
- if($cloudtype==1){ //七牛云存储
- $thumb= $thumb_str.'?imageView2/2/w/600/h/600';
- }else{
- $thumb=$thumb_str;
- }
- }
-
- $dataroom=array(
- "uid"=>$uid,
- "showid"=>$showid,
- "starttime"=>$starttime,
- "title"=>$title,
- "province"=>$province,
- "city"=>$city,
- "stream"=>$stream,
- "thumb"=>$thumb,
- "pull"=>$pull,
- "lng"=>$lng,
- "lat"=>$lat,
- "type"=>$type,
- "type_val"=>$type_val,
- "isvideo"=>0,
- "islive"=>0,
- "anyway"=>$anyway,
- "liveclassid"=>$liveclassid,
- "deviceinfo"=>$deviceinfo,
- "hotvotes"=>0,
- );
- $domain = new Domain_Live();
- $result = $domain->createRoom($uid,$dataroom);
- if($result===false){
- $rs['code'] = 1011;
- $rs['msg'] = '开播失败,请重试';
- return $rs;
- }
-
- $userinfo['city']=$city;
- $userinfo['usertype']=50;
- $userinfo['sign']='0';
- DI()->redis -> set($token,json_encode($userinfo));
- $votestotal=$domain->getVotes($uid);
-
- $info['userlist_time']=$configpri['userlist_time'];
- $info['barrage_fee']=$configpri['barrage_fee'];
- $info['chatserver']=$configpri['chatserver'];
- $info['votestotal']=$votestotal;
- $info['stream']=$stream;
- $info['push']=$push;
- $info['pull']=$pull;
-
- // 腾讯APPID
- $info['tx_appid']=$configpri['tx_appid'];
-
- // 敏感词集合
- $dirtyarr=array();
- if($configpri['sensitive_words']){
- $dirtyarr=explode(',',$configpri['sensitive_words']);
- }
- $info['sensitive_words']=$dirtyarr;
- //返回直播封面
- if($thumb){
- $info['thumb']=get_upload_path($thumb);
- }else{
- $info['thumb']=$userinfo['avatar_thumb'];
- }
- $rs['info'][0] = $info;
-
- return $rs;
- }
-
- /**
- * 修改直播状态
- * @desc 用于主播修改直播状态
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].msg 成功提示信息
- * @return string msg 提示信息
- */
- public function changeLive() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid = checkNull($this->uid);
- $token=checkNull($this->token);
- $stream=checkNull($this->stream);
- $status=checkNull($this->status);
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $domain = new Domain_Live();
- $info=$domain->changeLive($uid,$stream,$status);
-
- $rs['info'][0]['msg']='成功';
- return $rs;
- }
-
- /**
- * 关闭直播
- * @desc 用于用户结束直播
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].msg 成功提示信息
- * @return string msg 提示信息
- */
- public function stopRoom() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $uid = checkNull($this->uid);
- $token=checkNull($this->token);
- $stream=checkNull($this->stream);
- $type=checkNull($this->type);
- $source=checkNull($this->source);
- $time=checkNull($this->time);
- $sign=checkNull($this->sign);
- if(!$source){ //非socket来源,app访问
- if(!$time){
- $rs['code'] = 1001;
- $rs['msg'] = '参数错误,请重试';
- return $rs;
- }
- $now=time();
- if($now-$time>300){
- $rs['code']=1001;
- $rs['msg']='参数错误';
- return $rs;
- }
- if(!$sign){
- $rs['code']=1001;
- $rs['msg']="参数错误,请重试";
- return $rs;
- }
-
- $checkdata=array(
- 'uid'=>$uid,
- 'token'=>$token,
- 'time'=>$time,
- 'stream'=>$stream,
- );
-
- $issign=checkSign($checkdata,$sign);
- if(!$issign){
- $rs['code']=1001;
- $rs['msg']='签名错误';
- return $rs;
- }
- }
-
- $key='stopRoom_'.$stream;
- $isexist=getcaches($key);
- if(!$isexist ){
- $domain = new Domain_Live();
- $checkToken=checkToken($uid,$token);
- setcaches($key,'1',10);
- if($checkToken==700){
- $domain->stopRoom($uid,$stream);
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $info=$domain->stopRoom($uid,$stream);
-
- }
-
- $rs['info'][0]['msg']='关播成功';
- return $rs;
- }
-
- /**
- * 直播结束信息
- * @desc 用于直播结束页面信息展示
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].nums 人数
- * @return string info[0].length 时长
- * @return string info[0].votes 映票数
- * @return string msg 提示信息
- */
- public function stopInfo() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $stream=checkNull($this->stream);
-
- $domain = new Domain_Live();
- $info=$domain->stopInfo($stream);
- $rs['info'][0]=$info;
- return $rs;
- }
-
- /**
- * 检查直播状态
- * @desc 用于用户进房间时检查直播状态
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].type 房间类型
- * @return string info[0].type_val 收费房间价格,默认0
- * @return string info[0].type_msg 提示信息
- * @return string info[0].live_type 房间类型 0 视频直播 1 语音聊天室
- * @return string msg 提示信息
- */
- public function checkLive() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $liveuid=checkNull($this->liveuid);
- $stream=checkNull($this->stream);
-
- $configpub=getConfigPub();
- if($configpub['maintain_switch']==1){
- $rs['code']=1002;
- $rs['msg']=$configpub['maintain_tips'];
- return $rs;
- }
- if($uid>0){
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- }
-
-
- if($uid==$liveuid){
- $rs['code'] = 1011;
- $rs['msg'] = '不能进入自己的直播间';
- return $rs;
- }
-
- $domain = new Domain_Live();
- $info=$domain->checkLive($uid,$liveuid,$stream);
-
- if($info==1005){
- $rs['code'] = 1005;
- $rs['msg'] = '直播已结束';
- return $rs;
- }else if($info==1007){
- $rs['code'] = 1007;
- $rs['msg'] = '超管不能进入1v1房间';
- return $rs;
- }else if($info==1008){
- $rs['code'] = 1004;
- $rs['msg'] = '您已被踢出房间';
- return $rs;
- }
-
-
-
-
- $rs['info'][0]=$info;
-
-
- return $rs;
- }
-
- /**
- * 房间扣费
- * @desc 用于房间扣费
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].coin 用户余额
- * @return string msg 提示信息
- */
- public function roomCharge() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $liveuid=checkNull($this->liveuid);
- $stream=checkNull($this->stream);
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $domain = new Domain_Live();
- $info=$domain->roomCharge($uid,$liveuid,$stream);
-
- if($info==1005){
- $rs['code'] = 1005;
- $rs['msg'] = '直播已结束';
- return $rs;
- }else if($info==1006){
- $rs['code'] = 1006;
- $rs['msg'] = '该房间非扣费房间';
- return $rs;
- }else if($info==1007){
- $rs['code'] = 1007;
- $rs['msg'] = '房间费用有误';
- return $rs;
- }else if($info==1008){
- $rs['code'] = 1008;
- $rs['msg'] = '余额不足';
- return $rs;
- }
- $rs['info'][0]['coin']=$info['coin'];
-
- return $rs;
- }
- /**
- * 房间计时扣费
- * @desc 用于房间计时扣费
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].coin 用户余额
- * @return string msg 提示信息
- */
- public function timeCharge() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $liveuid=checkNull($this->liveuid);
- $stream=checkNull($this->stream);
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $domain = new Domain_Live();
-
- $key='timeCharge_'.$stream.'_'.$uid;
- $cache=getcaches($key);
- if($cache){
- $coin=$domain->getUserCoin($uid);
- $rs['info'][0]['coin']=$coin['coin'];
- return $rs;
- }
-
-
-
- $info=$domain->roomCharge($uid,$liveuid,$stream);
-
- if($info==1005){
- $rs['code'] = 1005;
- $rs['msg'] = '直播已结束';
- return $rs;
- }else if($info==1006){
- $rs['code'] = 1006;
- $rs['msg'] = '该房间非扣费房间';
- return $rs;
- }else if($info==1007){
- $rs['code'] = 1007;
- $rs['msg'] = '房间费用有误';
- return $rs;
- }else if($info==1008){
- $rs['code'] = 1008;
- $rs['msg'] = '余额不足';
- return $rs;
- }
- $rs['info'][0]['coin']=$info['coin'];
-
- setcaches($key,1,50);
-
- return $rs;
- }
-
- /**
- * 进入直播间
- * @desc 用于用户进入直播
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].votestotal 直播映票
- * @return string info[0].barrage_fee 弹幕价格
- * @return string info[0].userlist_time 用户列表获取间隔
- * @return string info[0].chatserver socket地址
- * @return string info[0].nums 房间人数
- * @return string info[0].pull_url 播流地址
- * @return string msg 提示信息
- */
- public function enterRoom() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $liveuid=checkNull($this->liveuid);
- $city=checkNull($this->city);
- $stream=checkNull($this->stream);
- $mobileid=checkNull($this->mobileid);
- $usernicename=checkNull($this->usernicename);
- if($uid>0){
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
- }
-
- $domain = new Domain_Live();
- $userinfo=getUserInfo($uid);
- if ($userinfo['id']<1){
- $userinfo['id'] = $uid;
- }
- $userinfo['user_nicename'] = $usernicename;
- if(!$city){
- $city='好像在火星';
- }
- $userinfo['city']=$city;
-
- $stream2=explode('_',$stream);
- $showid=$stream2[1];
-
- $contribution='0';
- if($showid && $uid>0){
- $contribution=$domain->getContribut($uid,$liveuid,$showid);
- }
- $userinfo['contribution'] = $contribution;
- /* 等级+100 保证等级位置位数相同,最后拼接1 防止末尾出现0 */
- $userinfo['sign']=$userinfo['contribution'].'.'.($userinfo['level']+100).'1';
- $userinfo['usertype'] = 30;
- if($uid<0){
- $userinfo['id']=$mobileid;
- $token=$mobileid;
- }
-
- DI()->redis -> set($token,json_encode($userinfo));
- // 一天后过期,自动删除
- $nowtime=time();
- $expiretime=$nowtime+60*60*24;
- if($expiretime > 0){
- DI()->redis->expire($token, $expiretime);
- }
-
-
- /* 用户列表 */
- $userlists=$this->getUserList($liveuid,$stream);
- $configpri=getConfigPri();
-
- $info=array(
- 'votestotal'=>$userlists['votestotal'],
- 'barrage_fee'=>$configpri['barrage_fee'],
- 'userlist_time'=>$configpri['userlist_time'],
- 'chatserver'=>$configpri['chatserver'],
-
- 'nums'=>$userlists['nums'],
- 'speak_limit'=>$configpri['speak_limit'],
- 'barrage_limit'=>$configpri['barrage_limit'],
-
- 'level'=>$userinfo['level']
- );
-
- $live_info=$domain->getLiveInfo($liveuid);
- $pull=$live_info['pull'];
- if($live_info['isvideo']!=1){
- $pull=PrivateKeyA('rtmp',$stream,0);
- }
-
- $info['pull']=$pull;
- $info['userlists']=$userlists['userlist'];
-
-
- /* 用户余额 */
- $domain2 = new Domain_User();
- $usercoin=$domain2->getBalance($uid);
- $info['coin']=(string)$usercoin['coin'];
-
- /** 敏感词集合*/
- $dirtyarr=array();
- if($configpri['sensitive_words']){
- $dirtyarr=explode(',',$configpri['sensitive_words']);
- }
- $info['sensitive_words']=$dirtyarr;
- $rs['info'][0]=$info;
- return $rs;
- }
-
-
- /**
- * 用户列表
- * @desc 用于直播间获取用户列表
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].userlist 用户列表
- * @return string info[0].nums 房间人数
- * @return string info[0].votestotal 主播映票
- * @return string info[0].guard_type 守护类型
- * @return string msg 提示信息
- */
- public function getUserLists() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $liveuid=checkNull($this->liveuid);
- $stream=checkNull($this->stream);
- $p=$this->p;
- /* 用户列表 */
- $info=$this->getUserList($liveuid,$stream,$p);
- $rs['info'][0]=$info;
- return $rs;
- }
- protected function getUserList($liveuid,$stream,$p=1) {
- /* 用户列表 */
- $n=1;
- $pnum=20;
- $start=($p-1)*$pnum;
-
-
-
-
- $list=array();
- $uidlist=DI()->redis -> zRevRange('user_'.$stream,$start,$pnum,true);
-
- foreach($uidlist as $k=>$v){
- $userinfo=getUserInfo($k);
- $info=explode(".",$v);
- $userinfo['contribution']=(string)$info[0];
-
-
-
- $list[]=$userinfo;
- }
-
-
- if(!$list){
- $list=array();
- }
-
- $nums=DI()->redis->zCard('user_'.$stream);
- if(!$nums){
- $nums=0;
- }
- $rs['userlist']=$list;
- $rs['nums']=(string)$nums;
- /* 主播信息 */
- $domain = new Domain_Live();
- $rs['votestotal']=$domain->getVotes($liveuid);
-
- return $rs;
- }
-
-
- /**
- * 弹窗
- * @desc 用于直播间弹窗信息
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].consumption 消费总数
- * @return string info[0].votestotal 票总数
- * @return string msg 提示信息
- */
- public function getPop() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $liveuid=checkNull($this->liveuid);
- $touid=checkNull($this->touid);
- $info=getUserInfo($touid);
- if(!$info){
- $rs['code']=1002;
- $rs['msg']='用户信息不存在';
- return $rs;
- }
- $info['action']='0';
- $rs['info'][0]=$info;
- return $rs;
- }
- /**
- * 礼物列表
- * @desc 用于获取礼物列表
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].coin 余额
- * @return array info[0].giftlist 礼物列表
- * @return string info[0].giftlist[].id 礼物ID
- * @return string info[0].giftlist[].type 礼物类型
- * @return string info[0].giftlist[].mark 礼物标识
- * @return string info[0].giftlist[].giftname 礼物名称
- * @return string info[0].giftlist[].needcoin 礼物价格
- * @return string info[0].giftlist[].gifticon 礼物图片
- * @return string msg 提示信息
- */
- public function getGiftList() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $domain = new Domain_Live();
- $giftlist=$domain->getGiftList();
-
-
- $domain2 = new Domain_User();
- $coin=$domain2->getBalance($uid);
-
- $rs['info'][0]['giftlist']=$giftlist;
- $rs['info'][0]['coin']=$coin['coin'];
- return $rs;
- }
- /**
- * 赠送礼物
- * @desc 用于赠送礼物
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].gifttoken 礼物token
- * @return string info[0].level 用户等级
- * @return string info[0].coin 用户余额
- * @return string msg 提示信息
- */
- public function sendGift() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $liveuid=checkNull($this->liveuid);
- $stream=checkNull($this->stream);
- $giftid=checkNull($this->giftid);
- $giftcount=checkNull($this->giftcount);
- $touids=checkNull($this->touids);
-
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $domain = new Domain_Live();
-
-
- $giftlist=$domain->getGiftList();
- $gift_info=array();
- foreach($giftlist as $k=>$v){
- if($giftid == $v['id']){
- $gift_info=$v;
- }
- }
-
- if(!$gift_info){
- $rs['code']=1002;
- $rs['msg']='礼物信息不存在';
- return $rs;
- }
-
-
- $domain = new Domain_Live();
- $result=$domain->sendGift($uid,$liveuid,$stream,$giftid,$giftcount,$touids);
-
- if($result==1001){
- $rs['code']=1001;
- $rs['msg']='余额不足';
- return $rs;
- }else if($result==1002){
- $rs['code']=1002;
- $rs['msg']='礼物信息不存在';
- return $rs;
- }else if($result==1004){
- $rs['code']=1004;
- $rs['msg']='请选择接收礼物用户';
- return $rs;
- }
-
- $rs['info'][0]['gifttoken']=$result['gifttoken'];
- $rs['info'][0]['level']=$result['level'];
- $rs['info'][0]['coin']=$result['coin'];
-
- unset($result['gifttoken']);
- unset($result['level']);
- unset($result['coin']);
- DI()->redis -> set($rs['info'][0]['gifttoken'],json_encode($result['list']));
-
-
- return $rs;
- }
-
- /**
- * 发送弹幕
- * @desc 用于发送弹幕
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].barragetoken 礼物token
- * @return string info[0].level 用户等级
- * @return string info[0].coin 用户余额
- * @return string msg 提示信息
- */
- public function sendBarrage() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $liveuid=checkNull($this->liveuid);
- $stream=checkNull($this->stream);
- $giftid=0;
- $giftcount=1;
-
- $content=checkNull($this->content);
- if($content==''){
- $rs['code'] = 1003;
- $rs['msg'] = '弹幕内容不能为空';
- return $rs;
- }
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $domain = new Domain_Live();
- $result=$domain->sendBarrage($uid,$liveuid,$stream,$giftid,$giftcount,$content);
-
- if($result==1001){
- $rs['code']=1001;
- $rs['msg']='余额不足';
- return $rs;
- }else if($result==1002){
- $rs['code']=1002;
- $rs['msg']='礼物信息不存在';
- return $rs;
- }
-
- $rs['info'][0]['barragetoken']=$result['barragetoken'];
- $rs['info'][0]['level']=$result['level'];
- $rs['info'][0]['coin']=$result['coin'];
-
- unset($result['barragetoken']);
- DI()->redis -> set($rs['info'][0]['barragetoken'],json_encode($result));
- return $rs;
- }
-
-
- /**
- * 主播映票
- * @desc 用于获取主播映票
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].votestotal 用户总数
- * @return string msg 提示信息
- */
- public function getVotes() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $liveuid=checkNull($this->liveuid);
- $domain = new Domain_Live();
- $info=$domain->getVotes($liveuid);
-
- $rs['info'][0]=$info;
- return $rs;
- }
- /**
- * 用户余额
- * @desc 用于获取用户余额
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].coin 余额
- * @return string msg 提示信息
- */
- public function getCoin() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
-
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
-
- $domain2 = new Domain_User();
- $coin=$domain2->getBalance($uid);
- $rs['info'][0]['coin']=$coin['coin'];
- return $rs;
- }
- /**
- * 检测房间状态
- * @desc 用于检测房间状态
- * @return int code 操作码,0表示成功
- * @return array info
- * @return string info[0].status 状态 0关1开
- * @return string msg 提示信息
- */
- public function checkLiveing() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $uid=checkNull($this->uid);
- $token=checkNull($this->token);
- $stream=checkNull($this->stream);
- $domain = new Domain_Live();
- $checkToken=checkToken($uid,$token);
- if($checkToken==700){
- //将主播关播
- $domain->stopRoom($uid,$stream);
- $rs['code'] = $checkToken;
- $rs['msg'] = '您的登陆状态失效,请重新登陆!';
- return $rs;
- }
-
- $info=$domain->checkLiveing($uid,$stream);
-
- $rs['info'][0]['status']=$info;
- return $rs;
- }
- /**
- * 获取直播信息
- * @desc 用于个人中心进入直播间获取直播信息
- * @return int code 操作码,0表示成功
- * @return array info 直播信息
- * @return string msg 提示信息
- */
- public function getLiveInfo() {
- $rs = array('code' => 0, 'msg' => '', 'info' => array());
-
- $liveuid=checkNull($this->liveuid);
-
- if($liveuid<1){
- $rs['code'] = 1001;
- $rs['msg'] = '参数错误';
- return $rs;
- }
-
-
- $domain2 = new Domain_Live();
- $info=$domain2->getLiveInfo($liveuid);
- if(!$info){
- $rs['code'] = 1002;
- $rs['msg'] = '直播已结束';
- return $rs;
- }
- $rs['info'][0]=$info;
- return $rs;
- }
-
- }
|