Live.php 35 KB

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