📄 a2billing.php
字号:
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, $result);
if (is_array($result)){
$A2B -> call_did($agi, $RateEngine, $result);
if ($A2B->set_inuse==1) $A2B -> callingcard_acct_start_inuse($agi,0);
}
}
// MOVE VOUCHER TO LET CUSTOMER ONLY REFILL
}elseif ($mode == 'voucher'){
$A2B->agiconfig['say_balance_after_auth']=1;
if ($A2B->agiconfig['answer_call']==1){
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[ANSWER CALL]');
$agi->answer();
$status_channel=6;
}else{
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[NO ANSWER CALL]');
$status_channel=4;
}
$A2B -> play_menulanguage ($agi);
/************************* PLAY INTRO MESSAGE ************************/
if (strlen($A2B->agiconfig['intro_prompt'])>0) $agi-> stream_file($A2B->agiconfig['intro_prompt'], '#');
$cia_res = $A2B -> callingcard_ivr_authenticate($agi);
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[TRY : callingcard_ivr_authenticate]");
for ($k=0;$k<3;$k++){
$vou_res = $A2B -> refill_card_with_voucher($agi, null);
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "VOUCHER RESULT = $vou_res");
if ($vou_res==1){
break;
} else {
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[NOTENOUGHCREDIT - refill_card_withvoucher fail] ");
}
}
// SAY GOODBYE
if ($A2B->agiconfig['say_goodbye']==0) $agi-> stream_file('prepaid-final', '#');
$agi->hangup();
if ($A2B->set_inuse==1) $A2B->callingcard_acct_start_inuse($agi,0);
$A2B -> write_log("[STOP - EXIT]", 0);
exit();
// MODE CID-CALLBACK
}elseif ($mode == 'cid-callback'){
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[MODE : CALLERID-CALLBACK - '.$A2B->CallerID.']');
// END
$agi->hangup();
// MAKE THE AUTHENTICATION ACCORDING TO THE CALLERID
$A2B->agiconfig['cid_enable']=1;
$A2B->agiconfig['cid_askpincode_ifnot_callerid']=0;
if (strlen($A2B->CallerID)>1 && is_numeric($A2B->CallerID)){
/* WE START ;) */
$cia_res = $A2B -> callingcard_ivr_authenticate($agi);
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[TRY : callingcard_ivr_authenticate]");
if ($cia_res==0){
$RateEngine = new RateEngine();
$A2B -> agiconfig['use_dnid']=1;
$A2B -> agiconfig['say_timetocall']=0;
if (substr($A2B->CallerID,0,1)=='0'){
$A2B -> dnid = $A2B -> destination = $caller_areacode.substr($A2B->CallerID,1);
}else{
$A2B -> dnid = $A2B -> destination = $caller_areacode.$A2B->CallerID;
}
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[destination: - '.$A2B->destination.']');
// LOOKUP RATE : FIND A RATE FOR THIS DESTINATION
$resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B ->destination, $A2B ->tariff);
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[resfindrate: - '.$resfindrate.']');
// IF FIND RATE
if ($resfindrate!=0){
//$RateEngine -> debug_st =1;
$res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit);
//echo ("RES_ALL_CALCULTIMEOUT ::> $res_all_calcultimeout");
if ($res_all_calcultimeout){
// MAKE THE CALL
if ($RateEngine -> ratecard_obj[0][34]!='-1'){
$usetrunk = 34;
$usetrunk_failover = 1;
$RateEngine -> usedtrunk = $RateEngine -> ratecard_obj[0][34];
} else {
$usetrunk = 29;
$RateEngine -> usedtrunk = $RateEngine -> ratecard_obj[0][29];
$usetrunk_failover = 0;
}
$prefix = $RateEngine -> ratecard_obj[0][$usetrunk+1];
$tech = $RateEngine -> ratecard_obj[0][$usetrunk+2];
$ipaddress = $RateEngine -> ratecard_obj[0][$usetrunk+3];
$removeprefix = $RateEngine -> ratecard_obj[0][$usetrunk+4];
$timeout = $RateEngine -> ratecard_obj[0]['timeout'];
$failover_trunk = $RateEngine -> ratecard_obj[0][40+$usetrunk_failover];
$addparameter = $RateEngine -> ratecard_obj[0][42+$usetrunk_failover];
$destination = $A2B ->destination;
if (strncmp($destination, $removeprefix, strlen($removeprefix)) == 0) $destination= substr($destination, strlen($removeprefix));
$pos_dialingnumber = strpos($ipaddress, '%dialingnumber%' );
$ipaddress = str_replace("%cardnumber%", $A2B->cardnumber, $ipaddress);
$ipaddress = str_replace("%dialingnumber%", $prefix.$destination, $ipaddress);
if ($pos_dialingnumber !== false){
$dialstr = "$tech/$ipaddress".$dialparams;
}else{
if ($A2B->agiconfig['switchdialcommand'] == 1){
$dialstr = "$tech/$prefix$destination@$ipaddress".$dialparams;
}else{
$dialstr = "$tech/$ipaddress/$prefix$destination".$dialparams;
}
}
//ADDITIONAL PARAMETER %dialingnumber%, %cardnumber%
if (strlen($addparameter)>0){
$addparameter = str_replace("%cardnumber%", $A2B->cardnumber, $addparameter);
$addparameter = str_replace("%dialingnumber%", $prefix.$destination, $addparameter);
$dialstr .= $addparameter;
}
$channel= $dialstr;
$exten = $A2B -> config["callback"]['extension'];
if ($argc > 4 && strlen($argv[4]) > 0) $exten = $argv[4];
$context = $A2B -> config["callback"]['context_callback'];
$id_server_group = $A2B -> config["callback"]['id_server_group'];
$priority = 1;
$timeout = $A2B -> config["callback"]['timeout']*1000;
$callerid = $A2B -> config["callback"]['callerid'];
$application='';
//$callerid=$A2B->CallerID;
$account = $A2B -> accountcode;
$uniqueid = MDP_NUMERIC(5).'-'.MDP_STRING(7);
$variable = "CALLED=".$A2B ->destination."|MODE=CID|CBID=$uniqueid|LEG=".$A2B -> username;
$status = 'PENDING';
$server_ip = 'localhost';
$num_attempt = 0;
if (is_numeric($A2B -> config["callback"]['sec_wait_before_callback']) && $A2B -> config["callback"]['sec_wait_before_callback']>=1){
$sec_wait_before_callback = $A2B -> config["callback"]['sec_wait_before_callback'];
}else{
$sec_wait_before_callback = 1;
}
if ($A2B->config["database"]['dbtype'] != "postgres"){
// MYSQL
$QUERY = " INSERT INTO cc_callback_spool (uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout ) VALUES ('$uniqueid', '$status', '$server_ip', '$num_attempt', '$channel', '$exten', '$context', '$priority', '$variable', '$id_server_group', ADDDATE( CURRENT_TIMESTAMP, INTERVAL $sec_wait_before_callback SECOND ), '$account', '$callerid', '30000')";
}else{
// POSTGRESQL
$QUERY = " INSERT INTO cc_callback_spool (uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout ) VALUES ('$uniqueid', '$status', '$server_ip', '$num_attempt', '$channel', '$exten', '$context', '$priority', '$variable', '$id_server_group', (CURRENT_TIMESTAMP + INTERVAL '$sec_wait_before_callback SECOND'), '$account', '$callerid', '30000')";
}
$res = $A2B -> DBHandle -> Execute($QUERY);
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-ALL : INSERT CALLBACK REQUEST IN SPOOL : QUERY=$QUERY]");
if (!$res){
$error_msg= "Cannot insert the callback request in the spool!";
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-ALL : CALLED=".$A2B ->destination." | $error_msg]");
}
}else{
$error_msg = 'Error : You don t have enough credit to call you back !!!';
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | $error_msg]");
}
}else{
$error_msg = 'Error : There is no route to call back your phonenumber !!!';
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | $error_msg]");
}
}else{
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | Authentication failed]");
}
}else{
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | error callerid]");
}
}elseif ($mode == 'all-callback'){
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[MODE : ALL-CALLBACK - '.$A2B->CallerID.']');
// END
$agi->hangup();
$A2B ->credit = 1000;
$A2B ->tariff = $A2B -> config["callback"]['all_callback_tariff'];
if (strlen($A2B->CallerID)>1 && is_numeric($A2B->CallerID)){
/* WE START ;) */
if ($cia_res==0){
$RateEngine = new RateEngine();
// $RateEngine -> webui = 0;
// LOOKUP RATE : FIND A RATE FOR THIS DESTINATION
$A2B ->agiconfig['use_dnid']=1;
$A2B ->agiconfig['say_timetocall']=0;
$A2B ->dnid = $A2B ->destination = $caller_areacode.$A2B->CallerID;
$resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B ->destination, $A2B ->tariff);
// IF FIND RATE
if ($resfindrate!=0){
//$RateEngine -> debug_st = 1;
$res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit);
if ($res_all_calcultimeout){
// MAKE THE CALL
if ($RateEngine -> ratecard_obj[0][34]!='-1'){
$usetrunk = 34;
$usetrunk_failover = 1;
$RateEngine -> usedtrunk = $RateEngine -> ratecard_obj[$k][34];
} else {
$usetrunk = 29;
$RateEngine -> usedtrunk = $RateEngine -> ratecard_obj[$k][29];
$usetrunk_failover = 0;
}
$prefix = $RateEngine -> ratecard_obj[0][$usetrunk+1];
$tech = $RateEngine -> ratecard_obj[0][$usetrunk+2];
$ipaddress = $RateEngine -> ratecard_obj[0][$usetrunk+3];
$removeprefix = $RateEngine -> ratecard_obj[0][$usetrunk+4];
$timeout = $RateEngine -> ratecard_obj[0]['timeout'];
$failover_trunk = $RateEngine -> ratecard_obj[0][40+$usetrunk_failover];
$addparameter = $RateEngine -> ratecard_obj[0][42+$usetrunk_failover];
$destination = $A2B ->destination;
if (strncmp($destination, $removeprefix, strlen($removeprefix)) == 0) $destination= substr($destination, strlen($removeprefix));
$pos_dialingnumber = strpos($ipaddress, '%dialingnumber%' );
$ipaddress = str_replace("%cardnumber%", $A2B->cardnumber, $ipaddress);
$ipaddress = str_replace("%dialingnumber%", $prefix.$destination, $ipaddress);
if ($pos_dialingnumber !== false){
$dialstr = "$tech/$ipaddress".$dialparams;
}else{
if ($A2B->agiconfig['switchdialcommand'] == 1){
$dialstr = "$tech/$prefix$destination@$ipaddress".$dialparams;
}else{
$dialstr = "$tech/$ipaddress/$prefix$destination".$dialparams;
}
}
//ADDITIONAL PARAMETER %dialingnumber%, %cardnumber%
if (strlen($addparameter)>0){
$addparameter = str_replace("%cardnumber%", $A2B->cardnumber, $addparameter);
$addparameter = str_replace("%dialingnumber%", $prefix.$destination, $addparameter);
$dialstr .= $addparameter;
}
$channel= $dialstr;
$exten = $A2B -> config["callback"]['extension'];
if ($argc > 4 && strlen($argv[4]) > 0) $exten = $argv[4];
$context = $A2B -> config["callback"]['context_callback'];
$id_server_group = $A2B -> config["callback"]['id_server_group'];
$callerid = $A2B -> config["callback"]['callerid'];
$priority = 1;
$timeout = $A2B -> config["callback"]['timeout']*1000;
$application='';
$account = $A2B -> accountcode;
$uniqueid = MDP_NUMERIC(5).'-'.MDP_STRING(7);
$variable = "CALLED=".$A2B ->destination."|MODE=ALL|CBID=$uniqueid|TARIFF=".$A2B ->tariff.'|LEG='.$A2B -> username;
$status = 'PENDING';
$server_ip = 'localhost';
$num_attempt = 0;
if (is_numeric($A2B -> config["callback"]['sec_wait_before_callback']) && $A2B -> config["callback"]['sec_wait_before_callback']>=1){
$sec_wait_before_callback = $A2B -> config["callback"]['sec_wait_before_callback'];
}else{
$sec_wait_before_callback = 1;
}
if ($A2B->config["database"]['dbtype'] != "postgres"){
// MYSQL
$QUERY = " INSERT INTO cc_callback_spool (uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout ) VALUES ('$uniqueid', '$status', '$server_ip', '$num_attempt', '$channel', '$exten', '$context', '$priority', '$variable', '$id_server_group', ADDDATE( CURRENT_TIMESTAMP, INTERVAL $sec_wait_before_callback SECOND ), '$account', '$callerid', '30000')";
}else{
// POSTGRESQL
$QUERY = " INSERT INTO cc_callback_spool (uniqueid, status, server_ip, num_attempt, channel, exten, context, priority, variable, id_server_group, callback_time, account, callerid, timeout ) VALUES ('$uniqueid', '$status', '$server_ip', '$num_attempt', '$channel', '$exten', '$context', '$priority', '$variable', '$id_server_group', (CURRENT_TIMESTAMP + INTERVAL '$sec_wait_before_callback SECOND'), '$account', '$callerid', '30000')";
}
$res = $A2B -> DBHandle -> Execute($QUERY);
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-ALL : INSERT CALLBACK REQUEST IN SPOOL : QUERY=$QUERY]");
if (!$res){
$error_msg= "Cannot insert the callback request in the spool!";
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-ALL : CALLED=".$A2B ->destination." | $error_msg]");
}
}else{
$error_msg = 'Error : You don t have enough credit to call you back !!!';
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | $error_msg]");
}
}else{
$error_msg = 'Error : There is no route to call back your phonenumber !!!';
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | $error_msg]");
}
}else{
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | Authentication failed]");
}
}else{
$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CALLBACK-CALLERID : CALLED=".$A2B ->destination." | error callerid]");
}
// MODE CALLBACK
}elseif ($mode == 'callback'){
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[CALLBACK]:[MODE : CALLBACK]');
if ($A2B -> config["callback"]['answer_call']==1){
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[CALLBACK]:[ANSWER CALL]');
$agi->answer();
$status_channel=6;
// PLAY INTRO FOR CALLBACK
if (strlen($A2B -> config["callback"]['callback_audio_intro']) > 0){
$agi-> stream_file($A2B -> config["callback"]['callback_audio_intro'], '#');
}
}else{
$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[CALLBACK]:[NO ANSWER CALL]');
$status_channel=4;
}
$called_party = $agi->get_variable("CALLED");
$called_party = $called_party['data'];
$calling_party = $agi->get_variable("CALLING");
$calling_party = $calling_party['data'];
$callback_mode = $agi->get_variable("MODE");
$callback_mode = $callback_mode['data'];
$callback_tariff = $agi->get_variable("TARIFF");
$callback_tariff = $callback_tariff['data'];
$callback_uniqueid = $agi->get_variable("CBID");
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -