Live.php 35 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244
  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['id'] = $uid;
  602. $userinfo['user_nicename'] = $usernicename;
  603. if(!$city){
  604. $city='好像在火星';
  605. }
  606. $userinfo['city']=$city;
  607. // $stream2=explode('_',$stream);
  608. // $showid=$stream2[1];
  609. $contribution='0';
  610. if($showid && $uid>0){
  611. $contribution=$domain->getContribut($uid,$liveuid,$showid);
  612. }
  613. $userinfo['contribution'] = $contribution;
  614. /* 等级+100 保证等级位置位数相同,最后拼接1 防止末尾出现0 */
  615. $userinfo['sign']=$userinfo['contribution'].'.'.($userinfo['level']+100).'1';
  616. $userinfo['usertype'] = 30;
  617. if($uid<0){
  618. $userinfo['id']=$mobileid;
  619. $token=$mobileid;
  620. }
  621. DI()->redis -> set($token,json_encode($userinfo));
  622. // 一天后过期,自动删除
  623. $nowtime=time();
  624. $expiretime=$nowtime+60*60*24;
  625. if($expiretime > 0){
  626. DI()->redis->expire($token, $expiretime);
  627. }
  628. /* 用户列表 */
  629. $userlists=$this->getUserList($liveuid,$stream);
  630. $configpri=getConfigPri();
  631. $info=array(
  632. 'votestotal'=>$userlists['votestotal'],
  633. 'barrage_fee'=>$configpri['barrage_fee'],
  634. 'userlist_time'=>$configpri['userlist_time'],
  635. 'chatserver'=>$configpri['chatserver'],
  636. 'nums'=>$userlists['nums'],
  637. 'speak_limit'=>$configpri['speak_limit'],
  638. 'barrage_limit'=>$configpri['barrage_limit'],
  639. 'level'=>$userinfo['level']
  640. );
  641. $live_info=$domain->getLiveInfo($liveuid);
  642. $pull=$live_info['pull'];
  643. if($live_info['isvideo']!=1){
  644. $pull=PrivateKeyA('rtmp',$stream,0);
  645. }
  646. $info['pull']=$pull;
  647. $info['userlists']=$userlists['userlist'];
  648. /* 用户余额 */
  649. $domain2 = new Domain_User();
  650. $usercoin=$domain2->getBalance($uid);
  651. $info['coin']=(string)$usercoin['coin'];
  652. /** 敏感词集合*/
  653. $dirtyarr=array();
  654. if($configpri['sensitive_words']){
  655. $dirtyarr=explode(',',$configpri['sensitive_words']);
  656. }
  657. $info['sensitive_words']=$dirtyarr;
  658. $rs['info'][0]=$info;
  659. return $rs;
  660. }
  661. /**
  662. * 用户列表
  663. * @desc 用于直播间获取用户列表
  664. * @return int code 操作码,0表示成功
  665. * @return array info
  666. * @return string info[0].userlist 用户列表
  667. * @return string info[0].nums 房间人数
  668. * @return string info[0].votestotal 主播映票
  669. * @return string info[0].guard_type 守护类型
  670. * @return string msg 提示信息
  671. */
  672. public function getUserLists() {
  673. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  674. $liveuid=checkNull($this->liveuid);
  675. $stream=checkNull($this->stream);
  676. $p=$this->p;
  677. /* 用户列表 */
  678. $info=$this->getUserList($liveuid,$stream,$p);
  679. $rs['info'][0]=$info;
  680. return $rs;
  681. }
  682. protected function getUserList($liveuid,$stream,$p=1) {
  683. /* 用户列表 */
  684. $n=1;
  685. $pnum=20;
  686. $start=($p-1)*$pnum;
  687. $list=array();
  688. $uidlist=DI()->redis -> zRevRange('user_'.$stream,$start,$pnum,true);
  689. foreach($uidlist as $k=>$v){
  690. $userinfo=getUserInfo($k);
  691. $info=explode(".",$v);
  692. $userinfo['contribution']=(string)$info[0];
  693. $list[]=$userinfo;
  694. }
  695. if(!$list){
  696. $list=array();
  697. }
  698. $nums=DI()->redis->zCard('user_'.$stream);
  699. if(!$nums){
  700. $nums=0;
  701. }
  702. $rs['userlist']=$list;
  703. $rs['nums']=(string)$nums;
  704. /* 主播信息 */
  705. $domain = new Domain_Live();
  706. $rs['votestotal']=$domain->getVotes($liveuid);
  707. return $rs;
  708. }
  709. /**
  710. * 弹窗
  711. * @desc 用于直播间弹窗信息
  712. * @return int code 操作码,0表示成功
  713. * @return array info
  714. * @return string info[0].consumption 消费总数
  715. * @return string info[0].votestotal 票总数
  716. * @return string msg 提示信息
  717. */
  718. public function getPop() {
  719. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  720. $uid=checkNull($this->uid);
  721. $liveuid=checkNull($this->liveuid);
  722. $touid=checkNull($this->touid);
  723. $info=getUserInfo($touid);
  724. if(!$info){
  725. $rs['code']=1002;
  726. $rs['msg']='用户信息不存在';
  727. return $rs;
  728. }
  729. $info['action']='0';
  730. $rs['info'][0]=$info;
  731. return $rs;
  732. }
  733. /**
  734. * 礼物列表
  735. * @desc 用于获取礼物列表
  736. * @return int code 操作码,0表示成功
  737. * @return array info
  738. * @return string info[0].coin 余额
  739. * @return array info[0].giftlist 礼物列表
  740. * @return string info[0].giftlist[].id 礼物ID
  741. * @return string info[0].giftlist[].type 礼物类型
  742. * @return string info[0].giftlist[].mark 礼物标识
  743. * @return string info[0].giftlist[].giftname 礼物名称
  744. * @return string info[0].giftlist[].needcoin 礼物价格
  745. * @return string info[0].giftlist[].gifticon 礼物图片
  746. * @return string msg 提示信息
  747. */
  748. public function getGiftList() {
  749. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  750. $uid=checkNull($this->uid);
  751. $token=checkNull($this->token);
  752. $checkToken=checkToken($uid,$token);
  753. if($checkToken==700){
  754. $rs['code'] = $checkToken;
  755. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  756. return $rs;
  757. }
  758. $domain = new Domain_Live();
  759. $giftlist=$domain->getGiftList();
  760. $domain2 = new Domain_User();
  761. $coin=$domain2->getBalance($uid);
  762. $rs['info'][0]['giftlist']=$giftlist;
  763. $rs['info'][0]['coin']=$coin['coin'];
  764. return $rs;
  765. }
  766. /**
  767. * 赠送礼物
  768. * @desc 用于赠送礼物
  769. * @return int code 操作码,0表示成功
  770. * @return array info
  771. * @return string info[0].gifttoken 礼物token
  772. * @return string info[0].level 用户等级
  773. * @return string info[0].coin 用户余额
  774. * @return string msg 提示信息
  775. */
  776. public function sendGift() {
  777. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  778. $uid=checkNull($this->uid);
  779. $token=checkNull($this->token);
  780. $liveuid=checkNull($this->liveuid);
  781. $stream=checkNull($this->stream);
  782. $giftid=checkNull($this->giftid);
  783. $giftcount=checkNull($this->giftcount);
  784. $touids=checkNull($this->touids);
  785. $checkToken=checkToken($uid,$token);
  786. if($checkToken==700){
  787. $rs['code'] = $checkToken;
  788. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  789. return $rs;
  790. }
  791. $domain = new Domain_Live();
  792. $giftlist=$domain->getGiftList();
  793. $gift_info=array();
  794. foreach($giftlist as $k=>$v){
  795. if($giftid == $v['id']){
  796. $gift_info=$v;
  797. }
  798. }
  799. if(!$gift_info){
  800. $rs['code']=1002;
  801. $rs['msg']='礼物信息不存在';
  802. return $rs;
  803. }
  804. $domain = new Domain_Live();
  805. $result=$domain->sendGift($uid,$liveuid,$stream,$giftid,$giftcount,$touids);
  806. if($result==1001){
  807. $rs['code']=1001;
  808. $rs['msg']='余额不足';
  809. return $rs;
  810. }else if($result==1002){
  811. $rs['code']=1002;
  812. $rs['msg']='礼物信息不存在';
  813. return $rs;
  814. }else if($result==1004){
  815. $rs['code']=1004;
  816. $rs['msg']='请选择接收礼物用户';
  817. return $rs;
  818. }
  819. $rs['info'][0]['gifttoken']=$result['gifttoken'];
  820. $rs['info'][0]['level']=$result['level'];
  821. $rs['info'][0]['coin']=$result['coin'];
  822. unset($result['gifttoken']);
  823. unset($result['level']);
  824. unset($result['coin']);
  825. DI()->redis -> set($rs['info'][0]['gifttoken'],json_encode($result['list']));
  826. return $rs;
  827. }
  828. /**
  829. * 发送弹幕
  830. * @desc 用于发送弹幕
  831. * @return int code 操作码,0表示成功
  832. * @return array info
  833. * @return string info[0].barragetoken 礼物token
  834. * @return string info[0].level 用户等级
  835. * @return string info[0].coin 用户余额
  836. * @return string msg 提示信息
  837. */
  838. public function sendBarrage() {
  839. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  840. $uid=checkNull($this->uid);
  841. $token=checkNull($this->token);
  842. $liveuid=checkNull($this->liveuid);
  843. $stream=checkNull($this->stream);
  844. $giftid=0;
  845. $giftcount=1;
  846. $content=checkNull($this->content);
  847. if($content==''){
  848. $rs['code'] = 1003;
  849. $rs['msg'] = '弹幕内容不能为空';
  850. return $rs;
  851. }
  852. $checkToken=checkToken($uid,$token);
  853. if($checkToken==700){
  854. $rs['code'] = $checkToken;
  855. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  856. return $rs;
  857. }
  858. $domain = new Domain_Live();
  859. $result=$domain->sendBarrage($uid,$liveuid,$stream,$giftid,$giftcount,$content);
  860. if($result==1001){
  861. $rs['code']=1001;
  862. $rs['msg']='余额不足';
  863. return $rs;
  864. }else if($result==1002){
  865. $rs['code']=1002;
  866. $rs['msg']='礼物信息不存在';
  867. return $rs;
  868. }
  869. $rs['info'][0]['barragetoken']=$result['barragetoken'];
  870. $rs['info'][0]['level']=$result['level'];
  871. $rs['info'][0]['coin']=$result['coin'];
  872. unset($result['barragetoken']);
  873. DI()->redis -> set($rs['info'][0]['barragetoken'],json_encode($result));
  874. return $rs;
  875. }
  876. /**
  877. * 主播映票
  878. * @desc 用于获取主播映票
  879. * @return int code 操作码,0表示成功
  880. * @return array info
  881. * @return string info[0].votestotal 用户总数
  882. * @return string msg 提示信息
  883. */
  884. public function getVotes() {
  885. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  886. $liveuid=checkNull($this->liveuid);
  887. $domain = new Domain_Live();
  888. $info=$domain->getVotes($liveuid);
  889. $rs['info'][0]=$info;
  890. return $rs;
  891. }
  892. /**
  893. * 用户余额
  894. * @desc 用于获取用户余额
  895. * @return int code 操作码,0表示成功
  896. * @return array info
  897. * @return string info[0].coin 余额
  898. * @return string msg 提示信息
  899. */
  900. public function getCoin() {
  901. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  902. $uid=checkNull($this->uid);
  903. $token=checkNull($this->token);
  904. $checkToken=checkToken($uid,$token);
  905. if($checkToken==700){
  906. $rs['code'] = $checkToken;
  907. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  908. return $rs;
  909. }
  910. $domain2 = new Domain_User();
  911. $coin=$domain2->getBalance($uid);
  912. $rs['info'][0]['coin']=$coin['coin'];
  913. return $rs;
  914. }
  915. /**
  916. * 检测房间状态
  917. * @desc 用于检测房间状态
  918. * @return int code 操作码,0表示成功
  919. * @return array info
  920. * @return string info[0].status 状态 0关1开
  921. * @return string msg 提示信息
  922. */
  923. public function checkLiveing() {
  924. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  925. $uid=checkNull($this->uid);
  926. $token=checkNull($this->token);
  927. $stream=checkNull($this->stream);
  928. $domain = new Domain_Live();
  929. $checkToken=checkToken($uid,$token);
  930. if($checkToken==700){
  931. //将主播关播
  932. $domain->stopRoom($uid,$stream);
  933. $rs['code'] = $checkToken;
  934. $rs['msg'] = '您的登陆状态失效,请重新登陆!';
  935. return $rs;
  936. }
  937. $info=$domain->checkLiveing($uid,$stream);
  938. $rs['info'][0]['status']=$info;
  939. return $rs;
  940. }
  941. /**
  942. * 获取直播信息
  943. * @desc 用于个人中心进入直播间获取直播信息
  944. * @return int code 操作码,0表示成功
  945. * @return array info 直播信息
  946. * @return string msg 提示信息
  947. */
  948. public function getLiveInfo() {
  949. $rs = array('code' => 0, 'msg' => '', 'info' => array());
  950. $liveuid=checkNull($this->liveuid);
  951. if($liveuid<1){
  952. $rs['code'] = 1001;
  953. $rs['msg'] = '参数错误';
  954. return $rs;
  955. }
  956. $domain2 = new Domain_Live();
  957. $info=$domain2->getLiveInfo($liveuid);
  958. if(!$info){
  959. $rs['code'] = 1002;
  960. $rs['msg'] = '直播已结束';
  961. return $rs;
  962. }
  963. $rs['info'][0]=$info;
  964. return $rs;
  965. }
  966. }