tonghuaAction.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. <?php
  2. class tonghuaClassAction extends apiAction
  3. {
  4. /**
  5. * 通话初始化
  6. */
  7. public function thinitAction()
  8. {
  9. if(!getconfig('video_bool'))return returnerror('系统未开启音视频');
  10. $id = (int)$this->get('id');
  11. $type = (int)$this->get('type');
  12. $rtctype = 1; //0,1腾讯
  13. if($id==$this->adminid)return returnerror('不能和自己通话');
  14. $nowtime = strtotime($this->now);
  15. $allfields = $this->db->getallfields('[Q]im_tonghua');
  16. if(!in_array('toid', $allfields)){
  17. $this->db->addFields('[Q]im_tonghua','toid','int(11)','0','对于人id可能是组');
  18. }
  19. //判断是不是在通话中
  20. $thrs = m('im_tonghua')->getone('(`faid`='.$id.' or `toid`='.$id.') and (`state` in(0,4) or (`state`=1 and enddt is null))', '*', 'id desc');
  21. if($thrs){
  22. $time = time() - strtotime($thrs['adddt']);
  23. $state = (int)$thrs['state'];
  24. $stime = 60;
  25. if($state == 1)$stime = 30* 60;
  26. if($time < $stime)return returnerror('对方忙线');//60秒内
  27. }
  28. //判断用户有没有在线
  29. $gbarr = m('reim')->pushserver('getonline', array(
  30. 'onlineid' => $id
  31. ));
  32. if(!$gbarr)return returnerror('没有服务端');
  33. if(!$gbarr['success'])return $gbarr;
  34. $online = false;
  35. $sdata = arrvalue($gbarr,'data');
  36. if($sdata){
  37. if(c('check')->isjson($sdata)){
  38. $ondats = json_decode($sdata, true);
  39. if($ondats && isset($ondats['pc'])){
  40. if($ondats['pc']==$id)$online = true;
  41. if($ondats['app']==$id)$online = true;
  42. }
  43. }else{
  44. if(contain(','.$sdata.',',','.$id.','))$online = true;
  45. }
  46. }
  47. if(!$online){
  48. $trows = m('login')->getall('`uid`='.$id.' and `online`=1 and `ispush`=1');
  49. if(!$trows)return returnerror('对方不在线,无法通话');
  50. $appfw = $this->option->getval('reimappwxsystem');
  51. if($appfw != '1')return returnerror('服务端没开启APP可用');
  52. $isbo = true;
  53. foreach($trows as $k=>$rs){
  54. $web = $rs['web'];
  55. if(!contain($web, 'iphone'))$isbo = false;
  56. }
  57. //if($isbo)return returnerror('对方使用iphone,暂不支持通话');
  58. }
  59. $barr = c('xinhuapi')->getdata('tonghua','thinit', array('faid'=>$this->adminid,'rtctype'=>$rtctype,'nowtime'=>$nowtime,'toid'=>$id,'type'=>$type));
  60. if(!$barr['success'])return $barr;
  61. $data = $barr['data'];
  62. $key = $data['channel'];
  63. c('cache')->set($key, $data, 60);
  64. //保存自己通话里面
  65. m('im_tonghua')->insert(array(
  66. 'uid' => $this->adminid,
  67. 'faid' => $this->adminid,
  68. 'channel' =>$data['channel'],
  69. 'type' =>$data['type'],
  70. 'plat' =>$rtctype,
  71. 'joinids' =>$id,
  72. 'toid' =>$id,
  73. 'adddt' =>$this->now,
  74. ));
  75. //异步发送
  76. c('rockqueue')->push('tonghua,call', array('key' => $key,'cishu'=>1));
  77. return $barr;
  78. }
  79. /**
  80. * 取消呼叫
  81. */
  82. public function cancelAction()
  83. {
  84. $channel = $this->get('channel');
  85. $state = (int)$this->get('state','3');
  86. m('im_tonghua')->update('`state`='.$state.'',"`channel`='$channel'");
  87. $barr = c('rockqueue')->push('tonghua,cancel', array('key' => $channel));
  88. if(!$barr['success'])return $barr;
  89. return returnsuccess();
  90. }
  91. /**
  92. * 接电话了(0呼叫中,1同意,2拒绝,3取消,4接受者已打开页面,5呼叫超过30秒无人接听)
  93. */
  94. public function jieAction()
  95. {
  96. $channel = $this->get('channel');
  97. $state = (int)$this->get('state','2');
  98. $dbs = m('im_tonghua');
  99. $onrs = $dbs->getone("`channel`='$channel'");
  100. $satype = '';
  101. if(!$onrs)return returnerror('通话不存在');
  102. $zt = $onrs['state'];
  103. if($zt == '3' || $zt=='5')return returnerror('对方已取消');
  104. if($zt=='1')return returnerror('已在另端接通');
  105. if($zt=='2')return returnerror('已在另端拒绝');
  106. $nowtime = strtotime($this->now);
  107. $upstsr = '`state`='.$state.'';
  108. if($state==1)$upstsr.=",`jiedt`='$this->now'";
  109. $dbs->update($upstsr,"`channel`='$channel'");
  110. $barr = c('rockqueue')->push('tonghua,jie', array('key'=>$channel,'nowtime'=>$nowtime,'uid'=>$this->adminid,'state'=>$state));
  111. if(!$barr['success'])return $barr;
  112. return returnsuccess(array(
  113. 'satype' => ''
  114. ));
  115. }
  116. /**
  117. * 接通
  118. */
  119. public function jietongAction()
  120. {
  121. $channel = $this->get('channel');
  122. $barr = c('xinhuapi')->getdata('tonghua','jietong', array('uid'=>$this->adminid,'channel'=>$channel));
  123. if($barr['success']){
  124. $bars = $this->jieAction();
  125. if(!$bars['success'])return $bars;
  126. $datas= $bars['data'];
  127. foreach($datas as $k=>$v)$barr['data'][$k] = $v;
  128. }
  129. return $barr;
  130. }
  131. /**
  132. * 结束通话
  133. */
  134. public function jiesuAction()
  135. {
  136. $nowtime = strtotime($this->now);
  137. $channel = $this->get('channel');
  138. $toid = (int)$this->get('toid');
  139. c('rockqueue')->push('tonghua,jiesu', array('uid'=>$this->adminid,'toid'=>$toid,'nowtime'=>$nowtime,'channel'=>$channel));
  140. m('im_tonghua')->update("`enddt`='$this->now',`jieid`='$this->adminid'","`channel`='$channel'");
  141. return returnsuccess();
  142. }
  143. /**
  144. * 接受者打开了界面
  145. */
  146. public function receopenAction()
  147. {
  148. $channel = $this->get('channel');
  149. $where = "`channel`='$channel'";
  150. $dbs = m('im_tonghua');
  151. $dbs->update('`state`=4', $where);
  152. $thrs = $dbs->getone($where);
  153. $sytime = time()-strtotime($thrs['adddt']);
  154. return returnsuccess(array(
  155. 'sytime' => $sytime
  156. ));
  157. }
  158. /**
  159. * 时时读取状态
  160. */
  161. public function stateAction()
  162. {
  163. $channel = $this->get('channel');
  164. $onrs = m('im_tonghua')->getone("`channel`='$channel'");
  165. $tayar = array('call','tongyi','jujue','cancel','wait','cancel','end');
  166. return returnsuccess(array(
  167. 'state' => arrvalue($tayar, $onrs['state']),
  168. 'th_channel'=> $channel
  169. ));
  170. }
  171. /**
  172. * 判断通话是不是结束
  173. */
  174. public function statethAction()
  175. {
  176. $channel = $this->get('channel');
  177. $onrs = m('im_tonghua')->getone("`channel`='$channel'");
  178. $state = 'wu';
  179. if($onrs && !isempt($onrs['enddt']))$state = 'jiesu';
  180. return returnsuccess(array(
  181. 'state' => $state
  182. ));
  183. }
  184. }
粤ICP备19079148号