<?php
/* Disable cache */
ini_set('soap.wsdl_cache_enabled', 0);
/* Configure variables */
/* IP of the VoipNow server (including port) */
$IP = "192.168.14.30"; //CHANGE
/* Version of the VoipNow product */
$VERSION = '3.0.0'; //CHANGE
/* Authentication token*/
$TOKEN= '1|n_xOgmCNHc_KLnvOh0T_N8yGM8sX.p05|1|B~GqASQvCd.dpq6tjtV.dmkzk6pX~Dnp'; //CHANGE .dmkzk6pX~Dnp'; //CHANGE
/* set SSL context options */
$streamContext = stream_context_create(array(
'ssl' => array(
'verify_peer' => false,
'verify_peer_name' => false,
'allow_self_signed' => true
)
));
/* Create SOAP client based on WSDL, with trace for debugging */
$client = new SoapClient('https://' . $IP . '/soap2/schema/' . $VERSION . '/voipnowservice.wsdl', array('trace' => 1, 'exceptions' => 0 1, 'stream_context' => $streamContext));
/* Create authentication headers */
$auth = new stdClass();
$auth->accessToken= $TOKEN;
$userCredentials = new SoapVar($auth, SOAP_ENC_OBJECT, 'http://4psa.com/HeaderData.xsd/' . $VERSION);
$header = new SoapHeader('http://4psa.com/HeaderData.xsd/' . $VERSION, 'userCredentials', $userCredentials, false);
$client->__setSoapHeaders(array($header));
function generate_rule($channelID=false, $intervalID=0) {
//channelID is default best cost
$prefix_operation = array(0=>'prefix', 1=>'add', 2=>'replace', 3=>'substract');
$action_array = array(0=>'block', 1 =>'transfer', 2=>'process');
$i = 0;
$caller_id = array('prefix' => array(
'callerIDPrefixOperation'=> 'prefix',
'callerIDPrefix' => '1',
'callerIDMatch'=> '2',
),
'add' => array(
'callerIDPrefixOperation'=> 'add',
'callerIDNumberAdd'=> '3',
'callerIDDigitsAfterAdd'=> '4',
'callerIDMatch'=> '5',
),
'replace' => array(
'callerIDPrefixOperation'=> 'replace',
'callerIDPrefix' => '6',
'callerIDMatch'=> '7',
),
'substract' => array(
'callerIDPrefixOperation'=> 'substract',
'callerIDDigits' => '8',
'callerIDDigitsAfter' => '9',
'callerIDMatch'=> '10',
),
);
foreach ($prefix_operation as $k =>$v){
if($v == 'prefix'){
foreach ($action_array as $key =>$val){
if($val == 'transfer' or $val == 'process'){
$arr[$i] = array(
'action' =>$val,
'number' => time() % 1000000 . rand(1, 1000),
'intervalID' => $intervalID,
'comingFrom' => '9999',
'channelID' => $channelID,
);
$rest = array(
'prefixOperation' => 'prefix',
'prefix' => '5',
'final' => '',
);
$arr[$i] = array_merge($arr[$i],$rest );
$arr[$i] = array_merge($arr[$i],$caller_id['prefix'] );
$i++;
}
}
}
if($v == 'add'){
foreach ($action_array as $key =>$val){
if($val == 'transfer' or $val == 'process'){
$arr[$i] = array(
'action' =>$val,
'number' => time() % 1000000 . rand(1, 1000),
'intervalID' => $intervalID,
'comingFrom' => '4444',
'channelID' => $channelID,
);
$rest3 = array(
'prefixOperation' => 'add',
'numberAdd' =>'2',
'digitsAfterAdd' => '1',
'prefix' => '4',
'final' => '',
);
$arr[$i] = array_merge($arr[$i],$rest3 );
$arr[$i] = array_merge($arr[$i],$caller_id['add'] );
$i++;
}
}
}
if($v == 'replace'){
foreach ($action_array as $key =>$val){
if($val == 'transfer' or $val == 'process'){
$arr[$i] = array(
'action' =>$val,
'number' => time() % 1000000 . rand(1, 1000),
'intervalID' => $intervalID,
'comingFrom' => '8888',
'channelID' => $channelID,
);
$rest1 = array(
'prefixOperation' => 'replace',
'final' => '',
);
$arr[$i] = array_merge($arr[$i],$rest1 );
$arr[$i] = array_merge($arr[$i],$caller_id['replace'] );
$i++;
}
}
}
if($v == 'substract'){
foreach ($action_array as $key =>$val){
if($val == 'transfer' or $val == 'process'){
$arr[$i] = array(
'action' =>$val,
'number' => time() % 1000000 . rand(1, 1000),
'intervalID' => $intervalID,
'comingFrom' => '555',
'channelID' => $channelID,
);
$rest2 = array(
'prefixOperation' => 'substract',
'digits' => '3',
'digitsAfter' => '1',
'final' => '',
);
$arr[$i] = array_merge($arr[$i],$rest2 );
$arr[$i] = array_merge($arr[$i],$caller_id['substract'] );
$i++;
}
}
}
}
$arr[$i] = array(
'action' =>'block',
'number' => time() % 1000000 . rand(1, 1000),
'intervalID' => $intervalID,
'commingFrom' => '4444',
);
$i++;
$arr[$i] = array(
'action' =>'portability',
'engine'=>'123123123',
'number' => time() % 1000000 . rand(1, 1000),
'intervalID' => $intervalID,
'commingFrom' => '4444',
);
return $arr;
}
class test {
function test(){
$this->name = 'My Rule ' . time();
return $this;
}
}
if (true)
{
$obj = new test();
$obj->rules = generate_rule(); //Add outgoing routing rules group
$result = $client->AddCallRulesOutGroup($obj);
echo "<br><br>REQUEST AddCallRulesOutGroup:<br>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastRequest() );
echo "<br><br>RESPONSE AddCallRulesOutGroup:<br>";
echo preg_replace(array("/></i", "/</i", "/>/i", "/\n/i"), array(">\n<", "<", ">", "<br />"), $client->__getLastResponse() );
}
?>
|