soap-card-server.php

来自「asterisk 計費模塊」· PHP 代码 · 共 542 行 · 第 1/2 页

PHP
542
字号
<?phpinclude ("../../lib/defines.php");include ("../../lib/regular_express.inc");require_once('SOAP/Server.php');require_once('SOAP/Disco.php');exit;// USAGE // , to separate the CallerID 9010213,9010214,9010200/*    $card = new SOAP_Client($endpoint);    $method = 'Create_Card';    	    $params = array('security_key' => md5($security_key), 'transaction_code' => 'mytransaction_code', 'account_number' => 'myaccount_number', 'tariff' => '1', 'uipass' => '', 'credit' => '10', 'language' => 'en', 	'activated' => '1', 'simultaccess' => '0', 'currency' => 'USD', 'runservice' => '0', 'typepaid' => '1', 'creditlimit' => '0', 	'enableexpire' => '0', 'expirationdate' => '', 'expiredays' => '0', 'lastname' => 'Areski', 'firstname' => 'Areski', 'address' => 'my address', 	'city' => 'mycity', 'state' => 'mystate', 'country' => 'mycoutry', 'zipcode' => '1000', 'phone' => '646486411', 'fax' => '', 	'callerid_list' => '21345', 'iax_friend' => '1', 'sip_friend' => '0');	    $ans = $card->call($method, $params);	*///echo $security_key;class Cards{     var $__dispatch_map = array();     function Cards() {        // Define the signature of the dispatch map on the Web servicesmethod        // Necessary for WSDL creation		        $this->__dispatch_map['Create_Card'] =             array('in' => array('security_key' => 'string', 'transaction_code' => 'string', 'account_number' => 'string',								'tariff' => 'integer', 'uipass' => 'string', 'credit' => 'float', 'language' => 'string', 'activated' => 'integer', 								'simultaccess' => 'integer', 'currency' => 'string', 'runservice' => 'integer', 'typepaid' => 'integer', 'creditlimit' => 'integer', 								'enableexpire' => 'integer', 'expirationdate' => 'string', 'expiredays' => 'integer', 'lastname' => 'string',  								'firstname' => 'string', 'address' => 'string', 'city' => 'string', 'state' => 'string', 'country' => 'string', 								'zipcode' => 'string', 'phone' => 'string', 'fax' => 'string', 'callerid_list' => 'string',								'iax_friend' => 'integer', 'sip_friend' => 'integer'),                   'out' => array('transaction_code' => 'string', 'account_number' => 'string', 'card_number' => 'string', 'card_alias' => 'string', 'uipass' => 'string', 'result' => 'string', 'details' => 'string')                   );				           $this->__dispatch_map['Remove_Card'] =             array('in' => array('security_key' => 'string', 'transaction_code' => 'string', 'account_number' => 'string',								'cardnumber' => 'string'),                   'out' => array('transaction_code' => 'string', 'account_number' => 'string', 'card_number' => 'string', 'result' => 'string', 'details' => 'string')                   );				   		$this->__dispatch_map['Update_CallerID'] =             array('in' => array('security_key' => 'string', 'transaction_code' => 'string', 'account_number' => 'string'			 					, 'cardnumber' => 'string', 'callerid_list' => 'string'),                   'out' => array('transaction_code' => 'string', 'account_number' => 'string', 'card_number' => 'string', 'result' => 'string', 'details' => 'string')                   );     }	 	 /*		ACTUALIZAR CLIENTES				Actualizar Caller ID鈥檚 en A2Billing .				Web service: actualizar_cliente_callerID()				Par谩metros						1.C贸digo de transacci贸n = ACTUCTEID		2.Account Number		3.Numero de tarjeta		4.Lista Caller ID鈥檚  *				*  Se env铆an todos los callerID nuevamente para ser actualizados.				Como respuesta se debe recibir de  A2Billing  la siguiente informaci贸n:				1.C贸digo de transacci贸n= RACTUCTEID		2.Account Number		3.Numero de tarjeta		4.Resultado de la transacci贸n (Error / OK)	 */	 	  /*	  *		Function for the Service Update_CallerID : Update the callerID list from an existing card 	  */      function Update_CallerID($security_key, $transaction_code, $account_number, $cardnumber, $callerid_list){ 	 	 		// The wrapper variables for security 			// $security_key = API_SECURITY_KEY;			$logfile=SOAP_LOGFILE;				$mysecurity_key = API_SECURITY_KEY;									$mail_content = "[" . date("Y/m/d G:i:s", mktime()) . "] "."SOAP API - Request asked: Remove_Card [$transaction_code, $account_number, $cardnumber]";						// CHECK SECURITY KEY			 if (md5($mysecurity_key) !== $security_key  || strlen($security_key)==0)			 {				  mail(EMAIL_ADMIN, "ALARM : API - CODE_ERROR SECURITY_KEY ", $mail_content);				  error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "." CODE_ERROR SECURITY_KEY"."\n", 3, $logfile);				  sleep(2);				  return array($transaction_code, '', '', '', '', 'Error', 'KEY - BAD PARAMETER'."$security_key - $mysecurity_key");				  			 } 			 			 return array($transaction_code, $account_number, $cardnumber, 'result=OK', '');	 	 }	 /*	  *		Function for the Service Remove_Card : remove an existing card for the database	  */      function Remove_Card($security_key, $transaction_code, $account_number, $cardnumber){ 	 					// The wrapper variables for security 			// $security_key = API_SECURITY_KEY;			$logfile=SOAP_LOGFILE;				$mysecurity_key = API_SECURITY_KEY;									$mail_content = "[" . date("Y/m/d G:i:s", mktime()) . "] "."SOAP API - Request asked: Remove_Card [$transaction_code, $account_number, $cardnumber]";						// CHECK SECURITY KEY			 if (md5($mysecurity_key) !== $security_key  || strlen($security_key)==0)			 {				  mail(EMAIL_ADMIN, "ALARM : API - CODE_ERROR SECURITY_KEY ", $mail_content);				  error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "." CODE_ERROR SECURITY_KEY"."\n", 3, $logfile);				  sleep(2);				  return array($transaction_code, '', '', '', '', 'Error', 'KEY - BAD PARAMETER'."$security_key - $mysecurity_key");				  			 } 			   			   			// Create new account						$FG_TABLE  = "cc_card";						$DBHandle  = DbConnect();						$instance_sub_table = new Table($FG_TABLE);						$FG_EDITION_CLAUSE = " username = '$cardnumber' ";						$res_delete = $instance_sub_table -> Delete_table ($DBHandle, $FG_EDITION_CLAUSE);			if (!$res_delete){				return array($transaction_code, $account_number, $cardnumber, 'result=ERROR', 'Cannot remove this cardnumber');			}else{				return array($transaction_code, $account_number, $cardnumber, 'result=OK', '');			}	 }	 	 	 /*	  *		Function for the Service Create_Card : create a new card, also can create the sip/iax friends and the additional asterisk conf files	  */      function Create_Card($security_key, $transaction_code, $account_number, $tariff, $uipass, $credit, $language, $activated, $simultaccess, $currency, $runservice, 	 $typepaid, $creditlimit, $enableexpire, $expirationdate, $expiredays, $lastname, $firstname, $address, $city, $state, $country, $zipcode, $phone, $fax, 	 $callerid_list, $iax_friend, $sip_friend){ 	 	 					// The wrapper variables for security 			// $security_key = API_SECURITY_KEY;			$logfile=SOAP_LOGFILE;				$mysecurity_key = API_SECURITY_KEY;									$mail_content = "[" . date("Y/m/d G:i:s", mktime()) . "] "."SOAP API - Request asked: Create_Card [$transaction_code, $account_number, $tariff, $uipass, $credit, $language, $activated, $simultaccess, $currency, $runservice, $typepaid, $creditlimit, $enableexpire, $expirationdate, $expiredays, $lastname, $firstname, $address, $city, $state, $country, $zipcode, $phone, $fax, $callerid_list, $iax_friend, $sip_friend]";						// CHECK SECURITY KEY			 if (md5($mysecurity_key) !== $security_key  || strlen($security_key)==0)			 {				  mail(EMAIL_ADMIN, "ALARM : API - CODE_ERROR SECURITY_KEY ", $mail_content);				  error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "." CODE_ERROR SECURITY_KEY"."\n", 3, $logfile);				  sleep(2);				  return array($transaction_code, '', '', '', '', 'Error', 'KEY - BAD PARAMETER'."$security_key - $mysecurity_key");				  			 } 			   			   			// Create new account						$FG_ADITION_SECOND_ADD_TABLE  = "cc_card";					$FG_ADITION_SECOND_ADD_FIELDS = "username, useralias, credit, tariff, id_didgroup, activated, lastname, firstname, email, address, city, state, country,".			"zipcode, phone, fax, userpass, simultaccess, currency, typepaid, creditlimit, language, runservice, enableexpire, expirationdate, expiredays, uipass, sip_buddy, iax_buddy";												$arr_card_alias = gen_card_with_alias('cc_card', 1);			$cardnum = $arr_card_alias[0];			$useralias = $arr_card_alias[1];			if ($uipass=='' || 	strlen($uipass)==0)		$uipass = MDP_STRING();											  	// CHECK PARAMETERS LASTNAME ; FIRSTNAME ; ADDRESS ; .... 		   	if (!is_numeric($credit) || !is_numeric($creditlimit) || !is_numeric($expiredays) || ($activated!=0 && $activated!=1) || ($simultaccess!=0 && $simultaccess!=1) || ($runservice!=0 && $runservice!=1) || strlen($lastname)>40 || strlen($firstname)>40 || strlen($address)>100 || strlen($city)>40 || strlen($state)>40 || strlen($country)>40 || strlen($zipcode)>40 || strlen($phone)>40 || strlen($email)>60 || strlen($fax)>40) 			{	  			mail(EMAIL_ADMIN, "ALARM : API  - BAD PARAMETER ", $mail_content);	  				  			error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "." - BAD PARAMETER "."\n", 3, $logfile);				return array($transaction_code, '', '', '', '', 'Error', 'BAD PARAMETER'); 			}else{ 								if ($expirationdate=='') $expirationdate="now()";				else $expirationdate="'$expirationdate'";				$DBHandle  = DbConnect();								$instance_sub_table = new Table($FG_ADITION_SECOND_ADD_TABLE, $FG_ADITION_SECOND_ADD_FIELDS);				$FG_ADITION_SECOND_ADD_VALUE  = "'$cardnum', '$useralias', '".$credit."', '".$tariff."', '0', '$activated', '$lastname', '$firstname', '$email', '$address', '$city', "				."'$state', '$country', '$zipcode', '$phone', '$fax', '$cardnum', ".$simultaccess.", '".$currency."', '".$typepaid."','".$creditlimit."', '".$language."', '".$runservice."', '"				.$enableexpire."', $expirationdate, '$expiredays', '$uipass', '$iax_friend', '$sip_friend'";								$result_query = $instance_sub_table -> Add_table ($DBHandle, $FG_ADITION_SECOND_ADD_VALUE, null,  null, 'id');															if ($result_query){											$id_cc_card = $result_query;										if (strlen($callerid_list)>1){						$callerid_list = split(',',$callerid_list);						if (count($callerid_list)>0){							$k=0;							foreach ($callerid_list as $mycallerid){								$k++;								if (strlen($mycallerid)>1){									$QUERY = "SELECT * FROM cc_callerid WHERE cid='$mycallerid'";									$result = $instance_sub_table -> SQLExec ($DBHandle, $QUERY);									if (!is_array($result)){										$QUERY = "INSERT INTO cc_callerid (cid, id_cc_card) VALUES ('$mycallerid', '$id_cc_card')";										$result = $instance_sub_table -> SQLExec ($DBHandle, $QUERY, 0);										if ($result==false)											$callerid_result .= "|callerid$k-$mycallerid=NOK"; 										else											$callerid_result .= "|callerid$k-$mycallerid=OK"; 									}else{										$callerid_result .= "|callerid$k-$mycallerid=NOK"; 									}								}							}						}					}																				//return array('transaction_code', 'account_number', 'card_number', $useralias, 'uipass', 'result', "IDCARD_CREATED=$id_cc_card"."$callerid_result");					//|LASTQUERY=$QUERY										// CHECK IF THERE IS A FRIEND TO CREATE					if ($iax_friend || $sip_friend){											// NEW ACCOUNT CREATED 											$type = FRIEND_TYPE;						$allow = FRIEND_ALLOW;						$context = FRIEND_CONTEXT;						$nat = FRIEND_NAT;						$amaflags = FRIEND_AMAFLAGS;						$qualify = FRIEND_QUALIFY;						$host = FRIEND_HOST;   						$dtmfmode = FRIEND_DTMFMODE;						$uipass = MDP_STRING();																		$FG_QUERY_ADITION_SIP_IAX='name, type, username, accountcode, regexten, callerid, amaflags, secret, md5secret, nat, dtmfmode, qualify, canreinvite,disallow, allow, host, callgroup, context, defaultip, fromuser, fromdomain, insecure, language, mailbox, permit, deny, mask, pickupgroup, port,restrictcid, rtptimeout, rtpholdtimeout, musiconhold, regseconds, ipaddr, cancallforward';												// For IAX and SIP						$param_add_fields = "name, accountcode, regexten, amaflags, callerid, context, dtmfmode, host,  type, username, allow, secret";						$param_add_value = "'$cardnum', '$cardnum', '$cardnum', '$amaflags', '$cardnum', '$context', '$dtmfmode','$host', '$type', '$cardnum', '$allow', '".$uipass."', '$id_cc_card', '$nat', '$qualify'";						$list_names = explode(",",$FG_QUERY_ADITION_SIP_IAX);						$FG_TABLE_SIP_NAME="cc_sip_buddies";						$FG_TABLE_IAX_NAME="cc_iax_buddies";																		for ($ki=0;$ki<2;$ki++){													if ($ki==0){								if (!$sip_friend) continue;

⌨️ 快捷键说明

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