123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257 |
- <?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,$liveuid);
- $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);
- // }
- // 获取主播的 头像=live_avatar , 名字=live_nicename
- $live_info_json = DI()->redis -> get('userinfo_'.$liveuid);
- // 检查值是否存在
- if ($live_info_json !== false) {
- $live_d = json_decode($live_info_json, true);
- $info['user_nicename'] = $live_d['user_nicename'];
- $info['live_avatar'] = $live_d['live_avatar'];
- } else {
- // 键不存在,输出提示信息
- // echo '指定的键在 Redis 中不存在';
- $rs['code'] = 404;
- $rs['msg'] = '请输入正常开播的房间号';
- return $rs;
- }
- $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;
- $result = array_merge($live_d, $info);
- $rs['info'][0]=$result;
- 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;
- }
-
- }
|