Live.php 35 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243
  1. <?php
  2. // +—————————————————————————————————————————————————————————————————————
  3. // | Created by Yunbao
  4. // +—————————————————————————————————————————————————————————————————————
  5. // | Copyright (c) 2013~2022 http://www.yunbaokj.com All rights reserved.
  6. // +—————————————————————————————————————————————————————————————————————
  7. // | Author: https://gitee.com/yunbaokeji
  8. // +—————————————————————————————————————————————————————————————————————
  9. // | Date: 2022-02-17
  10. // +—————————————————————————————————————————————————————————————————————
  11. /**
  12. * 直播间
  13. */
  14. class Api_Live extends PhalApi_Api {
  15. public function getRules() {
  16. return array(
  17. 'getSDK' => array(
  18. 'uid' => array('name' => 'uid', 'type' => 'int', 'desc' => '用户ID'),
  19. ),
  20. 'createRoom' => array(
  21. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  22. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  23. 'title' => array('name' => 'title', 'type' => 'string','default'=>'', 'desc' => '直播标题 url编码'),
  24. 'province' => array('name' => 'province', 'type' => 'string', 'default'=>'', 'desc' => '省份'),
  25. 'city' => array('name' => 'city', 'type' => 'string', 'default'=>'', 'desc' => '城市'),
  26. 'lng' => array('name' => 'lng', 'type' => 'string', 'default'=>'0', 'desc' => '经度值'),
  27. 'lat' => array('name' => 'lat', 'type' => 'string', 'default'=>'0', 'desc' => '纬度值'),
  28. 'type' => array('name' => 'type', 'type' => 'int', 'default'=>'0', 'desc' => '直播房间类型,0是普通房间,1是私密房间,2是收费房间,3是计时房间'),
  29. 'type_val' => array('name' => 'type_val', 'type' => 'string', 'default'=>'', 'desc' => '类型值'),
  30. 'anyway' => array('name' => 'anyway', 'type' => 'int', 'default'=>'0', 'desc' => '直播类型 1 PC, 0 app'),
  31. 'liveclassid' => array('name' => 'liveclassid', 'type' => 'int', 'default'=>'0', 'desc' => '直播分类ID'),
  32. 'deviceinfo' => array('name' => 'deviceinfo', 'type' => 'string', 'default'=>'', 'desc' => '设备信息'),
  33. 'thumb' => array('name' => 'thumb', 'type' => 'string', 'desc' => '开播封面'),
  34. ),
  35. 'changeLive' => array(
  36. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  37. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  38. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  39. 'status' => array('name' => 'status', 'type' => 'int', 'require' => true, 'desc' => '直播状态 0关闭 1直播'),
  40. ),
  41. 'stopRoom' => array(
  42. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  43. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  44. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  45. 'type' => array('name' => 'type', 'type' => 'int', 'default'=>'0', 'desc' => '类型'),
  46. 'source' => array('name' => 'source', 'type' => 'string', 'desc' => '访问来源 socekt:断联socket,app传值空'),
  47. 'time' => array('name' => 'time', 'type' => 'string', 'desc' => '当前时间戳'),
  48. 'sign' => array('name' => 'sign', 'type' => 'string', 'desc' => '签名'),
  49. ),
  50. 'stopInfo' => array(
  51. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  52. ),
  53. 'checkLive' => array(
  54. 'uid' => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
  55. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  56. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  57. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  58. ),
  59. 'roomCharge' => array(
  60. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  61. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  62. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  63. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  64. ),
  65. 'timeCharge' => array(
  66. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  67. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  68. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  69. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  70. ),
  71. 'enterRoom' => array(
  72. 'uid' => array('name' => 'uid', 'type' => 'string', 'require' => true, 'desc' => '用户ID'),
  73. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  74. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  75. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  76. 'city' => array('name' => 'city', 'type' => 'string','default'=>'', 'desc' => '城市'),
  77. 'mobileid' => array('name' => 'mobileid', 'type' => 'string','default'=>'', 'desc' => '实际唯一识别码'),
  78. 'usernicename' => array('name' => 'usernicename', 'type' => 'string','default'=>'', 'desc' => '用户名'),
  79. ),
  80. 'getUserLists' => array(
  81. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  82. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  83. 'p' => array('name' => 'p', 'type' => 'int', 'min' => 1, 'default'=>1,'desc' => '页数'),
  84. ),
  85. 'getPop' => array(
  86. 'uid' => array('name' => 'uid', 'type' => 'int', 'require' => true, 'desc' => '用户ID'),
  87. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  88. 'touid' => array('name' => 'touid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '对方ID'),
  89. ),
  90. 'getGiftList' => array(
  91. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  92. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  93. ),
  94. 'sendGift' => array(
  95. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  96. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  97. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  98. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  99. 'giftid' => array('name' => 'giftid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '礼物ID'),
  100. 'giftcount' => array('name' => 'giftcount', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '礼物数量'),
  101. 'touids' => array('name' => 'touids', 'type' => 'string', 'require' => true, 'desc' => '接收送礼物的麦上用户组'),
  102. ),
  103. 'sendBarrage' => array(
  104. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '用户ID'),
  105. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'desc' => '用户token'),
  106. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  107. 'stream' => array('name' => 'stream', 'type' => 'string', 'require' => true, 'desc' => '流名'),
  108. 'content' => array('name' => 'content', 'type' => 'string', 'min' => 1, 'require' => true, 'desc' => '弹幕内容'),
  109. ),
  110. 'getVotes' => array(
  111. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '主播ID'),
  112. ),
  113. 'getCoin' => array(
  114. 'uid' => array('name' => 'uid', 'type' => 'int', 'min' => 1, 'require' => true, 'desc' => '会员ID'),
  115. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'min' => 1, 'desc' => '会员token'),
  116. ),
  117. 'checkLiveing' => array(
  118. 'uid' => array('name' => 'uid', 'type' => 'int','desc' => '会员ID'),
  119. 'token' => array('name' => 'token', 'type' => 'string', 'require' => true, 'min' => 1, 'desc' => '会员token'),
  120. 'stream' => array('name' => 'stream', 'type' => 'string','desc' => '流名'),
  121. ),
  122. 'getLiveInfo' => array(
  123. 'liveuid' => array('name' => 'liveuid', 'type' => 'int', 'desc' => '主播ID'),
  124. ),
  125. );
  126. }
  127. /**
  128. * 获取SDK
  129. * @desc 用于获取SDK类型
  130. * @return int code 操作码,0表示成功
  131. * @return array info
  132. * @return string info[0].live_sdk SDK类型,0金山SDK 1腾讯SDK
  133. * @return object info[0].android 安卓CDN配置
  134. * @return object info[0].ios IOS CDN配置
  135. * @return string info[0].isshop 是否有店铺,0否1是
  136. * @return string msg 提示信息
  137. */
  138. public function getSDK() {
  139. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  140. $uid=checkNull($this->uid);
  141. $cdnset=include API_ROOT.'/../PhalApi/Config/cdnset.php';
  142. $rs['info'][0]=$cdnset;
  143. return $rs;
  144. }
  145. /**
  146. * 创建开播
  147. * @desc 用于用户开播生成记录
  148. * @return int code 操作码,0表示成功
  149. * @return array info
  150. * @return string info[0].userlist_time 用户列表请求间隔
  151. * @return string info[0].barrage_fee 弹幕价格
  152. * @return string info[0].votestotal 主播映票
  153. * @return string info[0].stream 流名
  154. * @return string info[0].push 推流地址
  155. * @return string info[0].pull 播流地址
  156. * @return string info[0].chatserver socket地址
  157. * @return array info[0].game_switch 游戏开关
  158. * @return string info[0].game_switch[][0] 开启的游戏类型
  159. * @return string info[0].game_bankerid 庄家ID
  160. * @return string info[0].game_banker_name 庄家昵称
  161. * @return string info[0].game_banker_avatar 庄家头像
  162. * @return string info[0].game_banker_coin 庄家余额
  163. * @return string info[0].game_banker_limit 上庄限额
  164. * @return object info[0].liang 用户靓号信息
  165. * @return string info[0].liang.name 号码,0表示无靓号
  166. * @return object info[0].vip 用户VIP信息
  167. * @return string info[0].vip.type VIP类型,0表示无VIP,1表示有VIP
  168. * @return string info[0].guard_nums 守护数量
  169. * @return string info[0].thumb 直播封面
  170. * @return string msg 提示信息
  171. */
  172. public function createRoom() {
  173. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  174. $uid = checkNull($this->uid);
  175. $token=checkNull($this->token);
  176. $configpub=getConfigPub();
  177. if($configpub['maintain_switch']==1){
  178. $rs['code']=1002;
  179. $rs['msg']=$configpub['maintain_tips'];
  180. return $rs;
  181. }
  182. $checkToken=checkToken($uid,$token);
  183. if($checkToken==700){
  184. $rs['code'] = $checkToken;
  185. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  186. return $rs;
  187. }
  188. $configpri=getConfigPri();
  189. if($configpri['auth_islimit']==1){
  190. $isauth=isAuth($uid);
  191. if(!$isauth){
  192. $rs['code']=1002;
  193. $rs['msg']='请先进行身份认证或等待审核';
  194. return $rs;
  195. }
  196. }
  197. $userinfo=getUserInfo($uid);
  198. if($configpri['level_islimit']==1){
  199. if( $userinfo['level'] < $configpri['level_limit'] ){
  200. $rs['code']=1003;
  201. $rs['msg']='等级小于'.$configpri['level_limit'].'级,不能直播';
  202. return $rs;
  203. }
  204. }
  205. $nowtime=time();
  206. $showid=$nowtime;
  207. $starttime=$nowtime;
  208. $title=checkNull($this->title);
  209. $province=checkNull($this->province);
  210. $city=checkNull($this->city);
  211. $lng=checkNull($this->lng);
  212. $lat=checkNull($this->lat);
  213. $type=checkNull($this->type);
  214. $type_val=checkNull($this->type_val);
  215. $anyway=checkNull($this->anyway);
  216. $liveclassid=checkNull($this->liveclassid);
  217. $deviceinfo=checkNull($this->deviceinfo);
  218. $thumb_str=checkNull($this->thumb);
  219. $sensitivewords=sensitiveField($title);
  220. if($sensitivewords==1001){
  221. $rs['code'] = 10011;
  222. $rs['msg'] = '输入非法,请重新输入';
  223. return $rs;
  224. }
  225. if( $type==1 && $type_val=='' ){
  226. $rs['code']=1002;
  227. $rs['msg']='密码不能为空';
  228. return $rs;
  229. }else if($type > 1 && $type_val<=0){
  230. $rs['code']=1002;
  231. $rs['msg']='价格不能小于等于0';
  232. return $rs;
  233. }
  234. $stream=$uid.'_'.$nowtime;
  235. $push=PrivateKeyA('rtmp',$stream,1);
  236. $pull=PrivateKeyA('rtmp',$stream,0);
  237. if(!$city){
  238. $city='好像在火星';
  239. }
  240. if(!$lng && $lng!=0){
  241. $lng='';
  242. }
  243. if(!$lat && $lat!=0){
  244. $lat='';
  245. }
  246. //APP原生上传后请求接口保存start
  247. $thumb="";
  248. if($thumb_str){
  249. $cloudtype=$configpri['cloudtype'];
  250. if($cloudtype==1){ //七牛云存储
  251. $thumb= $thumb_str.'?imageView2/2/w/600/h/600';
  252. }else{
  253. $thumb=$thumb_str;
  254. }
  255. }
  256. $dataroom=array(
  257. "uid"=>$uid,
  258. "showid"=>$showid,
  259. "starttime"=>$starttime,
  260. "title"=>$title,
  261. "province"=>$province,
  262. "city"=>$city,
  263. "stream"=>$stream,
  264. "thumb"=>$thumb,
  265. "pull"=>$pull,
  266. "lng"=>$lng,
  267. "lat"=>$lat,
  268. "type"=>$type,
  269. "type_val"=>$type_val,
  270. "isvideo"=>0,
  271. "islive"=>0,
  272. "anyway"=>$anyway,
  273. "liveclassid"=>$liveclassid,
  274. "deviceinfo"=>$deviceinfo,
  275. "hotvotes"=>0,
  276. );
  277. $domain = new Domain_Live();
  278. $result = $domain->createRoom($uid,$dataroom);
  279. if($result===false){
  280. $rs['code'] = 1011;
  281. $rs['msg'] = '开播失败,请重试';
  282. return $rs;
  283. }
  284. $userinfo['city']=$city;
  285. $userinfo['usertype']=50;
  286. $userinfo['sign']='0';
  287. DI()->redis -> set($token,json_encode($userinfo));
  288. $votestotal=$domain->getVotes($uid);
  289. $info['userlist_time']=$configpri['userlist_time'];
  290. $info['barrage_fee']=$configpri['barrage_fee'];
  291. $info['chatserver']=$configpri['chatserver'];
  292. $info['votestotal']=$votestotal;
  293. $info['stream']=$stream;
  294. $info['push']=$push;
  295. $info['pull']=$pull;
  296. // 腾讯APPID
  297. $info['tx_appid']=$configpri['tx_appid'];
  298. // 敏感词集合
  299. $dirtyarr=array();
  300. if($configpri['sensitive_words']){
  301. $dirtyarr=explode(',',$configpri['sensitive_words']);
  302. }
  303. $info['sensitive_words']=$dirtyarr;
  304. //返回直播封面
  305. if($thumb){
  306. $info['thumb']=get_upload_path($thumb);
  307. }else{
  308. $info['thumb']=$userinfo['avatar_thumb'];
  309. }
  310. $rs['info'][0] = $info;
  311. return $rs;
  312. }
  313. /**
  314. * 修改直播状态
  315. * @desc 用于主播修改直播状态
  316. * @return int code 操作码,0表示成功
  317. * @return array info
  318. * @return string info[0].msg 成功提示信息
  319. * @return string msg 提示信息
  320. */
  321. public function changeLive() {
  322. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  323. $uid = checkNull($this->uid);
  324. $token=checkNull($this->token);
  325. $stream=checkNull($this->stream);
  326. $status=checkNull($this->status);
  327. $checkToken=checkToken($uid,$token);
  328. if($checkToken==700){
  329. $rs['code'] = $checkToken;
  330. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  331. return $rs;
  332. }
  333. $domain = new Domain_Live();
  334. $info=$domain->changeLive($uid,$stream,$status);
  335. $rs['info'][0]['msg']='成功';
  336. return $rs;
  337. }
  338. /**
  339. * 关闭直播
  340. * @desc 用于用户结束直播
  341. * @return int code 操作码,0表示成功
  342. * @return array info
  343. * @return string info[0].msg 成功提示信息
  344. * @return string msg 提示信息
  345. */
  346. public function stopRoom() {
  347. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  348. $uid = checkNull($this->uid);
  349. $token=checkNull($this->token);
  350. $stream=checkNull($this->stream);
  351. $type=checkNull($this->type);
  352. $source=checkNull($this->source);
  353. $time=checkNull($this->time);
  354. $sign=checkNull($this->sign);
  355. if(!$source){ //非socket来源,app访问
  356. if(!$time){
  357. $rs['code'] = 1001;
  358. $rs['msg'] = '参数错误,请重试';
  359. return $rs;
  360. }
  361. $now=time();
  362. if($now-$time>300){
  363. $rs['code']=1001;
  364. $rs['msg']='参数错误';
  365. return $rs;
  366. }
  367. if(!$sign){
  368. $rs['code']=1001;
  369. $rs['msg']="参数错误,请重试";
  370. return $rs;
  371. }
  372. $checkdata=array(
  373. 'uid'=>$uid,
  374. 'token'=>$token,
  375. 'time'=>$time,
  376. 'stream'=>$stream,
  377. );
  378. $issign=checkSign($checkdata,$sign);
  379. if(!$issign){
  380. $rs['code']=1001;
  381. $rs['msg']='签名错误';
  382. return $rs;
  383. }
  384. }
  385. $key='stopRoom_'.$stream;
  386. $isexist=getcaches($key);
  387. if(!$isexist ){
  388. $domain = new Domain_Live();
  389. $checkToken=checkToken($uid,$token);
  390. setcaches($key,'1',10);
  391. if($checkToken==700){
  392. $domain->stopRoom($uid,$stream);
  393. $rs['code'] = $checkToken;
  394. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  395. return $rs;
  396. }
  397. $info=$domain->stopRoom($uid,$stream);
  398. }
  399. $rs['info'][0]['msg']='关播成功';
  400. return $rs;
  401. }
  402. /**
  403. * 直播结束信息
  404. * @desc 用于直播结束页面信息展示
  405. * @return int code 操作码,0表示成功
  406. * @return array info
  407. * @return string info[0].nums 人数
  408. * @return string info[0].length 时长
  409. * @return string info[0].votes 映票数
  410. * @return string msg 提示信息
  411. */
  412. public function stopInfo() {
  413. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  414. $stream=checkNull($this->stream);
  415. $domain = new Domain_Live();
  416. $info=$domain->stopInfo($stream);
  417. $rs['info'][0]=$info;
  418. return $rs;
  419. }
  420. /**
  421. * 检查直播状态
  422. * @desc 用于用户进房间时检查直播状态
  423. * @return int code 操作码,0表示成功
  424. * @return array info
  425. * @return string info[0].type 房间类型
  426. * @return string info[0].type_val 收费房间价格,默认0
  427. * @return string info[0].type_msg 提示信息
  428. * @return string info[0].live_type 房间类型 0 视频直播 1 语音聊天室
  429. * @return string msg 提示信息
  430. */
  431. public function checkLive() {
  432. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  433. $uid=checkNull($this->uid);
  434. $token=checkNull($this->token);
  435. $liveuid=checkNull($this->liveuid);
  436. $stream=checkNull($this->stream);
  437. $configpub=getConfigPub();
  438. if($configpub['maintain_switch']==1){
  439. $rs['code']=1002;
  440. $rs['msg']=$configpub['maintain_tips'];
  441. return $rs;
  442. }
  443. if($uid>0){
  444. $checkToken=checkToken($uid,$token);
  445. if($checkToken==700){
  446. $rs['code'] = $checkToken;
  447. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  448. return $rs;
  449. }
  450. }
  451. if($uid==$liveuid){
  452. $rs['code'] = 1011;
  453. $rs['msg'] = '不能进入自己的直播间';
  454. return $rs;
  455. }
  456. $domain = new Domain_Live();
  457. $info=$domain->checkLive($uid,$liveuid,$stream);
  458. if($info==1005){
  459. $rs['code'] = 1005;
  460. $rs['msg'] = '直播已结束';
  461. return $rs;
  462. }else if($info==1007){
  463. $rs['code'] = 1007;
  464. $rs['msg'] = '超管不能进入1v1房间';
  465. return $rs;
  466. }else if($info==1008){
  467. $rs['code'] = 1004;
  468. $rs['msg'] = '您已被踢出房间';
  469. return $rs;
  470. }
  471. $rs['info'][0]=$info;
  472. return $rs;
  473. }
  474. /**
  475. * 房间扣费
  476. * @desc 用于房间扣费
  477. * @return int code 操作码,0表示成功
  478. * @return array info
  479. * @return string info[0].coin 用户余额
  480. * @return string msg 提示信息
  481. */
  482. public function roomCharge() {
  483. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  484. $uid=checkNull($this->uid);
  485. $token=checkNull($this->token);
  486. $liveuid=checkNull($this->liveuid);
  487. $stream=checkNull($this->stream);
  488. $checkToken=checkToken($uid,$token);
  489. if($checkToken==700){
  490. $rs['code'] = $checkToken;
  491. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  492. return $rs;
  493. }
  494. $domain = new Domain_Live();
  495. $info=$domain->roomCharge($uid,$liveuid,$stream);
  496. if($info==1005){
  497. $rs['code'] = 1005;
  498. $rs['msg'] = '直播已结束';
  499. return $rs;
  500. }else if($info==1006){
  501. $rs['code'] = 1006;
  502. $rs['msg'] = '该房间非扣费房间';
  503. return $rs;
  504. }else if($info==1007){
  505. $rs['code'] = 1007;
  506. $rs['msg'] = '房间费用有误';
  507. return $rs;
  508. }else if($info==1008){
  509. $rs['code'] = 1008;
  510. $rs['msg'] = '余额不足';
  511. return $rs;
  512. }
  513. $rs['info'][0]['coin']=$info['coin'];
  514. return $rs;
  515. }
  516. /**
  517. * 房间计时扣费
  518. * @desc 用于房间计时扣费
  519. * @return int code 操作码,0表示成功
  520. * @return array info
  521. * @return string info[0].coin 用户余额
  522. * @return string msg 提示信息
  523. */
  524. public function timeCharge() {
  525. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  526. $uid=checkNull($this->uid);
  527. $token=checkNull($this->token);
  528. $liveuid=checkNull($this->liveuid);
  529. $stream=checkNull($this->stream);
  530. $checkToken=checkToken($uid,$token);
  531. if($checkToken==700){
  532. $rs['code'] = $checkToken;
  533. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  534. return $rs;
  535. }
  536. $domain = new Domain_Live();
  537. $key='timeCharge_'.$stream.'_'.$uid;
  538. $cache=getcaches($key);
  539. if($cache){
  540. $coin=$domain->getUserCoin($uid);
  541. $rs['info'][0]['coin']=$coin['coin'];
  542. return $rs;
  543. }
  544. $info=$domain->roomCharge($uid,$liveuid,$stream);
  545. if($info==1005){
  546. $rs['code'] = 1005;
  547. $rs['msg'] = '直播已结束';
  548. return $rs;
  549. }else if($info==1006){
  550. $rs['code'] = 1006;
  551. $rs['msg'] = '该房间非扣费房间';
  552. return $rs;
  553. }else if($info==1007){
  554. $rs['code'] = 1007;
  555. $rs['msg'] = '房间费用有误';
  556. return $rs;
  557. }else if($info==1008){
  558. $rs['code'] = 1008;
  559. $rs['msg'] = '余额不足';
  560. return $rs;
  561. }
  562. $rs['info'][0]['coin']=$info['coin'];
  563. setcaches($key,1,50);
  564. return $rs;
  565. }
  566. /**
  567. * 进入直播间
  568. * @desc 用于用户进入直播
  569. * @return int code 操作码,0表示成功
  570. * @return array info
  571. * @return string info[0].votestotal 直播映票
  572. * @return string info[0].barrage_fee 弹幕价格
  573. * @return string info[0].userlist_time 用户列表获取间隔
  574. * @return string info[0].chatserver socket地址
  575. * @return string info[0].nums 房间人数
  576. * @return string info[0].pull_url 播流地址
  577. * @return string msg 提示信息
  578. */
  579. public function enterRoom() {
  580. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  581. $uid=checkNull($this->uid);
  582. $token=checkNull($this->token);
  583. $liveuid=checkNull($this->liveuid);
  584. $city=checkNull($this->city);
  585. $stream=checkNull($this->stream);
  586. $mobileid=checkNull($this->mobileid);
  587. $usernicename=checkNull($this->usernicename);
  588. if($uid>0){
  589. $checkToken=checkToken($uid,$token);
  590. if($checkToken==700){
  591. $rs['code'] = $checkToken;
  592. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  593. return $rs;
  594. }
  595. }
  596. $domain = new Domain_Live();
  597. $userinfo=getUserInfo($uid);
  598. if ($userinfo['id']<1){
  599. $userinfo['id'] = $uid;
  600. }
  601. $userinfo['user_nicename'] = $usernicename;
  602. if(!$city){
  603. $city='好像在火星';
  604. }
  605. $userinfo['city']=$city;
  606. $stream2=explode('_',$stream);
  607. $showid=$stream2[1];
  608. $contribution='0';
  609. if($showid && $uid>0){
  610. $contribution=$domain->getContribut($uid,$liveuid,$showid);
  611. }
  612. $userinfo['contribution'] = $contribution;
  613. /* 等级+100 保证等级位置位数相同,最后拼接1 防止末尾出现0 */
  614. $userinfo['sign']=$userinfo['contribution'].'.'.($userinfo['level']+100).'1';
  615. $userinfo['usertype'] = 30;
  616. if($uid<0){
  617. $userinfo['id']=$mobileid;
  618. $token=$mobileid;
  619. }
  620. DI()->redis -> set($token,json_encode($userinfo));
  621. // 一天后过期,自动删除
  622. $nowtime=time();
  623. $expiretime=$nowtime+60*60*24;
  624. if($expiretime > 0){
  625. DI()->redis->expire($token, $expiretime);
  626. }
  627. /* 用户列表 */
  628. $userlists=$this->getUserList($liveuid,$stream);
  629. $configpri=getConfigPri();
  630. $info=array(
  631. 'votestotal'=>$userlists['votestotal'],
  632. 'barrage_fee'=>$configpri['barrage_fee'],
  633. 'userlist_time'=>$configpri['userlist_time'],
  634. 'chatserver'=>$configpri['chatserver'],
  635. 'nums'=>$userlists['nums'],
  636. 'speak_limit'=>$configpri['speak_limit'],
  637. 'barrage_limit'=>$configpri['barrage_limit'],
  638. 'level'=>$userinfo['level']
  639. );
  640. $live_info=$domain->getLiveInfo($liveuid);
  641. $pull=$live_info['pull'];
  642. if($live_info['isvideo']!=1){
  643. $pull=PrivateKeyA('rtmp',$stream,0);
  644. }
  645. $info['pull']=$pull;
  646. $info['userlists']=$userlists['userlist'];
  647. /* 用户余额 */
  648. $domain2 = new Domain_User();
  649. $usercoin=$domain2->getBalance($uid);
  650. $info['coin']=(string)$usercoin['coin'];
  651. /** 敏感词集合*/
  652. $dirtyarr=array();
  653. if($configpri['sensitive_words']){
  654. $dirtyarr=explode(',',$configpri['sensitive_words']);
  655. }
  656. $info['sensitive_words']=$dirtyarr;
  657. $rs['info'][0]=$info;
  658. return $rs;
  659. }
  660. /**
  661. * 用户列表
  662. * @desc 用于直播间获取用户列表
  663. * @return int code 操作码,0表示成功
  664. * @return array info
  665. * @return string info[0].userlist 用户列表
  666. * @return string info[0].nums 房间人数
  667. * @return string info[0].votestotal 主播映票
  668. * @return string info[0].guard_type 守护类型
  669. * @return string msg 提示信息
  670. */
  671. public function getUserLists() {
  672. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  673. $liveuid=checkNull($this->liveuid);
  674. $stream=checkNull($this->stream);
  675. $p=$this->p;
  676. /* 用户列表 */
  677. $info=$this->getUserList($liveuid,$stream,$p);
  678. $rs['info'][0]=$info;
  679. return $rs;
  680. }
  681. protected function getUserList($liveuid,$stream,$p=1) {
  682. /* 用户列表 */
  683. $n=1;
  684. $pnum=20;
  685. $start=($p-1)*$pnum;
  686. $list=array();
  687. $uidlist=DI()->redis -> zRevRange('user_'.$stream,$start,$pnum,true);
  688. foreach($uidlist as $k=>$v){
  689. $userinfo=getUserInfo($k);
  690. $info=explode(".",$v);
  691. $userinfo['contribution']=(string)$info[0];
  692. $list[]=$userinfo;
  693. }
  694. if(!$list){
  695. $list=array();
  696. }
  697. $nums=DI()->redis->zCard('user_'.$stream);
  698. if(!$nums){
  699. $nums=0;
  700. }
  701. $rs['userlist']=$list;
  702. $rs['nums']=(string)$nums;
  703. /* 主播信息 */
  704. $domain = new Domain_Live();
  705. $rs['votestotal']=$domain->getVotes($liveuid);
  706. return $rs;
  707. }
  708. /**
  709. * 弹窗
  710. * @desc 用于直播间弹窗信息
  711. * @return int code 操作码,0表示成功
  712. * @return array info
  713. * @return string info[0].consumption 消费总数
  714. * @return string info[0].votestotal 票总数
  715. * @return string msg 提示信息
  716. */
  717. public function getPop() {
  718. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  719. $uid=checkNull($this->uid);
  720. $liveuid=checkNull($this->liveuid);
  721. $touid=checkNull($this->touid);
  722. $info=getUserInfo($touid);
  723. if(!$info){
  724. $rs['code']=1002;
  725. $rs['msg']='用户信息不存在';
  726. return $rs;
  727. }
  728. $info['action']='0';
  729. $rs['info'][0]=$info;
  730. return $rs;
  731. }
  732. /**
  733. * 礼物列表
  734. * @desc 用于获取礼物列表
  735. * @return int code 操作码,0表示成功
  736. * @return array info
  737. * @return string info[0].coin 余额
  738. * @return array info[0].giftlist 礼物列表
  739. * @return string info[0].giftlist[].id 礼物ID
  740. * @return string info[0].giftlist[].type 礼物类型
  741. * @return string info[0].giftlist[].mark 礼物标识
  742. * @return string info[0].giftlist[].giftname 礼物名称
  743. * @return string info[0].giftlist[].needcoin 礼物价格
  744. * @return string info[0].giftlist[].gifticon 礼物图片
  745. * @return string msg 提示信息
  746. */
  747. public function getGiftList() {
  748. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  749. $uid=checkNull($this->uid);
  750. $token=checkNull($this->token);
  751. $checkToken=checkToken($uid,$token);
  752. if($checkToken==700){
  753. $rs['code'] = $checkToken;
  754. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  755. return $rs;
  756. }
  757. $domain = new Domain_Live();
  758. $giftlist=$domain->getGiftList();
  759. $domain2 = new Domain_User();
  760. $coin=$domain2->getBalance($uid);
  761. $rs['info'][0]['giftlist']=$giftlist;
  762. $rs['info'][0]['coin']=$coin['coin'];
  763. return $rs;
  764. }
  765. /**
  766. * 赠送礼物
  767. * @desc 用于赠送礼物
  768. * @return int code 操作码,0表示成功
  769. * @return array info
  770. * @return string info[0].gifttoken 礼物token
  771. * @return string info[0].level 用户等级
  772. * @return string info[0].coin 用户余额
  773. * @return string msg 提示信息
  774. */
  775. public function sendGift() {
  776. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  777. $uid=checkNull($this->uid);
  778. $token=checkNull($this->token);
  779. $liveuid=checkNull($this->liveuid);
  780. $stream=checkNull($this->stream);
  781. $giftid=checkNull($this->giftid);
  782. $giftcount=checkNull($this->giftcount);
  783. $touids=checkNull($this->touids);
  784. $checkToken=checkToken($uid,$token);
  785. if($checkToken==700){
  786. $rs['code'] = $checkToken;
  787. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  788. return $rs;
  789. }
  790. $domain = new Domain_Live();
  791. $giftlist=$domain->getGiftList();
  792. $gift_info=array();
  793. foreach($giftlist as $k=>$v){
  794. if($giftid == $v['id']){
  795. $gift_info=$v;
  796. }
  797. }
  798. if(!$gift_info){
  799. $rs['code']=1002;
  800. $rs['msg']='礼物信息不存在';
  801. return $rs;
  802. }
  803. $domain = new Domain_Live();
  804. $result=$domain->sendGift($uid,$liveuid,$stream,$giftid,$giftcount,$touids);
  805. if($result==1001){
  806. $rs['code']=1001;
  807. $rs['msg']='余额不足';
  808. return $rs;
  809. }else if($result==1002){
  810. $rs['code']=1002;
  811. $rs['msg']='礼物信息不存在';
  812. return $rs;
  813. }else if($result==1004){
  814. $rs['code']=1004;
  815. $rs['msg']='请选择接收礼物用户';
  816. return $rs;
  817. }
  818. $rs['info'][0]['gifttoken']=$result['gifttoken'];
  819. $rs['info'][0]['level']=$result['level'];
  820. $rs['info'][0]['coin']=$result['coin'];
  821. unset($result['gifttoken']);
  822. unset($result['level']);
  823. unset($result['coin']);
  824. DI()->redis -> set($rs['info'][0]['gifttoken'],json_encode($result['list']));
  825. return $rs;
  826. }
  827. /**
  828. * 发送弹幕
  829. * @desc 用于发送弹幕
  830. * @return int code 操作码,0表示成功
  831. * @return array info
  832. * @return string info[0].barragetoken 礼物token
  833. * @return string info[0].level 用户等级
  834. * @return string info[0].coin 用户余额
  835. * @return string msg 提示信息
  836. */
  837. public function sendBarrage() {
  838. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  839. $uid=checkNull($this->uid);
  840. $token=checkNull($this->token);
  841. $liveuid=checkNull($this->liveuid);
  842. $stream=checkNull($this->stream);
  843. $giftid=0;
  844. $giftcount=1;
  845. $content=checkNull($this->content);
  846. if($content==''){
  847. $rs['code'] = 1003;
  848. $rs['msg'] = '弹幕内容不能为空';
  849. return $rs;
  850. }
  851. $checkToken=checkToken($uid,$token);
  852. if($checkToken==700){
  853. $rs['code'] = $checkToken;
  854. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  855. return $rs;
  856. }
  857. $domain = new Domain_Live();
  858. $result=$domain->sendBarrage($uid,$liveuid,$stream,$giftid,$giftcount,$content);
  859. if($result==1001){
  860. $rs['code']=1001;
  861. $rs['msg']='余额不足';
  862. return $rs;
  863. }else if($result==1002){
  864. $rs['code']=1002;
  865. $rs['msg']='礼物信息不存在';
  866. return $rs;
  867. }
  868. $rs['info'][0]['barragetoken']=$result['barragetoken'];
  869. $rs['info'][0]['level']=$result['level'];
  870. $rs['info'][0]['coin']=$result['coin'];
  871. unset($result['barragetoken']);
  872. DI()->redis -> set($rs['info'][0]['barragetoken'],json_encode($result));
  873. return $rs;
  874. }
  875. /**
  876. * 主播映票
  877. * @desc 用于获取主播映票
  878. * @return int code 操作码,0表示成功
  879. * @return array info
  880. * @return string info[0].votestotal 用户总数
  881. * @return string msg 提示信息
  882. */
  883. public function getVotes() {
  884. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  885. $liveuid=checkNull($this->liveuid);
  886. $domain = new Domain_Live();
  887. $info=$domain->getVotes($liveuid);
  888. $rs['info'][0]=$info;
  889. return $rs;
  890. }
  891. /**
  892. * 用户余额
  893. * @desc 用于获取用户余额
  894. * @return int code 操作码,0表示成功
  895. * @return array info
  896. * @return string info[0].coin 余额
  897. * @return string msg 提示信息
  898. */
  899. public function getCoin() {
  900. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  901. $uid=checkNull($this->uid);
  902. $token=checkNull($this->token);
  903. $checkToken=checkToken($uid,$token);
  904. if($checkToken==700){
  905. $rs['code'] = $checkToken;
  906. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  907. return $rs;
  908. }
  909. $domain2 = new Domain_User();
  910. $coin=$domain2->getBalance($uid);
  911. $rs['info'][0]['coin']=$coin['coin'];
  912. return $rs;
  913. }
  914. /**
  915. * 检测房间状态
  916. * @desc 用于检测房间状态
  917. * @return int code 操作码,0表示成功
  918. * @return array info
  919. * @return string info[0].status 状态 0关1开
  920. * @return string msg 提示信息
  921. */
  922. public function checkLiveing() {
  923. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  924. $uid=checkNull($this->uid);
  925. $token=checkNull($this->token);
  926. $stream=checkNull($this->stream);
  927. $domain = new Domain_Live();
  928. $checkToken=checkToken($uid,$token);
  929. if($checkToken==700){
  930. //将主播关播
  931. $domain->stopRoom($uid,$stream);
  932. $rs['code'] = $checkToken;
  933. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  934. return $rs;
  935. }
  936. $info=$domain->checkLiveing($uid,$stream);
  937. $rs['info'][0]['status']=$info;
  938. return $rs;
  939. }
  940. /**
  941. * 获取直播信息
  942. * @desc 用于个人中心进入直播间获取直播信息
  943. * @return int code 操作码,0表示成功
  944. * @return array info 直播信息
  945. * @return string msg 提示信息
  946. */
  947. public function getLiveInfo() {
  948. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  949. $liveuid=checkNull($this->liveuid);
  950. if($liveuid<1){
  951. $rs['code'] = 1001;
  952. $rs['msg'] = '参数错误';
  953. return $rs;
  954. }
  955. $domain2 = new Domain_Live();
  956. $info=$domain2->getLiveInfo($liveuid);
  957. if(!$info){
  958. $rs['code'] = 1002;
  959. $rs['msg'] = '直播已结束';
  960. return $rs;
  961. }
  962. $rs['info'][0]=$info;
  963. return $rs;
  964. }
  965. }