12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244 |
- <?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['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']=html_entity_decode($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;
- }
-
- }
|