class.a2billing.php

来自「asterisk用 的voip记费软件」· PHP 代码 · 共 1,467 行 · 第 1/5 页

PHP
1,467 行
字号
	function get_agi_request_parameter($agi){			$this->CallerID 	= $agi->request['agi_callerid'];		$this->channel		= $agi->request['agi_channel'];		$this->uniqueid		= $agi->request['agi_uniqueid'];		$this->accountcode	= $agi->request['agi_accountcode'];		//$this->dnid		= $agi->request['agi_dnid'];		$this->dnid		= $agi->request['agi_extension'];				//Call function to find the cid number		$this -> isolate_cid();				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, ' get_agi_request_parameter = '.$this->CallerID.' ; '.$this->channel.' ; '.$this->uniqueid.' ; '.$this->accountcode.' ; '.$this->dnid);	}			/*	 *	function to find the cid number	 */	function isolate_cid(){				$pos_lt = strpos($this->CallerID, '<');		$pos_gt = strpos($this->CallerID, '>');					if (($pos_lt !== false) && ($pos_gt !== false)){		   $len_gt = $pos_gt - $pos_lt - 1;		   $this->CallerID = substr($this->CallerID,$pos_lt+1,$len_gt);		}	}			/*	 *	function would set when the card is used or when it release	 */	function callingcard_acct_start_inuse($agi, $inuse){				if ($inuse){					$QUERY = "UPDATE cc_card SET inuse=inuse+1 WHERE username='".$this->username."'";			$this -> set_inuse = 1;		}else{ 						$QUERY = "UPDATE cc_card SET inuse=inuse-1 WHERE username='".$this->username."'";			$this -> set_inuse = 0;		}				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[CARD STATUS UPDATE : $QUERY]");		if (!$this -> CC_TESTING) $result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY, 0);				return 0;	}				/**	 *	Function callingcard_ivr_authorize : check the dialed/dialing number and play the time to call	 *	 *  @param object $agi     *  @param float $credit     *  @return 1 if Ok ; -1 if error	**/	function callingcard_ivr_authorize($agi, &$RateEngine, $try_num){		$res=0;								/************** 	ASK DESTINATION 	******************/		$prompt_enter_dest = $this->agiconfig['file_conf_enter_destination'];				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__,  $this->agiconfig['use_dnid']." && ".in_array ($this->dnid, $this->agiconfig['no_auth_dnid'])." && ".strlen($this->dnid)."&& $try_num");				// CHECK IF USE_DNID IF NOT GET THE DESTINATION NUMBER		if ($this->agiconfig['use_dnid']==1 && !in_array ($this->dnid, $this->agiconfig['no_auth_dnid']) && strlen($this->dnid)>2 && $try_num==0){			$this->destination = $this->dnid;		}else{			$res_dtmf = $agi->get_data($prompt_enter_dest, 6000, 20);			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "RES DTMF : ".$res_dtmf ["result"]);			$this->destination = $res_dtmf ["result"];		}				//REDIAL FIND THE LAST DIALED NUMBER (STORED IN THE DATABASE)		if (strlen($this->destination)<=2 && is_numeric($this->destination) && $this->destination>=0){			$QUERY = "SELECT phone FROM cc_speeddial WHERE id_cc_card='".$this->id_card."' AND speeddial='".$this->destination."'";			$result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY);			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "QUERY = $QUERY\n RESULT : ".print_r($result,true));			if( is_array($result))	$this->destination = $result[0][0];					$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "REDIAL : DESTINATION ::> ".$this->destination);		}				// FOR TESTING : ENABLE THE DESTINATION NUMBER		if ($this->CC_TESTING) $this->destination="1800300200";		if ($this->CC_TESTING) $this->destination="3390010022";				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "DESTINATION ::> ".$this->destination);							if ($this->removeinterprefix) $this->destination = $this -> apply_rules ($this->destination);					$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "RULES APPLY ON DESTINATION ::> ".$this->destination);				// TRIM THE "#"s IN THE END, IF ANY		// usefull for SIP or IAX friends with "use_dnid" when their device sends also the "#"		// it should be safe for normal use		$this->destination = rtrim($this->destination, "#");				// SAY BALANCE		// this is hardcoded for now but we might have a setting in a2billing.conf for the combination		if ($this->destination=='*0'){			$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[SAY BALANCE ::> ".$this->credit."]");			$this -> fct_say_balance ($agi, $this->credit);			return -1;		}					//REDIAL FIND THE LAST DIALED NUMBER (STORED IN THE DATABASE)		if ($this->destination=='*1'){			$this->destination = $this->redial;			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[REDIAL : DTMF DESTINATION ::> ".$this->destination."]");				}				if ($this->destination<=0){			$prompt = "prepaid-invalid-digits";			// do not play the error message if the destination number is not numeric			// because most probably it wasn't entered by user (he has a phone keypad remember?)			// it helps with using "use_dnid" and extensions.conf routing			if (is_numeric($this->destination)) $agi-> stream_file($prompt, '#');			return -1;		}				// STRIP * FROM DESTINATION NUMBER		$this->destination = str_replace('*', '', $this->destination);				// LOOKUP RATE : FIND A RATE FOR THIS DESTINATION		$resfindrate = $RateEngine->rate_engine_findrates($this, $this->destination,$this->tariff);		if ($resfindrate==0){			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "ERROR ::> RateEngine didnt succeed to match the dialed number over the ratecard (Please check : id the ratecard is well create ; if the removeInter_Prefix is set according to your prefix in the ratecard ; if you hooked the ratecard to the Call Plan)");		}else{			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "OK - RESFINDRATE::> ".$resfindrate);		}						// IF DONT FIND RATE		if ($resfindrate==0){			$prompt="prepaid-dest-unreachable";			$agi-> stream_file($prompt, '#');			return -1;		}				/*$rate=$result[0][0];		if ($rate<=0){				//$prompt="prepaid-dest-blocked";				$prompt="prepaid-dest-unreachable";				continue;		}*/														// CHECKING THE TIMEOUT							$res_all_calcultimeout = $RateEngine->rate_engine_all_calcultimeout($this, $this->credit);				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "RES_ALL_CALCULTIMEOUT ::> $res_all_calcultimeout");		if (!$res_all_calcultimeout){										$prompt="prepaid-no-enough-credit";			$agi-> stream_file($prompt, '#');			return -1;		}						// calculate timeout		//$this->timeout = intval(($this->credit * 60*100) / $rate);  // -- RATE is millime cents && credit is 1cents				$this->timeout = $RateEngine-> ratecard_obj[0]['timeout'];		// set destination and timeout		// say 'you have x minutes and x seconds'		$minutes = intval($this->timeout / 60);		$seconds = $this->timeout % 60;				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "TIMEOUT::> ".$this->timeout."  : minutes=$minutes - seconds=$seconds");		if (!($minutes>0)){										$prompt="prepaid-no-enough-credit";			$agi-> stream_file($prompt, '#');			return -1;		}				if ($this->agiconfig['say_rateinitial']==1){			$this -> fct_say_rate ($agi, $RateEngine->ratecard_obj[0][12] * 100);   // say rate in cents		}				if ($this->agiconfig['say_timetocall']==1){			$agi-> stream_file('prepaid-you-have', '#');						if ($minutes>0){				$agi->say_number($minutes);				if ($minutes==1){					$agi-> stream_file('prepaid-minute', '#');				}else{					$agi-> stream_file('prepaid-minutes', '#');				}			}			if ($seconds>0){				if ($minutes>0) $agi-> stream_file('vm-and', '#');									$agi->say_number($seconds);				if ($seconds==1){					$agi-> stream_file('prepaid-second', '#');				}else{					$agi-> stream_file('prepaid-seconds', '#');				}			}		}		return 1;	}				/**	 *	Function call_sip_iax_buddy : make the Sip/IAX free calls	 *	 *  @param object $agi	 *  @param object $RateEngine     *  @param integer $try_num     *  @return 1 if Ok ; -1 if error	**/	function call_sip_iax_buddy($agi, &$RateEngine, $try_num){		$res=0;		if ( ($this->agiconfig['use_dnid']==1) && (!in_array ($this->dnid, $this->agiconfig['no_auth_dnid'])) && (strlen($this->dnid)>2 ))		{											$this->destination = $this->dnid;		}		else		{			$res_dtmf = $agi->get_data('prepaid-sipiax-enternumber', 6000, $this->config['global']['len_aliasnumber'], '#');						$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "RES DTMF : ".$res_dtmf ["result"]);			$this->destination = $res_dtmf ["result"];						if ($this->destination<=0){				return -1;			}		}				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "SIP o IAX DESTINATION : ".$this->destination);				$sip_buddies = 0; $iax_buddies = 0;						//$QUERY =  "SELECT name FROM cc_iax_buddies WHERE name='".$this->destination."'";		$QUERY = "SELECT name FROM cc_iax_buddies, cc_card WHERE cc_iax_buddies.name=cc_card.username AND useralias='".$this->destination."'";					$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, $QUERY);												$result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY);		$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, $result);						if( is_array($result)){	$iax_buddies = 1; $destiax=$result[0][0];}							//$QUERY =  "SELECT name FROM cc_sip_buddies WHERE name='".$this->destination."'";		$QUERY = "SELECT name FROM cc_sip_buddies, cc_card WHERE cc_sip_buddies.name=cc_card.username AND useralias='".$this->destination."'";		$result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY);		$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "QUERY = $QUERY\n RESULT : ".print_r($result,true));				if( is_array($result)){	$sip_buddies = 1; $destsip=$result[0][0];}				if (!$sip_buddies && !$iax_buddies){			$agi-> stream_file('prepaid-sipiax-num-nomatch', '#');							return -1;		}				if ($this -> CC_TESTING) $this->destination="kphone";				for ($k=0;$k< $sip_buddies+$iax_buddies;$k++){			if ($k==0 && $sip_buddies){ $this->tech = 'SIP'; $this->destination= $destsip; }			else{ $this->tech = 'IAX2'; $this->destination = $destiax; }							if ($this->agiconfig['record_call'] == 1){				$myres = $agi->exec("MONITOR ".$this->agiconfig['monitor_formatfile']."|".$this->uniqueid."|mb");				$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "EXEC MONITOR ".$this->agiconfig['monitor_formatfile']."|".$this->uniqueid."|mb");			}						$agi->set_callerid($this->useralias);			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[EXEC SetCallerID : ".$this->useralias."]");						$dialparams = $this->agiconfig['dialcommand_param_sipiax_friend'];			$dialstr = $this->tech."/".$this->destination.$dialparams;			$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "app_callingcard sip/iax friend: Dialing '$dialstr' ".$this->tech." Friend.\n");						//# Channel: technology/number@ip_of_gw_to PSTN			// Dial(IAX2/guest@misery.digium.com/s@default) 			$myres = $agi->exec("DIAL $dialstr");			$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "DIAL");					$answeredtime = $agi->get_variable("ANSWEREDTIME");			$answeredtime = $answeredtime['data'];			$dialstatus = $agi->get_variable("DIALSTATUS");			$dialstatus = $dialstatus['data'];											if ($this->agiconfig['record_call'] == 1){				// Monitor(wav,kiki,m)									$myres = $agi->exec("STOPMONITOR");				$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "EXEC StopMonitor (".$this->uniqueid."-".$this->cardnumber.")");			}

⌨️ 快捷键说明

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