tonghuaAction.php 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  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. $ondats = json_decode(arrvalue($gbarr,'data'), true);
  35. $online = false;
  36. if($ondats){
  37. if($ondats['pc']==$id)$online = true;
  38. if($ondats['app']==$id)$online = true;
  39. }
  40. if(!$online){
  41. $trows = m('login')->getall('`uid`='.$id.' and `online`=1 and `ispush`=1');
  42. if(!$trows)return returnerror('对方不在线,无法通话');
  43. $appfw = $this->option->getval('reimappwxsystem');
  44. if($appfw != '1')return returnerror('服务端没开启APP可用');
  45. $isbo = true;
  46. foreach($trows as $k=>$rs){
  47. $web = $rs['web'];
  48. if(!contain($web, 'iphone'))$isbo = false;
  49. }
  50. //if($isbo)return returnerror('对方使用iphone,暂不支持通话');
  51. }
  52. $barr = c('xinhuapi')->getdata('tonghua','thinit', array('faid'=>$this->adminid,'rtctype'=>$rtctype,'nowtime'=>$nowtime,'toid'=>$id,'type'=>$type));
  53. if(!$barr['success'])return $barr;
  54. $data = $barr['data'];
  55. $key = $data['channel'];
  56. c('cache')->set($key, $data, 60);
  57. //保存自己通话里面
  58. m('im_tonghua')->insert(array(
  59. 'uid' => $this->adminid,
  60. 'faid' => $this->adminid,
  61. 'channel' =>$data['channel'],
  62. 'type' =>$data['type'],
  63. 'plat' =>$rtctype,
  64. 'joinids' =>$id,
  65. 'toid' =>$id,
  66. 'adddt' =>$this->now,
  67. ));
  68. //异步发送
  69. c('rockqueue')->push('tonghua,call', array('key' => $key,'cishu'=>1));
  70. return $barr;
  71. }
  72. /**
  73. * 取消呼叫
  74. */
  75. public function cancelAction()
  76. {
  77. $channel = $this->get('channel');
  78. $state = (int)$this->get('state','3');
  79. m('im_tonghua')->update('`state`='.$state.'',"`channel`='$channel'");
  80. $barr = c('rockqueue')->push('tonghua,cancel', array('key' => $channel));
  81. if(!$barr['success'])return $barr;
  82. return returnsuccess();
  83. }
  84. /**
  85. * 接电话了(0呼叫中,1同意,2拒绝,3取消,4接受者已打开页面,5呼叫超过30秒无人接听)
  86. */
  87. public function jieAction()
  88. {
  89. $channel = $this->get('channel');
  90. $state = (int)$this->get('state','2');
  91. $dbs = m('im_tonghua');
  92. $onrs = $dbs->getone("`channel`='$channel'");
  93. $satype = '';
  94. if(!$onrs)return returnerror('通话不存在');
  95. $zt = $onrs['state'];
  96. if($zt == '3' || $zt=='5')return returnerror('对方已取消');
  97. if($zt=='1')return returnerror('已在另端接通');
  98. if($zt=='2')return returnerror('已在另端拒绝');
  99. $nowtime = strtotime($this->now);
  100. $upstsr = '`state`='.$state.'';
  101. if($state==1)$upstsr.=",`jiedt`='$this->now'";
  102. $dbs->update($upstsr,"`channel`='$channel'");
  103. $barr = c('rockqueue')->push('tonghua,jie', array('key'=>$channel,'nowtime'=>$nowtime,'uid'=>$this->adminid,'state'=>$state));
  104. if(!$barr['success'])return $barr;
  105. return returnsuccess(array(
  106. 'satype' => ''
  107. ));
  108. }
  109. /**
  110. * 接通
  111. */
  112. public function jietongAction()
  113. {
  114. $channel = $this->get('channel');
  115. $barr = c('xinhuapi')->getdata('tonghua','jietong', array('uid'=>$this->adminid,'channel'=>$channel));
  116. if($barr['success']){
  117. $bars = $this->jieAction();
  118. if(!$bars['success'])return $bars;
  119. $datas= $bars['data'];
  120. foreach($datas as $k=>$v)$barr['data'][$k] = $v;
  121. }
  122. return $barr;
  123. }
  124. /**
  125. * 结束通话
  126. */
  127. public function jiesuAction()
  128. {
  129. $nowtime = strtotime($this->now);
  130. $channel = $this->get('channel');
  131. $toid = (int)$this->get('toid');
  132. c('rockqueue')->push('tonghua,jiesu', array('uid'=>$this->adminid,'toid'=>$toid,'nowtime'=>$nowtime,'channel'=>$channel));
  133. m('im_tonghua')->update("`enddt`='$this->now',`jieid`='$this->adminid'","`channel`='$channel'");
  134. return returnsuccess();
  135. }
  136. /**
  137. * 接受者打开了界面
  138. */
  139. public function receopenAction()
  140. {
  141. $channel = $this->get('channel');
  142. $where = "`channel`='$channel'";
  143. $dbs = m('im_tonghua');
  144. $dbs->update('`state`=4', $where);
  145. $thrs = $dbs->getone($where);
  146. $sytime = time()-strtotime($thrs['adddt']);
  147. return returnsuccess(array(
  148. 'sytime' => $sytime
  149. ));
  150. }
  151. /**
  152. * 时时读取状态
  153. */
  154. public function stateAction()
  155. {
  156. $channel = $this->get('channel');
  157. $onrs = m('im_tonghua')->getone("`channel`='$channel'");
  158. $tayar = array('call','tongyi','jujue','cancel','wait','cancel','end');
  159. return returnsuccess(array(
  160. 'state' => arrvalue($tayar, $onrs['state']),
  161. 'th_channel'=> $channel
  162. ));
  163. }
  164. /**
  165. * 判断通话是不是结束
  166. */
  167. public function statethAction()
  168. {
  169. $channel = $this->get('channel');
  170. $onrs = m('im_tonghua')->getone("`channel`='$channel'");
  171. $state = 'wu';
  172. if($onrs && !isempt($onrs['enddt']))$state = 'jiesu';
  173. return returnsuccess(array(
  174. 'state' => $state
  175. ));
  176. }
  177. }
粤ICP备19079148号