tonghuaAction.php 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. if($id==$this->adminid)return returnerror('不能和自己通话');
  13. $nowtime = strtotime($this->now);
  14. //判断用户有没有在线
  15. $gbarr = m('reim')->pushserver('getonline', array(
  16. 'onlineid' => $id
  17. ));
  18. if(!$gbarr)return returnerror('没有服务端');
  19. if(!$gbarr['success'])return $gbarr;
  20. $ondats = json_decode(arrvalue($gbarr,'data'), true);
  21. $online = false;
  22. if($ondats){
  23. if($ondats['pc']==$id)$online = true;
  24. if($ondats['app']==$id)$online = true;
  25. }
  26. if(!$online){
  27. $to = m('login')->rows('`uid`='.$id.' and `online`=1 and `ispush`=1');
  28. if($to==0)return returnerror('对方不在线,无法通话');
  29. }
  30. $barr = c('xinhuapi')->getdata('tonghua','thinit', array('faid'=>$this->adminid,'nowtime'=>$nowtime,'toid'=>$id,'type'=>$type));
  31. if(!$barr['success'])return $barr;
  32. $data = $barr['data'];
  33. $key = $data['channel'];
  34. c('cache')->set($key, $data, 60);
  35. //保存自己通话里面
  36. m('im_tonghua')->insert(array(
  37. 'uid' => $this->adminid,
  38. 'faid' => $this->adminid,
  39. 'channel' =>$data['channel'],
  40. 'type' =>$data['type'],
  41. 'joinids' =>$id,
  42. 'adddt' =>$this->now,
  43. ));
  44. //异步发送
  45. c('rockqueue')->push('tonghua,call', array('key' => $key,'cishu'=>1));
  46. return $barr;
  47. }
  48. /**
  49. * 取消呼叫
  50. */
  51. public function cancelAction()
  52. {
  53. $channel = $this->get('channel');
  54. $state = (int)$this->get('state','3');
  55. m('im_tonghua')->update('`state`='.$state.'',"`channel`='$channel'");
  56. $barr = c('rockqueue')->push('tonghua,cancel', array('key' => $channel));
  57. if(!$barr['success'])return $barr;
  58. return returnsuccess();
  59. }
  60. /**
  61. * 接电话了(1同意,2拒绝,3取消,4接受者已打开页面,5呼叫超过30秒无人接听)
  62. */
  63. public function jieAction()
  64. {
  65. $channel = $this->get('channel');
  66. $state = (int)$this->get('state','2');
  67. $dbs = m('im_tonghua');
  68. $onrs = $dbs->getone("`channel`='$channel'");
  69. $satype = '';
  70. if(!$onrs)$satype = '通话不存在';
  71. if($onrs && ($onrs['state']=='3' || $onrs['state']=='5'))$satype = '对方已取消';
  72. if(!$satype){
  73. $nowtime = strtotime($this->now);
  74. $upstsr = '`state`='.$state.'';
  75. if($state==1)$upstsr.=",`jiedt`='$this->now'";
  76. $dbs->update($upstsr,"`channel`='$channel'");
  77. $barr = c('rockqueue')->push('tonghua,jie', array('key'=>$channel,'nowtime'=>$nowtime,'uid'=>$this->adminid,'state'=>$state));
  78. if(!$barr['success'])return $barr;
  79. }
  80. return returnsuccess(array(
  81. 'satype' => $satype
  82. ));
  83. }
  84. /**
  85. * 接通
  86. */
  87. public function jietongAction()
  88. {
  89. $channel = $this->get('channel');
  90. $barr = c('xinhuapi')->getdata('tonghua','jietong', array('uid'=>$this->adminid,'channel'=>$channel));
  91. if($barr['success']){
  92. $bars = $this->jieAction();
  93. if(!$bars['success'])return $bars;
  94. $datas= $bars['data'];
  95. foreach($datas as $k=>$v)$barr['data'][$k] = $v;
  96. }
  97. return $barr;
  98. }
  99. /**
  100. * 结束通话
  101. */
  102. public function jiesuAction()
  103. {
  104. $nowtime = strtotime($this->now);
  105. $channel = $this->get('channel');
  106. $toid = (int)$this->get('toid');
  107. c('rockqueue')->push('tonghua,jiesu', array('uid'=>$this->adminid,'toid'=>$toid,'nowtime'=>$nowtime,'channel'=>$channel));
  108. m('im_tonghua')->update("`enddt`='$this->now',`jieid`='$this->adminid'","`channel`='$channel'");
  109. return returnsuccess();
  110. }
  111. /**
  112. * 接受者打开了界面
  113. */
  114. public function receopenAction()
  115. {
  116. $channel = $this->get('channel');
  117. $where = "`channel`='$channel'";
  118. $dbs = m('im_tonghua');
  119. $dbs->update('`state`=4', $where);
  120. $thrs = $dbs->getone($where);
  121. $sytime = time()-strtotime($thrs['adddt']);
  122. return returnsuccess(array(
  123. 'sytime' => $sytime
  124. ));
  125. }
  126. /**
  127. * 时时读取状态
  128. */
  129. public function stateAction()
  130. {
  131. $channel = $this->get('channel');
  132. $onrs = m('im_tonghua')->getone("`channel`='$channel'");
  133. $tayar = array('','tongyi','jujue','cancel','wait','cancel');
  134. return returnsuccess(array(
  135. 'state' => arrvalue($tayar, $onrs['state'])
  136. ));
  137. }
  138. /**
  139. * 判断通话是不是结束
  140. */
  141. public function statethAction()
  142. {
  143. $channel = $this->get('channel');
  144. $onrs = m('im_tonghua')->getone("`channel`='$channel'");
  145. $state = 'wu';
  146. if($onrs && !isempt($onrs['enddt']))$state = 'jiesu';
  147. return returnsuccess(array(
  148. 'state' => $state
  149. ));
  150. }
  151. }
粤ICP备19079148号