C
C
ChelBios2019-11-15 18:12:02
PHP
ChelBios, 2019-11-15 18:12:02

How to choose which number to call PHPsip from?

The code is written in the PHPsip library, it calls the number specified in the $to variable.
So how do you choose the number to call from?

<?php 
 
    try{
      $username = 'логин'; 
      $password = 'пароль';
      $server = 'sip.qwerty.ui';
      $to = '+79000000000'; //куда звонить
      
      require_once('PhpSIP.class.php');
      $api = new PhpSIP();
      
      $api->setUsername($username);
      $api->setPassword($password);
 
      $api->addHeader('Subject: click2call');
      $api->setMethod('INVITE');
      $api->setFrom('sip:'.$username.'@'.$server);
      $api->setUri('sip:'.$to.'@'.$server);
 
      $res = $api->send();
 
      if ($res == 200) { 
        $api->setMethod('REFER');
        $api->addHeader('Refer-to: '.$to);
        $api->addHeader('Referred-By: sip:[email protected]'.$api->getSrcIp());
        $api->send();
        //echo "SUCCESS CALL";
        $api->setMethod('BYE');
        $api->send();
 
        $api->listen('NOTIFY');
        $api->reply(481,'Call Leg/Transaction Does Not Exist');
       
      }
 
      while ($res == 'No final response in 5 seconds.') {
        $api->setMethod('CANCEL');
        $res = $api->send();
        echo "{'warning':'No final response in 5 seconds.'}";
      }
      echo "{'result':'".$res."'}";
 
    } catch (Exception $e) {
      echo "{'error':'true', 'text':'".$e."'}";
    }
 
  ?>

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
doexec, 2019-11-15
@doexec

Add a pattern to outgoing calls with the desired number so that they dial "00" in front and add it to the code.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question