VirtualCallService.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | likeadmin快速开发前后端分离管理后台(PHP版)
  4. // +----------------------------------------------------------------------
  5. // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
  6. // | 开源版本可自由商用,可去除界面版权logo
  7. // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
  8. // | github下载:https://github.com/likeshop-github/likeadmin
  9. // | 访问官网:https://www.likeadmin.cn
  10. // | likeadmin团队 版权所有 拥有最终解释权
  11. // +----------------------------------------------------------------------
  12. // | author: likeadminTeam
  13. // +----------------------------------------------------------------------
  14. namespace app\common\service\call;
  15. use think\facade\Cache;
  16. class VirtualCallService
  17. {
  18. public static $host = 'https://101.37.133.245:11008/';
  19. public static $appId = '989460';
  20. public static $accessToken = 'edcd07d7216446b6ae549a2e621eb42b';
  21. public static function timestamp(){
  22. $time = explode (" ", microtime () );
  23. return $time[1] . "000";
  24. }
  25. /**
  26. * @notes 鉴权
  27. */
  28. public static function auth($bindNumberA, $bindNumberB, $maxBindingTime = 60)
  29. {
  30. $timestamp = self::timestamp();
  31. $sig = md5(self::$appId.self::$accessToken.$timestamp);
  32. $authorization = base64_encode(self::$appId.":".$timestamp);
  33. $url = self::$host . 'voice/1.0.0/middleNumberAXB/'.self::$appId.'/'.$sig;
  34. $header = [
  35. "Accept:application/json",
  36. "Content-Type:application/json;charset=utf-8",
  37. "Authorization:$authorization"
  38. ];
  39. $params = [
  40. //"middleNumber" => "13003426180",
  41. "bindNumberA" => $bindNumberA,
  42. "bindNumberB" => $bindNumberB,
  43. "maxBindingTime" => $maxBindingTime,
  44. "callbackUrl" => "",
  45. ];
  46. $params = json_encode($params);
  47. $response = http_request($url, $params, $header);
  48. return $response;
  49. }
  50. /**
  51. * @notes 虚拟外呼回调通知
  52. */
  53. public static function notify($params)
  54. {
  55. if (empty($params['appId']) || $params['appId'] != self::$appId) {
  56. return ['resultCode' => "200"];
  57. }
  58. return ['resultCode' => "200"];
  59. }
  60. //////////////////优音云平台//////////////////////////
  61. //外显固话
  62. public static function addHiddedPhone($bindNumberA, $bindNumberB){
  63. $url = 'https://xtapi.uincall.com/api/call/addHiddedPhone.action';
  64. $header = [
  65. "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
  66. ];
  67. $data = json_encode([['phone1' => $bindNumberA, 'phone2' => $bindNumberB]]);
  68. //echo $data;die;
  69. $params = [
  70. 'appver' => '1',
  71. 'timestamp' => date('YmdHis'),
  72. 'user' => '075533318487_dev',
  73. 'account' => '075533318487',
  74. 'data' => ($data),
  75. ];
  76. $token = self::getToken();
  77. $params['secret'] = self::getSecret($params, $token);
  78. $params = http_build_query($params, '=', '&');
  79. $response = http_request($url, $params, $header);
  80. return $response;
  81. }
  82. //外显小号
  83. public static function bind($bindNumberA, $bindNumberB, $maxBindingTime = 60){
  84. $url = 'https://xtapi.uincall.com/api/call/bindHiddedPhone.action';
  85. $header = [
  86. "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
  87. ];
  88. $params = [
  89. 'appver' => '1',
  90. 'timestamp' => date('YmdHis'),
  91. 'user' => '075533318487_dev',
  92. 'account' => '075533318487',
  93. 'callingId' => $bindNumberA,
  94. 'transferNum' => $bindNumberB,
  95. 'expiration' => $maxBindingTime,
  96. ];
  97. $token = self::getToken();
  98. $params['secret'] = self::getSecret($params, $token);
  99. $params = http_build_query($params, '=', '&');
  100. $response = http_request($url, $params, $header);
  101. return $response;
  102. }
  103. public static function getToken()
  104. {
  105. if ($token = Cache::get('uincall_token')) {
  106. return $token;
  107. }
  108. $url = 'https://xtapi.uincall.com/api/call/union400Login.action';
  109. $header = [
  110. "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
  111. ];
  112. $params = [
  113. 'appver' => '1',
  114. 'timestamp' => date('YmdHis'),
  115. 'user' => '075533318487_dev',
  116. ];
  117. $params['secret'] = self::getSecret($params, 'da7fd311e57a46af88eb972d47ebc954');
  118. $params = http_build_query($params, '=', '&');
  119. $response = http_request($url, $params, $header);
  120. if (isset($response['errcode']) && $response['errcode'] == 0) {
  121. $exp = strtotime($response['data']['expiredtime']) - time();
  122. Cache::set('uincall_token', $response['data']['token'], $exp);
  123. return $response['data']['token'];
  124. }
  125. return "";
  126. }
  127. public static function getSecret($params,$token)
  128. {
  129. //按键值名排序
  130. ksort($params);
  131. $str = '';
  132. foreach ($params as $key => $value) {
  133. if ($value !== '' && $value !== null) {
  134. $str .= $key . $value;
  135. }
  136. }
  137. $str .= $token;
  138. $sign = md5($str);
  139. return $sign;
  140. }
  141. }