A2Billing

    技术2022-05-11  28

    #!/usr/bin/php -q<?phpdeclare(ticks = 1);if (function_exists('pcntl_signal')){ pcntl_signal(SIGHUP,  SIG_IGN);}

    error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));include_once (dirname(__FILE__)."/libs_a2billing/db_php_lib/Class.Table.php");include (dirname(__FILE__)."/libs_a2billing/Class.A2Billing.php");include (dirname(__FILE__)."/libs_a2billing/Class.RateEngine.php");   include (dirname(__FILE__)."/libs_a2billing/phpagi_2_14/phpagi.php");include (dirname(__FILE__)."/libs_a2billing/phpagi_2_14/phpagi-asmanager.php");include (dirname(__FILE__)."/libs_a2billing/Misc.php");include (dirname(__FILE__)."/outgoing.php"); $charge_callback=0;$G_startime = time();$agi_date = "Release : 22 January 2008";$agi_version = "Asterisk2Billing - Version 1.3.2 (Yellowjacket)";

    if ($argc > 1 && ($argv[1] == '--version' || $argv[1] == '-v')){ echo "A2Billing - Version $agi_version - $agi_date/n"; exit;}

    /**********   CREATE THE AGI INSTANCE + ANSWER THE CALL  **********/$agi = new AGI();

    if ($argc > 1 && is_numeric($argv[1]) && $argv[1] >= 0){  $idconfig = $argv[1];}else{ $idconfig = 1;}if ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'menu')       $mode = 'menu';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'callback')  $mode = 'callback';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'voip-callback')  $mode = 'voip-callback';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'precallback') $mode = 'precallback';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'balance') $mode = 'balance';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'voucher') $mode = 'voucher';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'halfvoucher') $mode = 'halfvoucher';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'answervoucher') $mode = 'answervoucher';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'answercall') $mode = 'answercall';else $mode = 'standard';

    // get the area code for the cid-callback & all-callbackif ($argc > 3 && strlen($argv[3]) > 0) $publicphone = $argv[3];else $publicphone = false;

    $A2B = new A2Billing();$A2B -> load_conf($agi, NULL, 0, $idconfig);$A2B -> mode = $mode;

    //$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "IDCONFIG : $idconfig");//$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "MODE : $mode");

    define ("DB_TYPE", isset($A2B->config["database"]['dbtype'])?$A2B->config["database"]['dbtype']:null);

    //-- Print header//$A2B -> debug( VERBOSE , $agi, __FILE__, __LINE__, 'AGI Request:');//$A2B -> debug( VERBOSE , $agi, __FILE__, __LINE__, print_r($agi->request, true));/* GET THE AGI PARAMETER(参数) */$A2B -> get_agi_request_parameter ($agi);if (!$A2B -> DbConnect()){       $agi-> stream_file('prepaid-final', '#'); exit;     }$instance_table = new Table();$A2B -> set_instance_table ($instance_table); 

    //GET CURRENCIES(货币) FROM DATABASE

    $QUERY =  "SELECT id,currency,name,value from cc_currencies order by id";$result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);//

    if (is_array($result)){ $num_cur = count($result); for ($i=0;$i<$num_cur;$i++) {  $currencies_list[$result[$i][1]] = array (1 => $result[$i][2], 2 => $result[$i][3]); }}$RateEngine = new RateEngine();

    if($mode == 'menu') //辩证半直拨预约和半直拨充值{ $agi->hangup(); if(substr($A2B->dnid,0,3)=='11#') {  $A2B->dnid=substr($A2B->dnid,3);  //半直拨充值  $mode='halfvoucher'; } elseif(substr($A2B->dnid,0,3)=='12#') {  $called=substr($A2B->dnid,3);  $called=str_replace('#','',$called);  //半直拨预约   $mode='halfdid'; } else {  $agi->verbose("this is mode is error!");  $agi->hangup();  exit; }}

    if($mode=='halfvoucher') //半直拨充值{      $A2B->dnid=str_replace('#','',$A2B->dnid);       if(strstr($A2B->dnid,'*')==false)       {        //为本机充值  result_vouchernumber充值卡        $result_vouchernumber=$A2B->dnid;         if(substr($A2B->CallerID,0,1)==0)      {       $A2B->CallerID=substr($A2B->CallerID,1);      }      //result_voucherphone用户手机号码通过$A2B->CallerID获取得到        $result_voucherphone=$A2B->CallerID;       }       else       {        //为其它手机充值        $temp_dnid=explode('*',$A2B->dnid);        $result_vouchernumber=$temp_dnid[0]; //充值卡        $result_voucherphone=$temp_dnid[1];  //充值的手机号码       }        /*        *        */        //判断是否手机号码     if(strlen($result_voucherphone)==11 && (ereg("^13[0-9][0-9]{4,8}$", $result_voucherphone)||ereg("^15[0-9][0-9]{4,8}$", $result_voucherphone)||ereg("^18[0-9][0-9]{4,8}$", $result_voucherphone)) )    {     //判断充值卡位数是否正确       if(isset($result_vouchernumber)&& strlen($result_vouchernumber)==$A2B -> config["global"]['len_voucher'])      {                $QUERY="select voucher,credit,tariff,agent,expireday from cc_voucher where expirationdate >= CURRENT_TIMESTAMP and activated='t' and voucher = '".$result_vouchernumber."'";       $result_voucher=$A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);

            $result_count = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       if(is_array($result_voucher))//充值卡通过初步验证        {          $expire_day=$result_voucher[0][4];          $halfvoucher='ok';        }        else        {          $agi->exec("playback","you_input_error");          $agi->hangup();          exit;        }      }      else      {       $agi->exec("playback","you_input_error");       $agi->hangup();       exit;      }    }    else    {         $agi->exec("playback","you_input_error");       $agi->hangup();       exit;    }    if($halfvoucher=='ok')    {         $QUERY= "SELECT username , tariff from cc_card where username='".$result_voucherphone."' ";//查看是不是新用户       $result_cardtariff=$A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       if(!is_array($result_cardtariff))//是新用户 那么就开始创建      {        $upass=substr($result_voucherphone,-6);       $QUERY="insert into cc_card (creationdate,enableexpire,username,useralias ,expiredays,userpass ,uipass,credit,tariff,activated,simultaccess,agent) VALUES(now(),'3','$result_voucherphone','$result_voucherphone','$expire_day','$upass','$upass','".$result_voucher[0][1]."','".$result_voucher[0][2]."','t','1',".$result_voucher[0][3].")";//插入新纪录        $result = $A2B ->instance_table -> SQLExec ($A2B->DBHandle, $QUERY);        $QUERY = "UPDATE cc_voucher SET activated='u', usedcardnumber='".$result_voucherphone."', usedate=now() WHERE voucher='".$result_vouchernumber."'";//修改卡的状态       $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       $QUERY= "SELECT id from cc_card where username='".$result_voucherphone."'";       $tmp=$A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       $context=$A2B->config['callback']['context_voip_callback'];       $QUERY="insert into cc_iax_buddies (id_cc_card,name,accountcode,callerid ,context,host,mailbox,port,secret,username) VALUES('".$tmp[0][0]."','".$result_voucherphone."','".$result_voucherphone."','".$result_voucherphone."','".$context."','dynamic','".$result_voucherphone."','0','".$upass."','".$result_voucherphone."')";       $result_sip = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       $QUERY="insert into cc_sip_buddies (id_cc_card,name,accountcode,callerid ,context,mailbox,port,secret,username) VALUES('".$tmp[0][0]."','".$result_voucherphone."','".$result_voucherphone."','".$result_voucherphone."','".$context."','".$result_voucherphone."','0','".$upass."','".$result_voucherphone."')";       $result_iax = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);               $QUERY="select commender,commended,credit from cc_commend where status='0' and commended='".$result_voucherphone."'";            $result_commend = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);            if(is_array($result_commend))//的确被人推荐过(推荐用户才可以注册)            {              $QUERY="update cc_card set credit = credit + ".$result_commend[0][2]." where username = '".$result_commend[0][0]."'";              $updete_credit = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);              $QUERY="update cc_commend set status = 1 where commender = '".$result_commend[0][0]."' and commended= '".$result_voucherphone."'";              $updete_commend = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);            }             $agi->exec("playback","voucher_success");       $agi->hangup();      }     else//不是新用户      {         if($result_cardtariff[0][1]==$result_voucher[0][2])         {             $QUERY="SELECT  id,expiredays, UNIX_TIMESTAMP(creationdate),credit FROM cc_card WHERE UNIX_TIMESTAMP( creationdate ) +60 *60 *24 * expiredays < UNIX_TIMESTAMP( now( ) ) and username = '".$result_voucherphone."'";//查看用户是否过期            $result_expire = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);              if(is_array($result_expire))// 已经过期               {               $QUERY = "insert into cc_expire_bak(card_id,expiredays,creationdate,credit) values('".$result_expire[0][0]."','".$result_expire[0][1]."','".date("Y-m-d H:d:s",$result_expire[0][2])."','".$result_expire[0][3]."')";//备份             $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);             $QUERY = "UPDATE cc_voucher SET activated='u', usedcardnumber='".$result_voucherphone ."', usedate=now() WHERE voucher='".$result_vouchernumber."'";             $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);                  $QUERY = "UPDATE cc_card SET activated = 't',credit='".$result_voucher[0][1]."',creationdate=CURRENT_TIMESTAMP,expiredays= '$expire_day'  WHERE username='".$result_voucherphone."'";             $result = $A2B-> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);                       }               else//没有过期               {                          $QUERY = "UPDATE cc_voucher SET activated='u', usedcardnumber='".$result_voucherphone ."', usedate=now() WHERE voucher='".$result_vouchernumber."'";                $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);                //$agi->verbose($QUERY);               $QUERY ="UPDATE cc_card SET  creationdate=now() , activated = 't',credit=credit + '".$result_voucher[0][1]."',expiredays='$expire_day'  WHERE username='".$result_voucherphone."'";               $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);              }                    $agi->exec("playback","voucher_success");                     $agi->hangup();           }          else          {             //如果手机和充值卡的tariff不同             $agi->exec("playback","voucher_failed");             $agi->hangup();          }      }    }}

    if($mode=='answervoucher')//接通充值{   $agi->answer();   if(substr($A2B->CallerID,0,1)==0)    {     $A2B->CallerID=substr($A2B->CallerID,1);    }    $called_party=$A2B->CallerID;   for($vocherphone=0;$vocherphone<=3;$vocherphone++)   {    if($vocherphone==3)    {     $agi->hangup();     break 2;    }    //请输入你要充值手机号码 并以井号结束 本机直接按井号键结束 返回请按11井     $res_dtmf = $agi->get_data('please_input_your_voucherphone',10000,12);    $result_voucherphone = $res_dtmf ["result"];    //本机    if(isset($result_voucherphone) && strlen($result_voucherphone)==11 && (ereg("^13[0-9][0-9]{4,8}$", $result_voucherphone)||ereg("^15[0-9][0-9]{4,8}$", $result_voucherphone)||ereg("^18[0-9][0-9]{4,8}$", $result_voucherphone)))    {         $the_username=1;         break;    }    elseif($res_dtmf ["data"]=="timeout")    {        continue;    }    //其它手机    elseif(strlen($result_voucherphone)==0 && (ereg("^13[0-9][0-9]{4,8}$", $called_party)||ereg("^15[0-9][0-9]{4,8}$", $called_party)||ereg("^18[0-9][0-9]{4,8}$", $called_party)) )     {              $result_voucherphone=$called_party;       $the_username=1;       break;     }     else     {      $agi->exec("playback","you_input_error");      }   }     if($the_username==1)   {     for($vocherpwd=0;$vocherpwd<=3;$vocherpwd++)    {     if($vocherpwd==3)     {      $agi->hangup();      break 2;     }     $res_dtmf = $agi->get_data('please_input_your_pwd',10000,11);//请输入你要充值的卡号 并以井号结束 返回请按*#键     $result_vouchernumber = $res_dtmf ["result"];//获取卡号      if(isset($result_vouchernumber)&& strlen($result_vouchernumber)==$A2B -> config["global"]['len_voucher'])//判断充值卡**如果正确     {               $QUERY="select voucher,credit,tariff,agent,expireday from cc_voucher where expirationdate >= CURRENT_TIMESTAMP and activated='t' and voucher = '".$result_vouchernumber."'";      $result_voucher=$A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      if(is_array($result_voucher))//充值卡通过初步验证       {         $expire_day=$result_voucher[0][4];         $the_voucher=1;         break;       }       else       {         $agi->exec("playback","you_input_error");       }     }     else     {      $agi->exec("playback","you_input_error");     }    }   }       if($the_voucher==1 && $the_username==1)//有卡$result_vouchernumber 有账号了$result_voucherphone   {     $QUERY= "SELECT username , tariff from cc_card where username='".$result_voucherphone."' ";//查看是不是新用户      $result_cardtariff=$A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      if(!is_array($result_cardtariff))//是新用户 那么就开始创建     {       $upass=substr($result_voucherphone,-6);      $QUERY="insert into cc_card (creationdate,enableexpire,username,useralias ,expiredays,userpass ,uipass,credit,tariff,activated,simultaccess,agent) VALUES(now(),'3','$result_voucherphone','$result_voucherphone','$expire_day','$upass','$upass','".$result_voucher[0][1]."','".$result_voucher[0][2]."','t','1',".$result_voucher[0][3].")";//插入新纪录       $result = $A2B ->instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       $QUERY = "UPDATE cc_voucher SET activated='u', usedcardnumber='".$result_voucherphone."', usedate=now() WHERE voucher='".$result_vouchernumber."'";//修改卡的状态      $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      $QUERY= "SELECT id from cc_card where username='".$result_voucherphone."'";      $tmp=$A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      $context=$A2B->config['callback']['context_voip_callback'];      $QUERY="insert into cc_iax_buddies (id_cc_card,name,accountcode,callerid ,context,host,mailbox,port,secret,username) VALUES('".$tmp[0][0]."','".$result_voucherphone."','".$result_voucherphone."','".$result_voucherphone."','".$context."','dynamic','".$result_voucherphone."','0','".$upass."','".$result_voucherphone."')";      $result_sip = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      $QUERY="insert into cc_sip_buddies (id_cc_card,name,accountcode,callerid ,context,mailbox,port,secret,username) VALUES('".$tmp[0][0]."','".$result_voucherphone."','".$result_voucherphone."','".$result_voucherphone."','".$context."','".$result_voucherphone."','0','".$upass."','".$result_voucherphone."')";      $result_iax = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);             $QUERY="select commender,commended,credit from cc_commend where status='0' and commended='".$result_voucherphone."'";            $result_commend = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);            if(is_array($result_commend))//的确被人推荐过            {              $QUERY="update cc_card set credit = credit + ".$result_commend[0][2]." where username = '".$result_commend[0][0]."'";              $updete_credit = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);              $QUERY="update cc_commend set status = 1 where commender = '".$result_commend[0][0]."' and commended= '".$result_voucherphone."'";              $updete_commend = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);            }            $agi->exec("playback","voucher_success");     }    else//不是新用户     {        if($result_cardtariff[0][1]==$result_voucher[0][2])        {            $QUERY="SELECT  id,expiredays, UNIX_TIMESTAMP(creationdate),credit FROM cc_card WHERE UNIX_TIMESTAMP( creationdate ) +60 *60 *24 * expiredays < UNIX_TIMESTAMP( now( ) ) and username = '".$result_voucherphone."'";//查看用户是否过期           $result_expire = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);             if(is_array($result_expire))// 已经过期              {              $QUERY = "insert into cc_expire_bak(card_id,expiredays,creationdate,credit) values('".$result_expire[0][0]."','".$result_expire[0][1]."','".date("Y-m-d H:d:s",$result_expire[0][2])."','".$result_expire[0][3]."')";//备份            $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);            $QUERY = "UPDATE cc_voucher SET activated='u', usedcardnumber='".$result_voucherphone ."', usedate=now() WHERE voucher='".$result_vouchernumber."'";            $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);                 $QUERY = "UPDATE cc_card SET activated = 't',credit='".$result_voucher[0][1]."',creationdate=CURRENT_TIMESTAMP,expiredays= '$expire_day'  WHERE username='".$result_voucherphone."'";            $result = $A2B-> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);                     }              else//没有过期              {                         $QUERY = "UPDATE cc_voucher SET activated='u', usedcardnumber='".$result_voucherphone ."', usedate=now() WHERE voucher='".$result_vouchernumber."'";               $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);               //$agi->verbose($QUERY);              $QUERY ="UPDATE cc_card SET  creationdate=now() , activated = 't',credit=credit + '".$result_voucher[0][1]."',expiredays='$expire_day'  WHERE username='".$result_voucherphone."'";              $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);             }                   $agi->exec("playback","voucher_success");               }         else         {            //如果手机和充值卡的tariff不同            $agi->exec("playback","voucher_failed");          }     }   }}  

    if($mode == 'precallback' || $mode=='halfdid' || $mode=='answercall') //依次为正常预约 半直拨预约 接通预约  因为这里很多代码重复 所以写到一起 通过不同的mode值辨别{

            if(substr($A2B->CallerID,0,1)==0)    {     $A2B->CallerID=substr($A2B->CallerID,1);    }          if(strlen($A2B->CallerID)>=11 && (ereg("^13[0-9][0-9]{4,8}$",$A2B->CallerID) || ereg("^15[0-9][0-9]{4,8}$",$A2B->CallerID) || ereg("^18[0-9][0-9]{4,8}$",$A2B->CallerID)) )//判断是否手机号码     {

             $check_vip=$RateEngine->rate_check_vip($A2B,$A2B->CallerID,1); //找到黑名单,返回0 反之返回1        if($check_vip==0)       {         $agi->verbose("rate_check_vip===========".$A2B->CallerID."====so.... hangup!");         $agi->hangup();         exit;       }                       $minutes= $A2B -> config["callback"]['minutes'];      $times = $A2B -> config["callback"]['times'];             if($minutes!=0 && $times!=0) //检测恶意用户     {       $t=time(); //获得当前时间       $t1=date("Y-m-d H:i:s",$t);               $t=$t-$minutes; //向前推多少时间       $t2=date("Y-m-d H:i:s",$t);              $cc_account=substr($A2B->CallerID,-11); //主叫的后11位              $QUERY="select  *   from cc_callback_spool  where entry_time>'$t2' and entry_time<'$t1' and account like '%".$cc_account."'";        $agi->verbose($QUERY);       $result_count = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);              $count=(int)count($result_count);       $agi->verbose($count);       if($count > $times )       {          $QUERY="insert into cc_vip(telphone,grade) values ('$A2B->CallerID','1')";                     $result_count = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);          exit;       }                }               $QUERY="select * from cc_card where username= '".$A2B->CallerID."'";       $temp_username = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       if(is_array($temp_username)) //是我们的用户 那么我们考虑是否报余额 提醒他充值 提醒他有效期       {       $QUERY="select username,tariff,credit,activated ,id from cc_card where username= '".$A2B->CallerID."'";         $result_username = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      if($result_username[0][2] <= $A2B -> config["callback"]['min_credit']) //余额小于多少提醒他充值      {        $prompt="your_credit_no_enough";        $agi-> stream_file($prompt, '#');      }             if ($A2B->agiconfig['say_balance_after_call']==1 && $result_username[0][3]=='t') //报余额       {         $A2B-> fct_say_balance ($agi, $result_username[0][2]);      }            $QUERY="SELECT creationdate, activated, FROM_UNIXTIME( UNIX_TIMESTAMP( creationdate ) +60 *60 *24 * (expiredays-5) ) ,FROM_UNIXTIME( UNIX_TIMESTAMP( creationdate ) +60 *60 *24 * expiredays )  FROM cc_card where username='$A2B->CallerID'";      $result_expiretime= $A2B->instance_table -> SQLExec ($A2B->DBHandle, $QUERY, 1);       if($result_expiretime[0][2]<=date("Y-m-d H:i:s") && $result_expiretime[0][3]>=date("Y-m-d H:i:s") && $result_expiretime[0][1] =='t' )       {        //你的有效期不足5天,请注意充值!        $agi-> stream_file("you_will_expire_voucher", '#');        }              $callfile=1;       $A2B ->tariff=$result_username[0][1];       }     else     {         //新用户 但是是手机用户,那么我们要考虑回铃!       $callfile=1;        $A2B ->tariff=$A2B->config['callback']['callback_tariff']; //回拨时候走的哪个tariff 请配置a2billing.conf       $agi->verbose("I am new user  tariff========".$A2B->config['callback']['callback_tariff']);     }          }     else     {      //不是手机用户      $agi->hangup();      exit;     }       if($callfile==1) //准备工作就绪 我们开始写.call文件     {                  if($mode=='halfdid')      {        if (strlen($called)==1 && is_numeric($called) && $called>=0)//快速拨号     {      $QUERY = "SELECT phone FROM cc_speeddial WHERE id_cc_card='".$result_username[0][4]."' AND speeddial='".$called."'";            $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);       if( is_array($result))       {         $called= $result[0][0];       }       else       {         $agi->exec("playback","there_is_not_likeman|noanswer");         $agi->hangup();              $A2B->DbDisconnect();              exit;       }     }     else //查找缩位拨号     {      $QUERY = "SELECT destination FROM cc_superlinkman WHERE card_username='".$A2B->CallerID."' AND destination like '%".$called."'";       $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);      if( is_array($result))       {       $called= $result[0][0];      }      else      {        $agi->exec("playback","there_is_not_likeman|noanswer");              $agi->hangup();              $A2B->DbDisconnect();              exit;      }     }      }            if($mode=='answercall')      {       $agi->answer();    for($answercall=0;$answercall<=3;$answercall++)    {      if($answercall==3)      {       $agi->hangup();       exit;      }      $result = $agi->get_data("please_input_numberphone", 10000, 15);//请输入被叫并以井号键结束      $result_dtmf = $result["result"];      if(is_numeric($result_dtmf) && strlen($result_dtmf)>5)      {            $called= $result_dtmf;            break;          }          elseif(strlen($result_dtmf)==1 && is_numeric($result_dtmf))          {            $QUERY = "SELECT phone FROM cc_speeddial WHERE id_cc_card='".$result_username[0][4]."' AND speeddial='".$result_dtmf."'";        $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);        if( is_array($result))        {          $called= $result[0][0];          break;        }        else        {         $agi->exec("playback","there_is_not_likeman|noanswer");        }          }          elseif(strlen($result_dtmf)==4 && is_numeric($result_dtmf))          {             $QUERY = "SELECT destination FROM cc_superlinkman WHERE card_username='".$A2B->CallerID."' AND destination like '%".$result_dtmf."'";          $result = $A2B -> instance_table -> SQLExec ($A2B->DBHandle, $QUERY);         if( is_array($result))         {         $called= $result[0][0];         break;        }        else        {          $agi->exec("playback","there_is_not_likeman|noanswer");        }          }          else          {            $agi->exec("playback","you_input_error");            }    }      }            $A2B -> destination=$A2B->CallerID;       $called_party=$A2B->destination;     $check_hcode=$RateEngine->rate_check_dialprefix($A2B,$A2B->destination , $A2B->tariff); //找到H码表 将返回前插码 否则返回0   if($check_hcode!=0)   {     $A2B->destination=$check_hcode.$A2B->destination; //能找到H码       $agi->verbose("Hcode is ok".$check_hcode);   }      $h_called_party=$A2B->destination;   $agi->verbose("tariff========".$A2B->tariff);   $agi->verbose("destination========".$A2B->destination);      $agi->exec("playback","please_hangup_wait|noanswer");     $resfindrate = $RateEngine->rate_engine_findrates($A2B, $A2B ->destination, $A2B ->tariff,1);  //1 代表回拨属性  本次是回拨 肯定要写上'1'  默认是外呼       if ($resfindrate!=0)       {         $res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($A2B, $A2B->credit);    $agi->verbose ("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'];      $callbackrate  = $RateEngine -> ratecard_obj[0]['callbackrate'];      $failover_trunk = $RateEngine -> ratecard_obj[0][40+$usetrunk_failover];      $addparameter = $RateEngine -> ratecard_obj[0][42+$usetrunk_failover];      $idtrunk=$RateEngine -> ratecard_obj[0][56];        $iddevice=$RateEngine -> ratecard_obj[0][57];                $destination = $A2B ->destination;      if (strncmp($destination, $removeprefix, strlen($removeprefix)) == 0) $destination= substr($destination, strlen($removeprefix));//?μ?o            $pos_dialingnumber = strpos($ipaddress, '%dialingnumber%' );            $ipaddress = str_replace("

    转载请注明原文地址: https://ibbs.8miu.com/read-750056.html

    最新回复(0)