tonghuaAction.php 3.2 KB

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