soap-card-server.php
来自「asterisk 計費模塊」· PHP 代码 · 共 542 行 · 第 1/2 页
PHP
542 行
$cfriend='sip'; $FG_TABLE_NAME="cc_sip_buddies"; $buddyfile = BUDDY_SIP_FILE; }else{ if (!$iax_friend) continue; $cfriend='iax'; $FG_TABLE_NAME="cc_iax_buddies"; $buddyfile = BUDDY_IAX_FILE; } // Insert Sip/Iax account info if (($ki==0 && $sip_friend) || ($ki==1 && $iax_friend)){ $instance_table1 = new Table($FG_TABLE_NAME, $FG_QUERY_ADITION_SIP_IAX); $result_query1=$instance_table1 -> Add_table ($DBHandle, $param_add_value, $param_add_fields, null, null); $instance_table_friend = new Table($FG_TABLE_NAME,'id, '.$FG_QUERY_ADITION_SIP_IAX); $list_friend = $instance_table_friend -> Get_list ($DBHandle, '', null, null, null, null); $fd=fopen($buddyfile,"w"); if (!$fd){ mail($email_alarm, "ALARM : SOAP-API - Could not open buddy file '$buddyfile'", $mail_content); error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "."[Could not open buddy file '$buddyfile'] - SOAP-API "."\n", 3, $logfile); return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API - Could not open buddy file $buddyfile'); }else{ foreach ($list_friend as $data){ $line="\n\n[".$data[1]."]\n"; if (fwrite($fd, $line) === FALSE) { error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "."[Impossible to write to the file ($buddyfile)] - CODE_ERROR 8"."\n", 3, $logfile); return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API Impossible to write to the file ($buddyfile)'); }else{ for ($i=1;$i<count($data)-1;$i++){ if (strlen($data[$i+1])>0){ if (trim($list_names[$i]) == 'allow'){ $codecs = explode(",",$data[$i+1]); $line = ""; foreach ($codecs as $value) $line .= trim($list_names[$i]).'='.$value."\n"; } else $line = (trim($list_names[$i]).'='.$data[$i+1]."\n"); if (fwrite($fd, $line) === FALSE){ error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "."[Impossible to write to the file ($buddyfile)] - CODE_ERROR 8"."\n", 3, $logfile); return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API ERROR : Card created in the DB but Impossible to write to the file ($buddyfile)'); } } } } } fclose($fd); } } } // END OF FOR - KI } // END if ($iax_friend || $sip_friend) return array($transaction_code, $account_number, $cardnum, $useralias, $uipass, 'result=OK', "ID CARD_CREATED=$result_query$callerid_result"); }else{ mail(EMAIL_ADMIN, "ALARM : SOAP-API (Add_table)", "$FG_ADITION_SECOND_ADD_VALUE\n\n".$mail_content); error_log ("[" . date("Y/m/d G:i:s", mktime()) . "] "."[SOAP-API CODE_ERROR Add_table "."\n", 3, $logfile); return array($transaction_code, '', '', '', '', 'Error', 'SOAP-API CODE_ERROR Add_table'); } } // END - CHECK PARAMETERS LASTNAME ; FIRSTNAME ; ADDRESS ; .... }}$server = new SOAP_Server();$webservice = new Cards();$server->addObjectMap($webservice, 'http://schemas.xmlsoap.org/soap/envelope/');if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD']=='POST') { $server->service($HTTP_RAW_POST_DATA); } else { // Create the DISCO server $disco = new SOAP_DISCO_Server($server,'Cards'); header("Content-type: text/xml"); if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'],'wsdl') == 0) { echo $disco->getWSDL(); } else { echo $disco->getDISCO(); }}exit;// CLASS xmlrpc_client/*Usage: $client = new xmlrpc_client("http://localhost:7080"); print $client->echo('x')."\n"; print $client->add(1, 3)."\n";*/class xmlrpc_client{ var $url; var $urlparts; function xmlrpc_client($url) { $this->url = $url; $this->urlparts = parse_url($this->url); foreach(array('scheme', 'host', 'user', 'pass', 'path', 'query', 'fragment') as $part) { if (!isset($this->urlparts[$part])) { $this->urlparts[$part] = NULL; } } } function call($function, $arguments, &$return) { $requestprms['host'] = $this->urlparts['host']; $requestprms['port'] = $this->urlparts['port']; $requestprms['uri'] = $this->urlparts['path']; $requestprms['method'] = $function; $requestprms['args'] = $arguments; $requestprms['debug'] = 0; $requestprms['timeout'] = 0; $requestprms['user'] = NULL; $requestprms['pass'] = NULL; $requestprms['secure'] = 0; $result = xu_rpc_http_concise($requestprms); if (is_array($result) && isset($result['faultCode'])) { print('Error in xmlrpc call \''.$function.'\''."\n"); print(' code : '.$result['faultCode']."\n"); print(' message: '.$result['faultString']."\n"); return false; } $return = $result; return true; }}/* * function return_xmlrpc_error */function return_xmlrpc_error($errno,$errstr,$errfile=NULL,$errline=NULL ,$errcontext=NULL){ global $xmlrpc_server; if(!$xmlrpc_server)die("Error: $errstr in '$errfile', line '$errline'"); header("Content-type: text/xml; charset=UTF-8"); print(xmlrpc_encode(array( 'faultCode'=>$errno ,'faultString'=>"Remote XMLRPC Error from ".$_SERVER['HTTP_HOST'].": $errstr in at $errfile:$errline" ))); die();} /* * function agesorter */function agesorter($m){ global $agesorter_arr, $xmlrpcerruser, $s; xmlrpc_debugmsg("Entering 'agesorter'"); // get the parameter $sno=$m->getParam(0); // error string for [if|when] things go wrong $err=""; // create the output value $v=new xmlrpcval(); $agar=array(); if (isset($sno) && $sno->kindOf()=="array") { $max=$sno->arraysize(); // TODO: create debug method to print can work once more // print "<!-- found $max array elements -->\n"; for($i=0; $i<$max; $i++) { $rec=$sno->arraymem($i); if ($rec->kindOf()!="struct") { $err="Found non-struct in array at element $i"; break; } // extract name and age from struct $n=$rec->structmem("name"); $a=$rec->structmem("age"); // $n and $a are xmlrpcvals, // so get the scalarval from them $agar[$n->scalarval()]=$a->scalarval(); } $agesorter_arr=$agar; // hack, must make global as uksort() won't // allow us to pass any other auxilliary information uksort($agesorter_arr, agesorter_compare); $outAr=array(); while (list( $key, $val ) = each( $agesorter_arr ) ) { // recreate each struct element $outAr[]=new xmlrpcval(array("name" => new xmlrpcval($key), "age" => new xmlrpcval($val, "int")), "struct"); } // add this array to the output value $v->addArray($outAr); } else { $err="Must be one parameter, an array of structs"; } if ($err) { return new xmlrpcresp(0, $xmlrpcerruser, $err); } else { return new xmlrpcresp($v); }}/* * function getallheaders_xmlrpc */ function getallheaders_xmlrpc($m) { global $xmlrpcerruser; if (function_exists('getallheaders')) { return new xmlrpcresp(php_xmlrpc_encode(getallheaders())); } else { $headers = array(); // IIS: poor man's version of getallheaders foreach ($_SERVER as $key => $val) if (strpos($key, 'HTTP_') === 0) { $key = ucfirst(str_replace('_', '-', strtolower(substr($key, 5)))); $headers[$key] = $val; } return new xmlrpcresp(php_xmlrpc_encode($headers)); } } ?>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?