tonghuaAction.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <?php
  2. /**
  3. * 语音通话
  4. *
  5. */
  6. class tonghuaClassAction extends runtAction
  7. {
  8. public function sendcpush($arr, $isnei=false)
  9. {
  10. $arr['msgtype'] = 'calltonghua';
  11. $arr['type'] = 'calltonghua';
  12. $reimobj = m('reim');
  13. $reimobj->pushserver('sendapp', $arr);
  14. $reimobj->pushserver('send', $arr);
  15. if($isnei)c('JPush')->sendJpush($arr);
  16. }
  17. /**
  18. * 呼叫发送
  19. * http://192.168.1.2/app/xinhu/task.php?m=tonghua|runt&a=call&key=d9ydh2d8
  20. */
  21. public function callAction()
  22. {
  23. $key = $this->getparams('key');
  24. $cishu = (int)$this->getparams('cishu','1');
  25. if($cishu>=15)return;
  26. if(!$key)return;
  27. $data = c('cache')->get($key);
  28. if(!$data)return;
  29. $channel = $data['channel'];
  30. $uid = $data['uid'];
  31. $urs = m('admin')->getone($uid);
  32. $thrs = m('im_tonghua')->getone("`channel`='$channel'");
  33. if(!$thrs)return;
  34. if($thrs['state']>0)return;
  35. $this->rock->adminid = $uid;
  36. $this->rock->adminname = $urs['name'];
  37. if($cishu==1){
  38. $typea= array('语音','视频');
  39. $cont = $this->jm->base64encode('['.$typea[$data['type']].'通话]');
  40. $pushcont = $this->jm->base64encode('邀请与您'.$typea[$data['type']].'通话...');
  41. m('reim')->sendinfor('user', $uid, $data['toid'], array(
  42. 'optdt' => $thrs['adddt'],
  43. 'cont' => $cont,
  44. 'pushcont' => $pushcont,
  45. 'msgid' => $channel
  46. ));
  47. }
  48. //每2秒呼叫一次
  49. $this->sendcpush(array(
  50. 'adminid' => $uid,
  51. 'adminname' => $urs['name'],
  52. 'adminface' => m('admin')->getface($urs['face']),
  53. 'th_type' => $data['type'],
  54. 'calltype' => 'call',
  55. 'th_channel' => $channel,
  56. 'th_appid' => $data['appid'],
  57. 'th_time' => time()-strtotime($thrs['adddt']),
  58. 'receid' => $data['toid']
  59. ));
  60. c('rockqueue')->push('tonghua,call', array('key' => $key,'cishu'=>$cishu+1),time()+2);
  61. return 'success';
  62. }
  63. /**
  64. * 取消呼叫
  65. */
  66. public function cancelAction()
  67. {
  68. $key = $this->getparams('key');
  69. $data = c('cache')->get($key);
  70. if(!$data)return;
  71. $channel = $data['channel'];
  72. $this->sendcpush(array(
  73. 'adminid' => $data['uid'],
  74. 'calltype' => 'cancel',
  75. 'th_channel'=> $channel,
  76. 'receid' => $data['toid']
  77. ), true);
  78. return 'success';
  79. }
  80. /**
  81. * 拒接/同意
  82. */
  83. public function jieAction()
  84. {
  85. $key = $this->getparams('key');
  86. $state = (int)$this->getparams('state','2');
  87. $nowtime = $this->getparams('nowtime');
  88. $uid = (int)$this->getparams('uid','0');
  89. $data = c('cache')->get($key);
  90. if(!$data)return;
  91. $channel = $data['channel'];
  92. $tayar = array('','tongyi','jujue');
  93. $this->sendcpush(array(
  94. 'adminid' => $data['toid'],
  95. 'calltype' => $tayar[$state],
  96. 'th_channel'=> $channel,
  97. 'receid' => $data['uid'].','.$data['toid']
  98. ));
  99. c('xinhuapi')->getdata('tonghua','jietongs', array('uid'=>$uid,'state'=>$state,'nowtime'=>$nowtime,'channel'=>$channel));
  100. return 'success';
  101. }
  102. /**
  103. * 结束通话
  104. */
  105. public function jiesuAction()
  106. {
  107. $uid = (int)$this->getparams('uid');
  108. $toid = (int)$this->getparams('toid');
  109. $nowtime = $this->getparams('nowtime');
  110. $channel = $this->getparams('channel');
  111. $this->sendcpush(array(
  112. 'adminid' => $uid,
  113. 'calltype' => 'jiesu',
  114. 'th_channel'=> $channel,
  115. 'receid' => $toid
  116. ));
  117. return c('xinhuapi')->getdata('tonghua','jiesu', array('uid'=>$uid,'nowtime'=>$nowtime,'channel'=>$channel));
  118. }
  119. }
粤ICP备19079148号