📄 a2billingi.php
字号:
$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(); $agi->answer(); // MAKE THE AUTHENTICATION ACCORDING TO THE CALLERID $A2B->agiconfig['cid_enable']=1; $A2B->agiconfig['cid_askpincode_ifnot_callerid']=1; 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 == 'callback-register'){//手机回拨注册程序 b-52-1@163.com $agi->answer();//新用户注册过程函数function cid_new_reg(){ global $agi; global $A2B; $i = 0 ; $a = 0 ;// 查询密码及卡号 do{ //获取卡号 $result = $agi->get_data("cid-reg-enter-card",8000, 20); $dtmf = $result['result']; $i++; $QUERY = "SELECT id, uipass, credit from cc_card WHERE username='".$dtmf."'"; $result_card = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY); if (is_array($result_card))break; if ($i<3) { $agi-> stream_file("cid-reg-invalid-digit", '#'); } } while($i<3 );if (!is_array($result_card)) { break;}do{ //获取密码 $result = $agi->get_data("cid-reg-enter-pass",8000, 20); $dtmf_passwd = $result['result']; $a++; if ($dtmf_passwd == $result_card[0][1]){ $pass_check = "yes"; break; }else{ $pass_check = "no"; } if ($a<3) { $agi-> stream_file("cid-reg-invalid-digit", '#'); } $agi->verbose($pass_check);} while($a<3 );//返回帐号信息$agi->verbose($pass_check); if ($pass_check == "yes") { return $result_card; }else{ return "0"; }}//余额播报及充值函数,传入余额$balance,充值成功break 2;function refill_and_select($balance){global $agi;global $A2B; $A2B->fct_say_balance($agi, $balance, 0, "cid-reg");//余额播报正确for ($k=0;$k<3;$k++){$vou_res = $A2B -> refill_card_with_voucher($agi, null, $A2B->CallerID);$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] "); } }$agi->get_data("callingcard-enter-callnumber",8000, 20); //break 1;}//已注册用户查询余额函数,根据$A2B->CallerID判断帐号,返回余额$user_balancefunction get_balance(){ global $agi; global $A2B; $QUERY = "SELECT id_cc_card from cc_callerid WHERE cid='".$A2B->CallerID."'"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);// $result = $A2B -> DBHandle -> Execute($QUERY); if (is_array($result)) { //找到了有效的卡号 $agi->verbose('accout found !'); $cid_exists = "yes"; $acount_id = $result[0][0]; $agi->verbose("id is $acount_id"); }else { $agi->verbose('account not exists !'); $cid_exists = "no"; } $QUERY = "SELECT id, uipass, credit from cc_card WHERE id='".$acount_id."'"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY); if (is_array($result)){ $user_id = $result[0][0];// $agi->verbose($user_id); $user_passwd = $result[0][1];// $agi->verbose($user_passwd); $user_balance = $result[0][2];// $agi->verbose($user_balance); return $user_balance; }else{ $agi->verbose("accout not found !"); }}//已注册用户主操作菜单函数,传入余额$user_balance,1.查询充值,2.设置快速拨号,3.解除绑定。function set_speed_dial1($user_id){ global $agi; global $A2B; $agi->verbose("TEST!!!".$user_id); for ($i=0;$i<10;$i++){ $dtmf_result = $agi->get_data("speed-dial-num",8000, 1); $my_dtmf = $dtmf_result['result']; if (is_numeric($my_dtmf)) { //查询数据库改快捷拨号是否存在, $QUERY = "SELECT id_cc_card,phone from cc_speeddial WHERE speeddial='".$my_dtmf."'"; $result_speed = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY); $agi->verbose($result_speed[0][1]); if (is_array($result_speed)) {//该快速拨号存在 $agi-> stream_file("speed-phone-exists", '#'); $agi->say_digits($result_speed[0][1]); $edit_speed = $agi->get_data("speed-phone-exists-edit",8000, 1); $edit = $edit_speed['result']; $agi->verbose($edit);//2007-12-31 $res_edit = $edit; }else{ $agi->verbose("enter speed dial number"); //$speed_result = $agi->get_data("请输入该快捷拨号对应的电话号码,并以#号键结束",8000, 20); $speed_result = $agi->get_data("speed-dial-phonenumber",8000, 20); $my_speed = $speed_result['result']; if (is_numeric($my_speed) && strlen($my_speed)> 5) { $QUERY = "INSERT INTO cc_speeddial (id_cc_card, phone, name, speeddial, creationdate) VALUES ('".$user_id."', '".$my_speed."','快速拨号_".$my_dtmf."', '".$my_dtmf."', 'now()')"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY); } $agi-> stream_file('speed-set-ok', '#'); $agi->verbose("spee dial set ok!"); } if($res_edit == 1){ $new_speed_res = $agi->get_data("speed-phone-exists-edit-new",8000, 20); $new_speed = $new_speed_res['result']; if (is_numeric($new_speed) && strlen($new_speed)> 5) { $QUERY = "UPDATE `cc_speeddial` SET `phone` = '".$new_speed."' WHERE `speeddial` = '".$my_dtmf."'"; $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY); } $agi-> stream_file('speed-set-ok', '#'); $agi->verbose("spee dial set ok!"); } }else { break; } } }function registed_user_ivr($user_balance,$user_id){ global $agi; global $A2B; //已注册用户操作菜单 //重试3次 for ($i=0;$i<3;$i++){ $result = $agi->get_data("cid-reg-welcome1",8000, 1); $dtmf = $result['result']; switch ($dtmf){ //查询余额及充值 case "1": refill_and_select($user_balance); break; //添加删除
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -