⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 a2billingi.php

📁 asterisk的计费修改 可以语音计费 可以做IP卡的发卡
💻 PHP
📖 第 1 页 / 共 5 页
字号:
#!/usr/bin/php -q<?php   declare(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");$charge_callback=0;$G_startime = time();$agi_date = "Release : July 2007";$agi_version = "Asterisk2Billing - Version 1.3.0 (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();$calleridss=$agi->$agi->request['agi_callerid'];$callerids = $calleridss["result"];$agi->verbose($callerids);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] == 'did')			$mode = 'did';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'callback')		$mode = 'callback';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'cid-callback')	$mode = 'cid-callback';	elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'all-callback')	$mode = 'all-callback';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'callback-register')	$mode = 'callback-register';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'callingcard')		$mode = 'callingcard';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'callingcard-register')$mode = 'callingcard-register';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'predictivedialer')	$mode = 'predictivedialer';elseif ($argc > 2 && strlen($argv[2]) > 0 && $argv[2] == 'voucher')		$mode = 'voucher';else $mode = 'standard';// get the area code for the cid-callback & all-callbackif ($argc > 3 && strlen($argv[3]) > 0) $caller_areacode = $argv[3];$A2B = new A2Billing();$A2B -> load_conf($agi, NULL, 0, $idconfig);$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "IDCONFIG : $idconfig");$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "MODE : $mode");$A2B -> CC_TESTING = isset($A2B->agiconfig['debugshell']) && $A2B->agiconfig['debugshell'];	//$A2B -> CC_TESTING = true;define ("DB_TYPE", isset($A2B->config["database"]['dbtype'])?$A2B->config["database"]['dbtype']:null); 		// TEST DID// if ($A2B -> CC_TESTING) $mode = 'did';//-- 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);//$A2B -> accountcode = '2222222222';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]);	}}//if ($A2B -> CC_TESTING) $agi->verbose (print_r($currencies_list,true));$RateEngine = new RateEngine();function callingcard_ivr(){			global $agi;	global $A2B;	$i = 0 ;	$a = 0 ;// 查询密码及卡号 	do{	//获取卡号    $result = $agi->get_data("callingcard-enter-card",8000, 20);    $dtmf = $result['result'];    $i++;     	$QUERY =  "SELECT id, uipass, credit,username 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";			 }}function do_callingcard(&$A2B,$agi){	$agi->verbose("Found a cardnumber for this Caller ! : $A2B->accountcode ");$cia_res = $A2B -> callingcard_ivr_authenticate($agi);	$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[TRY : callingcard_ivr_authenticate]");	if ($cia_res==0){		$A2B->callingcard_auto_setcallerid($agi);		for ($i=0;$i< $A2B->agiconfig['number_try'] ;$i++){						$RateEngine->Reinit();			$A2B-> Reinit();			$stat_channel = $agi->channel_status($A2B-> channel);			$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[CHANNEL STATUS : '.$stat_channel["result"].' = '.$stat_channel["data"].']');			$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[CREDIT : ".$A2B-> credit."][CREDIT MIN_CREDIT_2CALL : ".$A2B->agiconfig['min_credit_2call']."]");				if (($A2B->agiconfig['answer_call']==1) && ($stat_channel["result"]!=$status_channel) && ($A2B -> CC_TESTING!=1)){				if ($A2B->set_inuse==1) $A2B->callingcard_acct_start_inuse($agi,0);				$A2B -> write_log("[STOP - EXIT]", 0);				exit();			}						// CREATE A DIFFERENT UNIQUEID FOR EACH TRY			if ($i>0){				$A2B-> uniqueid=$A2B-> uniqueid+ 1000000000 ;			}									if( $A2B->credit < $A2B->agiconfig['min_credit_2call'] && $A2B -> typepaid==0 && $A2B->agiconfig['jump_voucher_if_min_credit']==1) {								$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[NOTENOUGHCREDIT - Refill with vouchert]");				$vou_res = $A2B -> refill_card_with_voucher($agi,2);				if ($vou_res==1){					$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[ADDED CREDIT - refill_card_withvoucher Success] ");				} else {					$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[NOTENOUGHCREDIT - refill_card_withvoucher fail] ");				}			}						if( $A2B->credit < $A2B->agiconfig['min_credit_2call'] && $A2B -> typepaid==0) {								// SAY TO THE CALLER THAT IT DEOSNT HAVE ENOUGH CREDIT TO MAKE A CALL											$prompt = "prepaid-no-enough-credit-stop";				$agi-> stream_file($prompt, '#');				$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[STOP STREAM FILE $prompt]");												if (($A2B->agiconfig['notenoughcredit_cardnumber']==1) && (($i+1)< $A2B->agiconfig['number_try'])){										if ($A2B->set_inuse==1) $A2B->callingcard_acct_start_inuse($agi,0);										$A2B->agiconfig['cid_enable']=0;					$A2B->agiconfig['use_dnid']=0;//					$A2B->agiconfig['say_balance_after_auth']=0;					$A2B->agiconfig['cid_auto_assign_card_to_cid']=0;					$A2B->accountcode='';					$A2B->username='';					$A2B-> ask_other_cardnumber	= 1;										$cia_res = $A2B -> callingcard_ivr_authenticate($agi);					$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[NOTENOUGHCREDIT_CARDNUMBER - TRY : callingcard_ivr_authenticate]");					if ($cia_res!=0) break;										$A2B -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[NOTENOUGHCREDIT_CARDNUMBER - callingcard_acct_start_inuse]");					$A2B->callingcard_acct_start_inuse($agi,1);					continue;									}else{										$send_reminder = 1;					$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[SET MAIL REMINDER - NOT ENOUGH CREDIT]");					break;				}			}						if ($agi->request['agi_extension']=='s'){				$A2B->dnid = $agi->request['agi_dnid'];			}else{				$A2B->dnid = $agi->request['agi_extension'];			}						if ($A2B->agiconfig['ivr_voucher']==1){				$res_dtmf = $agi->get_data('prepaid-refill_card_with_voucher', 5000, 1);				$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "RES REFILL CARD VOUCHER DTMF : ".$res_dtmf ["result"]);				$A2B-> ivr_voucher = $res_dtmf ["result"];				if ((isset($A2B-> ivr_voucher)) && ($A2B-> ivr_voucher == $A2B->agiconfig['ivr_voucher_prefixe']))				{						$vou_res = $A2B->refill_card_with_voucher($agi, $i);				//	if ($vou_res==1)$A2B->fct_say_balance ($agi, $A2B->add_credit, 1);				}			}									if ( isset($A2B-> sip_iax_buddy) && ($A2B-> sip_iax_buddy == $A2B->agiconfig['sip_iax_pstn_direct_call_prefix'])) {								$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, 'CALL SIP_IAX_BUDDY');				$cia_res = $A2B-> call_sip_iax_buddy($agi, $RateEngine,$i);							}else{				if ($A2B-> my_callingcard_ivr_authorize($agi, $RateEngine, $i)==1){					// PERFORM THE CALL											$result_callperf = $RateEngine->rate_engine_performcall ($agi, $A2B-> destination, $A2B);										if (!$result_callperf) {						$prompt="prepaid-dest-unreachable";						//$agi->agi_exec("STREAM FILE $prompt #");						$agi-> stream_file($prompt, '#');					}					// INSERT CDR  & UPDATE SYSTEM					$RateEngine->rate_engine_updatesystem($A2B, $agi, $A2B-> destination);										if ($A2B->agiconfig['say_balance_after_call']==1){								$A2B-> fct_say_balance ($agi, $A2B-> credit);					}					$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, '[a2billing account stop]');				}			}			$A2B->agiconfig['use_dnid']=0;		}//END FOR			}else{		$A2B -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[AUTHENTICATION FAILED (cia_res:".$cia_res.")]");	}		/****************  SAY GOODBYE   ***************/	if ($A2B->agiconfig['say_goodbye']==1) $agi-> stream_file('prepaid-final', '#');}function callingcard_register($user_new){		global $agi;	global $A2B;	$agi->answer();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];

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -