| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- <?php
- // +----------------------------------------------------------------------
- // | likeadmin快速开发前后端分离管理后台(PHP版)
- // +----------------------------------------------------------------------
- // | 欢迎阅读学习系统程序代码,建议反馈是我们前进的动力
- // | 开源版本可自由商用,可去除界面版权logo
- // | gitee下载:https://gitee.com/likeshop_gitee/likeadmin
- // | github下载:https://github.com/likeshop-github/likeadmin
- // | 访问官网:https://www.likeadmin.cn
- // | likeadmin团队 版权所有 拥有最终解释权
- // +----------------------------------------------------------------------
- // | author: likeadminTeam
- // +----------------------------------------------------------------------
- namespace app\common\service\call;
- use think\facade\Cache;
- class VirtualCallService
- {
- public static $host = 'https://101.37.133.245:11008/';
- public static $appId = '989460';
- public static $accessToken = 'edcd07d7216446b6ae549a2e621eb42b';
- public static function timestamp(){
- $time = explode (" ", microtime () );
- return $time[1] . "000";
- }
- /**
- * @notes 鉴权
- */
- public static function auth($bindNumberA, $bindNumberB, $maxBindingTime = 60)
- {
- $timestamp = self::timestamp();
- $sig = md5(self::$appId.self::$accessToken.$timestamp);
- $authorization = base64_encode(self::$appId.":".$timestamp);
- $url = self::$host . 'voice/1.0.0/middleNumberAXB/'.self::$appId.'/'.$sig;
- $header = [
- "Accept:application/json",
- "Content-Type:application/json;charset=utf-8",
- "Authorization:$authorization"
- ];
- $params = [
- //"middleNumber" => "13003426180",
- "bindNumberA" => $bindNumberA,
- "bindNumberB" => $bindNumberB,
- "maxBindingTime" => $maxBindingTime,
- "callbackUrl" => "",
- ];
- $params = json_encode($params);
- $response = http_request($url, $params, $header);
- return $response;
- }
- /**
- * @notes 虚拟外呼回调通知
- */
- public static function notify($params)
- {
- if (empty($params['appId']) || $params['appId'] != self::$appId) {
- return ['resultCode' => "200"];
- }
- return ['resultCode' => "200"];
- }
- //////////////////优音云平台//////////////////////////
- //外显固话
- public static function addHiddedPhone($bindNumberA, $bindNumberB){
- $url = 'https://xtapi.uincall.com/api/call/addHiddedPhone.action';
- $header = [
- "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
- ];
- $data = json_encode([['phone1' => $bindNumberA, 'phone2' => $bindNumberB]]);
- //echo $data;die;
- $params = [
- 'appver' => '1',
- 'timestamp' => date('YmdHis'),
- 'user' => '075533318487_dev',
- 'account' => '075533318487',
- 'data' => ($data),
- ];
- $token = self::getToken();
- $params['secret'] = self::getSecret($params, $token);
- $params = http_build_query($params, '=', '&');
- $response = http_request($url, $params, $header);
- return $response;
- }
- //外显小号
- public static function bind($bindNumberA, $bindNumberB, $maxBindingTime = 60){
- $url = 'https://xtapi.uincall.com/api/call/bindHiddedPhone.action';
- $header = [
- "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
- ];
- $params = [
- 'appver' => '1',
- 'timestamp' => date('YmdHis'),
- 'user' => '075533318487_dev',
- 'account' => '075533318487',
- 'callingId' => $bindNumberA,
- 'transferNum' => $bindNumberB,
- 'expiration' => $maxBindingTime,
- ];
- $token = self::getToken();
- $params['secret'] = self::getSecret($params, $token);
- $params = http_build_query($params, '=', '&');
- $response = http_request($url, $params, $header);
- return $response;
- }
- public static function getToken()
- {
- if ($token = Cache::get('uincall_token')) {
- return $token;
- }
- $url = 'https://xtapi.uincall.com/api/call/union400Login.action';
- $header = [
- "Content-Type:application/x-www-form-urlencoded;charset=UTF-8"
- ];
- $params = [
- 'appver' => '1',
- 'timestamp' => date('YmdHis'),
- 'user' => '075533318487_dev',
- ];
- $params['secret'] = self::getSecret($params, 'da7fd311e57a46af88eb972d47ebc954');
- $params = http_build_query($params, '=', '&');
- $response = http_request($url, $params, $header);
- if (isset($response['errcode']) && $response['errcode'] == 0) {
- $exp = strtotime($response['data']['expiredtime']) - time();
- Cache::set('uincall_token', $response['data']['token'], $exp);
- return $response['data']['token'];
- }
- return "";
- }
- public static function getSecret($params,$token)
- {
- //按键值名排序
- ksort($params);
- $str = '';
- foreach ($params as $key => $value) {
- if ($value !== '' && $value !== null) {
- $str .= $key . $value;
- }
- }
- $str .= $token;
- $sign = md5($str);
- return $sign;
- }
- }
|