📄 class.soap_server.php
字号:
<?php
class soap_server extends nusoap_base
{
var $headers = array( );
var $request = "";
var $requestHeaders = "";
var $document = "";
var $requestSOAP = "";
var $methodURI = "";
var $methodname = "";
var $methodparams = array( );
var $xml_encoding = "";
var $SOAPAction = "";
var $outgoing_headers = array( );
var $response = "";
var $responseHeaders = "";
var $responseSOAP = "";
var $methodreturn = false;
var $methodreturnisliteralxml = false;
var $fault = false;
var $result = "successful";
var $operations = array( );
var $wsdl = false;
var $externalWSDLURL = false;
var $debug_flag = false;
function soap_server( $wsdl = false )
{
global $debug;
global $_REQUEST;
global $_SERVER;
global $HTTP_SERVER_VARS;
if ( isset( $debug ) )
{
$this->debug_flag = $debug;
}
else if ( isset( $_REQUEST['debug'] ) )
{
$this->debug_flag = $_REQUEST['debug'];
}
else if ( isset( $_SERVER['QUERY_STRING'] ) )
{
$qs = explode( "&", $_SERVER['QUERY_STRING'] );
foreach ( $qs as $v )
{
if ( substr( $v, 0, 6 ) == "debug=" )
{
$this->debug_flag = substr( $v, 6 );
}
}
}
else if ( isset( $HTTP_SERVER_VARS['QUERY_STRING'] ) )
{
$qs = explode( "&", $HTTP_SERVER_VARS['QUERY_STRING'] );
foreach ( $qs as $v )
{
if ( substr( $v, 0, 6 ) == "debug=" )
{
$this->debug_flag = substr( $v, 6 );
}
}
}
if ( $wsdl )
{
if ( is_object( $wsdl ) && is_a( $wsdl, "wsdl" ) )
{
$this->wsdl = $wsdl;
$this->externalWSDLURL = $this->wsdl->wsdl;
$this->debug( "Use existing wsdl instance from ".$this->externalWSDLURL );
}
else
{
$this->debug( "Create wsdl from ".$wsdl );
$this->wsdl = new wsdl( $wsdl );
$this->externalWSDLURL = $wsdl;
}
$this->debug( "wsdl...\n".$this->wsdl->debug_str );
$this->wsdl->debug_str = "";
if ( $err = $this->wsdl->geterror( ) )
{
exit( "WSDL ERROR: ".$err );
}
}
}
function service( $data )
{
global $QUERY_STRING;
if ( isset( $_SERVER['QUERY_STRING'] ) )
{
$qs = $_SERVER['QUERY_STRING'];
}
else if ( isset( $GLOBALS['QUERY_STRING'] ) )
{
$qs = $GLOBALS['QUERY_STRING'];
}
else if ( isset( $QUERY_STRING ) && $QUERY_STRING != "" )
{
$qs = $QUERY_STRING;
}
if ( isset( $qs ) && ereg( "wsdl", $qs ) )
{
if ( $this->externalWSDLURL )
{
if ( strpos( $this->externalWSDLURL, "://" ) !== false )
{
header( "Location: ".$this->externalWSDLURL );
}
else
{
header( "Content-Type: text/xml\r\n" );
$fp = fopen( $this->externalWSDLURL, "r" );
fpassthru( $fp );
}
}
else
{
header( "Content-Type: text/xml; charset=ISO-8859-1\r\n" );
print $this->wsdl->serialize( );
}
}
else if ( $data == "" && $this->wsdl )
{
print $this->webdescription( );
}
else
{
$this->parse_request( $data );
if ( !$this->fault )
{
$this->invoke_method( );
}
if ( !$this->fault )
{
$this->serialize_return( );
}
$this->send_response( );
}
}
function parse_http_headers( )
{
global $HTTP_SERVER_VARS;
global $_SERVER;
$this->request = "";
if ( function_exists( "getallheaders" ) )
{
$this->headers = getallheaders( );
foreach ( $this->headers as $k => $v )
{
$this->request .= "{$k}: {$v}\r\n";
$this->debug( "{$k}: {$v}" );
}
if ( isset( $this->headers['SOAPAction'] ) )
{
$this->SOAPAction = str_replace( "\"", "", $this->headers['SOAPAction'] );
}
if ( strpos( $this->headers['Content-Type'], "=" ) )
{
$enc = str_replace( "\"", "", substr( strstr( $this->headers['Content-Type'], "=" ), 1 ) );
if ( eregi( "^(ISO-8859-1|US-ASCII|UTF-8)\$", $enc ) )
{
$this->xml_encoding = strtoupper( $enc );
}
else
{
$this->xml_encoding = "US-ASCII";
}
}
else
{
$this->xml_encoding = "UTF-8";
}
}
else if ( isset( $_SERVER ) && is_array( $_SERVER ) )
{
foreach ( $GLOBALS['_SERVER'] as $k => $v )
{
if ( substr( $k, 0, 5 ) == "HTTP_" )
{
$k = str_replace( " ", "-", ucwords( strtolower( str_replace( "_", " ", substr( $k, 5 ) ) ) ) );
}
else
{
$k = str_replace( " ", "-", ucwords( strtolower( str_replace( "_", " ", $k ) ) ) );
}
if ( $k == "Soapaction" )
{
$k = "SOAPAction";
$v = str_replace( "\"", "", $v );
$v = str_replace( "\\", "", $v );
$this->SOAPAction = $v;
}
else if ( $k == "Content-Type" )
{
if ( strpos( $v, "=" ) )
{
$enc = substr( strstr( $v, "=" ), 1 );
$enc = str_replace( "\"", "", $enc );
$enc = str_replace( "\\", "", $enc );
if ( eregi( "^(ISO-8859-1|US-ASCII|UTF-8)\$", $enc ) )
{
$this->xml_encoding = strtoupper( $enc );
}
else
{
$this->xml_encoding = "US-ASCII";
}
}
else
{
$this->xml_encoding = "UTF-8";
}
}
$this->headers[$k] = $v;
$this->request .= "{$k}: {$v}\r\n";
$this->debug( "{$k}: {$v}" );
}
}
else if ( is_array( $HTTP_SERVER_VARS ) )
{
foreach ( $HTTP_SERVER_VARS as $k => $v )
{
if ( substr( $k, 0, 5 ) == "HTTP_" )
{
$k = str_replace( " ", "-", ucwords( strtolower( str_replace( "_", " ", substr( $k, 5 ) ) ) ) );
if ( $k == "Soapaction" )
{
$k = "SOAPAction";
$v = str_replace( "\"", "", $v );
$v = str_replace( "\\", "", $v );
$this->SOAPAction = $v;
}
else if ( $k == "Content-Type" )
{
if ( strpos( $v, "=" ) )
{
$enc = substr( strstr( $v, "=" ), 1 );
$enc = str_replace( "\"", "", $enc );
$enc = str_replace( "\\", "", $enc );
if ( eregi( "^(ISO-8859-1|US-ASCII|UTF-8)\$", $enc ) )
{
$this->xml_encoding = strtoupper( $enc );
}
else
{
$this->xml_encoding = "US-ASCII";
}
}
else
{
$this->xml_encoding = "UTF-8";
}
}
$this->headers[$k] = $v;
$this->request .= "{$k}: {$v}\r\n";
$this->debug( "{$k}: {$v}" );
}
}
}
}
function parse_request( $data = "" )
{
$this->debug( "entering parse_request() on ".date( "H:i Y-m-d" ) );
$this->parse_http_headers( );
$this->debug( "got character encoding: ".$this->xml_encoding );
if ( isset( $this->headers['Content-Encoding'] ) && $this->headers['Content-Encoding'] != "" )
{
$this->debug( "got content encoding: ".$this->headers['Content-Encoding'] );
if ( $this->headers['Content-Encoding'] == "deflate" || $this->headers['Content-Encoding'] == "gzip" )
{
if ( function_exists( "gzuncompress" ) )
{
if ( $this->headers['Content-Encoding'] == "deflate" && ( $degzdata = @gzuncompress( $data ) ) )
{
$data = $degzdata;
}
else if ( $this->headers['Content-Encoding'] == "gzip" && ( $degzdata = gzinflate( substr( $data, 10 ) ) ) )
{
$data = $degzdata;
}
else
{
$this->fault( "Server", "Errors occurred when trying to decode the data" );
return;
}
}
else
{
$this->fault( "Server", "This Server does not support compressed data" );
return;
}
}
}
$this->request .= "\r\n".$data;
$this->requestSOAP = $data;
$parser = new soap_parser( $data, $this->xml_encoding );
$this->debug( "parser debug: \n".$parser->debug_str );
if ( $err = $parser->geterror( ) )
{
$this->result = "fault: error in msg parsing: ".$err;
$this->fault( "Server", "error in msg parsing:\n".$err );
}
else
{
$this->methodURI = $parser->root_struct_namespace;
$this->methodname = $parser->root_struct_name;
$this->debug( "method name: ".$this->methodname );
$this->debug( "calling parser->get_response()" );
$this->methodparams = $parser->get_response( );
$this->requestHeaders = $parser->getheaders( );
$this->document = $parser->document;
}
$this->debug( "leaving parse_request() on ".date( "H:i Y-m-d" ) );
}
function invoke_method( )
{
$this->debug( "entering invoke_method" );
if ( !function_exists( $this->methodname ) )
{
$this->debug( "method '{$this->methodname}' not found!" );
$this->result = "fault: method not found";
$this->fault( "Server", "method '{$this->methodname}' not defined in service" );
return;
}
if ( $this->wsdl )
{
if ( !( $this->opData = $this->wsdl->getoperationdata( $this->methodname ) ) )
{
$this->fault( "Server", "Operation '{$this->methodname}' is not defined in the WSDL for this service" );
return;
}
$this->debug( "opData is ".$this->vardump( $this->opData ) );
}
$this->debug( "method '{$this->methodname}' exists" );
if ( !$this->verify_method( $this->methodname, $this->methodparams ) )
{
$this->debug( "ERROR: request not verified against method signature" );
$this->result = "fault: request failed validation against method signature";
$this->fault( "Server", "Operation '{$this->methodname}' not defined in service." );
return;
}
$this->debug( "params var dump ".$this->vardump( $this->methodparams ) );
if ( $this->methodparams )
{
$this->debug( "calling '{$this->methodname}' with params" );
if ( !function_exists( "call_user_func_array" ) )
{
$this->debug( "calling method using eval()" );
$funcCall = $this->methodname."(";
foreach ( $this->methodparams as $param )
{
$funcCall .= "\"{$param}\",";
}
$funcCall = substr( $funcCall, 0, 0 - 1 ).")";
$this->debug( "function call:<br>".$funcCall );
@eval( "\$this->methodreturn = {$funcCall};" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -