class.a2billing.php

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

PHP
1,467 行
字号
							$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[".$this->tech." Friend][K=$k]:[ANSWEREDTIME=".$answeredtime."-DIALSTATUS=".$dialstatus."]");							//# Ooh, something actually happend! 			if ($dialstatus  == "BUSY") {														$answeredtime=0;				$agi-> stream_file('prepaid-isbusy', '#');			} elseif ($this->dialstatus == "NOANSWER") {				$answeredtime=0;				$agi-> stream_file('prepaid-noanswer', '#');			} elseif ($dialstatus == "CANCEL") {				$answeredtime=0;			} elseif ($dialstatus == "ANSWER") {				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "-> dialstatus : $dialstatus, answered time is ".$answeredtime." \n");			} elseif ($k+1 == $sip_buddies+$iax_buddies){				$prompt="prepaid-dest-unreachable";				$agi-> stream_file($prompt, '#');			}						if (($dialstatus  == "CHANUNAVAIL") || ($dialstatus  == "CONGESTION"))	continue;							if ($answeredtime >0){ 				$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[CC_RATE_ENGINE_UPDATESYSTEM: usedratecard K=$K - (answeredtime=$answeredtime :: dialstatus=$dialstatus :: cost=$cost)]");				$QUERY = "INSERT INTO cc_call (uniqueid,sessionid,username,nasipaddress,starttime,sessiontime, calledstation, ".											" terminatecause, stoptime, calledrate, sessionbill, calledcountry, calledsub, destination, id_tariffgroup, id_tariffplan, id_ratecard, id_trunk, src, sipiax) VALUES ".					"('".$this->uniqueid."', '".$this->channel."',  '".$this->username."', '".$this->hostname."',";				if ($this->config['database']['dbtype'] == "postgres"){					$QUERY .= " CURRENT_TIMESTAMP - interval '$answeredtime seconds' ";				}else{					$QUERY .= " CURRENT_TIMESTAMP - INTERVAL $answeredtime SECOND ";				}										$QUERY .= ", '$answeredtime', '".$this->destination."', '$dialstatus', now(), '0', '0', ".					" '".$this->countrycode."', '".$this->subcode."', '".$this->tech." CALL', '0', '0', '0', '0', '$this->CallerID', '1' )";								$result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY, 0);				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "QUERY = $QUERY\n RESULT : ".$result);				return 1;			}		}		return -1;		}			/**	 *	Function call_did 	 *	 *  @param object $agi	 *  @param object $RateEngine     	 *  @param object $listdestination	 	cc_did.id, cc_did_destination.id, billingtype, cc_did.id_trunk,	destination, cc_did.id_trunk, voip_call		     *  @return 1 if Ok ; -1 if error	**/	function call_did($agi, &$RateEngine, $listdestination){		$res=0;		if ($this -> CC_TESTING) $this->destination="kphone";		$this->agiconfig['say_balance_after_auth']=0;		$this->agiconfig['say_timetocall']=0;						if (($listdestination[0][2]==0) || ($listdestination[0][2]==2)) $doibill = 1;		else $doibill = 0;		$callcount=0;		foreach ($listdestination as $inst_listdestination){			$callcount++;						$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[A2Billing] DID call friend: FOLLOWME=$callcount (cardnumber:".$inst_listdestination[6]."|destination:".$inst_listdestination[4]."|tariff:".$inst_listdestination[3].")\n");						$this->agiconfig['cid_enable']= 0;			$this->accountcode = $inst_listdestination[6];			$this->tariff = $inst_listdestination[3];			$this->destination = $inst_listdestination[4];			$this->username = $inst_listdestination[6];									// MAKE THE AUTHENTICATION TO GET ALL VALUE : CREDIT - EXPIRATION - ...			if ($this -> callingcard_ivr_authenticate($agi)!=0){				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[A2Billing] DID call friend: AUTHENTICATION FAILS !!!\n");			}else{								// CHECK IF DESTINATION IS SET				if (strlen($inst_listdestination[4])==0) continue;								// IF VOIP CALL				if ($inst_listdestination[5]==1){										// RUN MONITOR TO RECORD CALL					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");					}											$dialparams = $this->agiconfig['dialcommand_param_sipiax_friend'];					$dialstr = $inst_listdestination[4].$dialparams;										$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[A2Billing] DID call friend: Dialing '$dialstr' Friend.\n");										//# Channel: technology/number@ip_of_gw_to PSTN					// Dial(IAX2/guest@misery.digium.com/s@default) 					// DIAL OUT					$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){										$myres = $agi->exec("STOPMONITOR");						$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "EXEC StopMonitor (".$this->uniqueid."-".$this->cardnumber.")");					}											$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[".$inst_listdestination[4]." Friend][followme=$callcount]:[ANSWEREDTIME=".$answeredtime."-DIALSTATUS=".$dialstatus."]");																	//# Ooh, something actually happend! 					if ($dialstatus  == "BUSY") {						$answeredtime=0;						$agi-> stream_file('prepaid-isbusy', '#');						// FOR FOLLOWME IF THERE IS MORE WE PASS TO THE NEXT ONE OTHERWISE WE NEED TO LOG THE CALL MADE						if (count($listdestination)>$callcount) continue;					} elseif ($this->dialstatus == "NOANSWER") {						$answeredtime=0;						$agi-> stream_file('prepaid-noanswer', '#');						// FOR FOLLOWME IF THERE IS MORE WE PASS TO THE NEXT ONE OTHERWISE WE NEED TO LOG THE CALL MADE						if (count($listdestination)>$callcount) continue;					} elseif ($dialstatus == "CANCEL") {						$answeredtime=0;						// FOR FOLLOWME IF THERE IS MORE WE PASS TO THE NEXT ONE OTHERWISE WE NEED TO LOG THE CALL MADE						if (count($listdestination)>$callcount) continue;					} elseif ($dialstatus == "ANSWER") {						$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[A2Billing] DID call friend: dialstatus : $dialstatus, answered time is ".$answeredtime." \n");					} elseif (($dialstatus  == "CHANUNAVAIL") || ($dialstatus  == "CONGESTION")) {						$answeredtime=0;						// FOR FOLLOWME IF THERE IS MORE WE PASS TO THE NEXT ONE OTHERWISE WE NEED TO LOG THE CALL MADE						if (count($listdestination)>$callcount) continue;					} else{						$agi-> stream_file('prepaid-noanswer', '#');						// FOR FOLLOWME IF THERE IS MORE WE PASS TO THE NEXT ONE OTHERWISE WE NEED TO LOG THE CALL MADE						if (count($listdestination)>$callcount) continue;					}																										if ($answeredtime >0){ 													$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[DID CALL - LOG CC_CALL: FOLLOWME=$callcount - (answeredtime=$answeredtime :: dialstatus=$dialstatus :: cost=$cost)]");													$QUERY = "INSERT INTO cc_call (uniqueid,sessionid,username,nasipaddress,starttime,sessiontime, calledstation, ".													" terminatecause, stoptime, calledrate, sessionbill, calledcountry, calledsub, destination, id_tariffgroup, id_tariffplan, id_ratecard, id_trunk, src, sipiax) VALUES ".							"('".$this->uniqueid."', '".$this->channel."',  '".$this->username."', '".$this->hostname."',";						if ($this->config['database']['dbtype'] == "postgres"){							$QUERY .= " CURRENT_TIMESTAMP - interval '$answeredtime seconds' ";						}else{							$QUERY .= " CURRENT_TIMESTAMP - INTERVAL $answeredtime SECOND ";						}												$QUERY .= ", '$answeredtime', '".$inst_listdestination[4]."', '$dialstatus', now(), '0', '0', ".							" '".$this->countrycode."', '".$this->subcode."', 'DID CALL', '0', '0', '0', '0', '$this->CallerID', '3' )";												$result = $this -> instance_table -> SQLExec ($this->DBHandle, $QUERY, 0);						$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[DID CALL - LOG CC_CALL: SQL: $QUERY]:[result:$result]");												// CC_DID & CC_DID_DESTINATION - cc_did.id, cc_did_destination.id													$QUERY = "UPDATE cc_did SET secondusedreal = secondusedreal + $answeredtime WHERE id='".$inst_listdestination[0]."'";						$result = $this->instance_table -> SQLExec ($this -> DBHandle, $QUERY, 0);						$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[UPDATE DID: SQL: $QUERY]:[result:$result]");												$QUERY = "UPDATE cc_did_destination SET secondusedreal = secondusedreal + $answeredtime WHERE id='".$inst_listdestination[1]."'";						$result = $this->instance_table -> SQLExec ($this -> DBHandle, $QUERY, 0);						$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[UPDATE DID_DESTINATION: SQL: $QUERY]:[result:$result]");												return 1;					}													// ELSEIF NOT VOIP CALL					}else{											$this->agiconfig['use_dnid']=1;						$this->agiconfig['say_timetocall']=0;												$this->dnid = $this->destination = $inst_listdestination[4];						if ($this->CC_TESTING) $this->dnid = $this->destination="011324885";																		if ($this -> callingcard_ivr_authorize($agi, $RateEngine, 0)==1){															// PERFORM THE CALL								$result_callperf = $RateEngine->rate_engine_performcall ($agi, $this -> destination, $this);							if (!$result_callperf) {								$prompt="prepaid-noanswer.gsm"; 								$agi-> stream_file($prompt, '#');								continue;							}								 							if (($RateEngine->dialstatus == "NOANSWER") || ($RateEngine->dialstatus == "CANCEL") || ($RateEngine->dialstatus == "BUSY") || ($RateEngine->dialstatus == "CHANUNAVAIL") || ($RateEngine->dialstatus == "CONGESTION")) continue;															// INSERT CDR  & UPDATE SYSTEM							$RateEngine->rate_engine_updatesystem($this, $agi, $this-> destination, $doibill, 1);							// CC_DID & CC_DID_DESTINATION - cc_did.id, cc_did_destination.id														$QUERY = "UPDATE cc_did SET secondusedreal = secondusedreal + ".$RateEngine->answeredtime." WHERE id='".$inst_listdestination[0]."'";							$result = $this->instance_table -> SQLExec ($this -> DBHandle, $QUERY, 0);							$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[UPDATE DID: SQL: $QUERY]:[result:$result]");														$QUERY = "UPDATE cc_did_destination SET secondusedreal = secondusedreal + ".$RateEngine->answeredtime." WHERE id='".$inst_listdestination[1]."'";							$result = $this->instance_table -> SQLExec ($this -> DBHandle, $QUERY, 0);							$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[UPDATE DID_DESTINATION: SQL: $QUERY]:[result:$result]");														// THEN STATUS IS ANSWER							break;						}											}			} // END IF AUTHENTICATE		}// END FOR	}			/**	 *	Function to play the balance 	 * 	format : "you have 100 dollars and 28 cents"	 *	 *  @param object $agi     *  @param float $credit     *  @return nothing	**/	function fct_say_balance ($agi, $credit, $fromvoucher){				global $currencies_list;				if (isset($this->agiconfig['agi_force_currency']) && strlen($this->agiconfig['agi_force_currency'])==3)		{ 			$this->currency = $this->agiconfig['agi_force_currency'];		}				$this -> debug( VERBOSE | WRITELOG, $agi, __FILE__, __LINE__, "[CURRENCY : $this->currency]");		if (!isset($currencies_list[strtoupper($this->currency)][2]) || !is_numeric($currencies_list[strtoupper($this->currency)][2])) $mycur = 1;		else $mycur = $currencies_list[strtoupper($this->currency)][2];		$credit_cur = $credit / $mycur;				list($units,$cents)=split('[.]', $credit_cur);		if (strlen($cents)>2) $cents=substr($cents,0,2);		if ($units=='') $units=0;		if ($cents=='') $cents=0;		elseif (strlen($cents)==1) $cents.= '0';				if (isset($this->agiconfig['currency_association_internal'][strtolower($this->currency)])){			$unit_audio = $this->agiconfig['currency_association_internal'][strtolower($this->currency)];		}else{			$unit_audio = $this->agiconfig['currency_association_internal']['all'];		}						$cent_audio = 'prepaid-cents';						// say 'you have x dollars and x cents'		if ($fromvoucher!=1)$agi-> stream_file('prepaid-you-have', '#');		else $agi-> stream_file('prepaid-account_refill', '#');				if ($units==0 && $cents==0){								$agi->say_number(0);								$agi-> stream_file($unit_audio, '#');		}else{			if ($units >= 1){				$agi->say_number($units);				$agi-> stream_file($unit_audio, '#');			}						if ($units > 0 && $cents > 0){				$agi-> stream_file('vm-and', '#');			}			if ($cents>0){				$agi->say_number($cents);				$agi-> stream_file($cent_audio, '#');			}		}	}		/**	 *      Function to play the rate in cents	 *      format : "7 point 5 cents per minute"	 *	 *  @param object $agi	 *  @param float $rate	 *  @return nothing	 **/	function fct_say_rate ($agi, $rate){		$this -> debug( WRITELOG, $agi, __FILE__, __LINE__, "[SAY RATE ::> ".$rate."]");

⌨️ 快捷键说明

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