id | user | number |
---|---|---|
238 | LutovVO | 50512 |
<? // require($_SERVER["DOCUMENT_ROOT"]."/bitrix/modules/main/include/prolog_before.php"); $USER = new CUser; $userlogin = $USER->GetLogin(); // $results = $DB->Query("SELECT `number` FROM `phones` WHERE `user`='".$userlogin."' LIMIT 1"); $userphone = $results->Fetch(); if (!empty($_POST['call'])) { // $recipient = str_replace(' ', '', $_POST['recipient']); $recipient = str_replace('+', '', $recipient); $recipient = str_replace('-', '', $recipient); $recipient = str_replace('(', '', $recipient); $recipient = str_replace(')', '', $recipient); $answer = ''; // C Asterisk $command = array(); $command[1] = 'action=login&username=PORTAL&secret=PASSWORD&events=off'; $command[2] = 'action=originate&channel=local/'.$userphone['number'].'@PORTAL&context=redirportal&exten='.$recipient.'&priority=1&CallerID=PORTAL'; $command[3] = 'action=logoff'; // CURL $curl = curl_init(); foreach($command as $key => $data) { // , $mansession = $_COOKIE['mansession_id']; $cookie = 'mansession_id="'.$mansession.'"'; // - Asterisk curl_setopt($curl, CURLOPT_URL, 'http://127.0.0.1:8088/rawman'); // curl_setopt($curl, CURLOPT_HEADER, 1); // POST curl_setopt($curl, CURLOPT_POST, 1); // cookie curl_setopt($curl, CURLOPT_COOKIE, $cookie); // CURL , ( ) curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // curl_setopt($curl, CURLOPT_POSTFIELDS, $data); $res = curl_exec($curl); // , if(!$res) { $error = curl_error($curl).'('.curl_errno($curl).')'; echo $error; } // , else { // preg_match('/mansession_id="(.*)";/', $res, $cut); $_COOKIE['mansession_id'] = $cut[1]; // $tech_answer .= '<h2> '.$key.': '.$data.'</h2>'.'<p><b>:</b></p>'.nl2br($res).'<br/><hr><br/>'; $answer = '<p style="color:green;"> </p>'; } } curl_close($curl); die('ok'); } else { die('not_ok'); } ?>
function createRequestObject() { if (typeof XMLHttpRequest === 'undefined') { XMLHttpRequest = function() { try { return new ActiveXObject("Msxml2.XMLHTTP.6.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP.3.0"); } catch(e) {} try { return new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) {} try { return new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) {} throw new Error("This browser does not support XMLHttpRequest."); }; } return new XMLHttpRequest(); } function ajax_submit(params, path) { var req; req = createRequestObject(); req.open('POST', path, true); req.timeout=5000; req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); req.onreadystatechange = function() { if (req.readyState == 4) { if(req.status == 200) { // alert(" : "+req.responseText); if (req.responseText=='ok') { // alert('!'); } else { // alert(' !'); } } else { // alert(' '); } } } req.send(params); } function call_to (number) { var params = 'call=1&recipient='+number; var path = '/services/telephony/call/'; ajax_submit(params, path) }
<span class="link" onclick="call_to('50512')"></span>
Source: https://habr.com/ru/post/178467/
All Articles