📄 nusoap.php
字号:
$length += strlen( $chunk );
}
else
{
$chunk = substr( $buffer, $chunkstart, $chunkend - $chunkstart );
$new .= $chunk;
$length += strlen( $chunk );
$chunkstart = $chunkend + strlen( $lb );
$chunkend = strpos( $buffer, $lb, $chunkstart ) + strlen( $lb );
if ( $chunkend == FALSE )
{
}
else
{
$temp = substr( $buffer, $chunkstart, $chunkend - $chunkstart );
$chunk_size = hexdec( trim( $temp ) );
$chunkstart = $chunkend;
}
}
}
return $new;
}
function buildpayload( $data )
{
$this->outgoing_headers['Content-Length'] = strlen( $data );
$this->outgoing_payload = "{$this->request_method} {$this->uri} HTTP/{$this->protocol_version}\r\n";
foreach ( $this->outgoing_headers as $k => $v )
{
$this->outgoing_payload .= $k.": ".$v."\r\n";
}
$this->outgoing_payload .= "\r\n";
$this->outgoing_payload .= $data;
}
function sendrequest( $data )
{
$this->buildpayload( $data );
if ( $this->scheme == "http" || $this->scheme == "ssl" )
{
if ( !fputs( $this->fp, $this->outgoing_payload, strlen( $this->outgoing_payload ) ) )
{
$this->seterror( "couldn't write message data to socket" );
$this->debug( "couldn't write message data to socket" );
return false;
}
$this->debug( "wrote data to socket, length = ".strlen( $this->outgoing_payload ) );
return true;
}
else if ( $this->scheme == "https" )
{
foreach ( $this->outgoing_headers as $k => $v )
{
$curl_headers[] = "{$k}: {$v}";
}
curl_setopt( $this->ch, CURLOPT_HTTPHEADER, $curl_headers );
if ( $this->request_method == "POST" )
{
curl_setopt( $this->ch, CURLOPT_POST, 1 );
curl_setopt( $this->ch, CURLOPT_POSTFIELDS, $data );
}
$this->debug( "set cURL payload" );
return true;
}
}
function getresponse( )
{
$this->incoming_payload = "";
if ( $this->scheme == "http" || $this->scheme == "ssl" )
{
$data = "";
while ( !isset( $lb ) )
{
if ( feof( $this->fp ) )
{
$this->incoming_payload = $data;
$this->debug( "found no headers before EOF after length ".strlen( $data ) );
$this->debug( "received before EOF:\n".$data );
$this->seterror( "server failed to send headers" );
return false;
}
$data .= fgets( $this->fp, 256 );
$pos = strpos( $data, "\r\n\r\n" );
if ( 1 < $pos )
{
$lb = "\r\n";
}
else
{
$pos = strpos( $data, "\n\n" );
if ( 1 < $pos )
{
$lb = "\n";
}
}
if ( isset( $lb ) && ereg( "^HTTP/1.1 100", $data ) )
{
unset( $lb );
$data = "";
}
}
$this->incoming_payload .= $data;
$this->debug( "found end of headers after length ".strlen( $data ) );
$header_data = trim( substr( $data, 0, $pos ) );
$header_array = explode( $lb, $header_data );
foreach ( $header_array as $header_line )
{
$arr = explode( ":", $header_line, 2 );
if ( 1 < count( $arr ) )
{
$header_name = strtolower( trim( $arr[0] ) );
$this->incoming_headers[$header_name] = trim( $arr[1] );
}
else if ( isset( $header_name ) )
{
$this->incoming_headers[$header_name] .= $lb." ".$header_line;
}
}
$content_length = isset( $this->incoming_headers['content-length'] ) ? $this->incoming_headers['content-length'] : 2147483647;
$data = "";
$strlen = 0;
while ( $strlen < $content_length && !feof( $this->fp ) )
{
$readlen = min( 8192, $content_length - $strlen );
$tmp = fread( $this->fp, $readlen );
$strlen += strlen( $tmp );
$data .= $tmp;
}
$this->debug( "read body of length ".strlen( $data ) );
$this->incoming_payload .= $data;
$this->debug( "received a total of ".strlen( $this->incoming_payload )." bytes of data from server" );
if ( !$this->persistentConnection || feof( $this->fp ) )
{
fclose( $this->fp );
$this->fp = false;
$this->debug( "closed socket" );
}
if ( $this->incoming_payload == "" )
{
$this->seterror( "no response from server" );
return false;
}
if ( isset( $this->incoming_headers['transfer-encoding'] ) && strtolower( $this->incoming_headers['transfer-encoding'] ) == "chunked" )
{
if ( !( $data = $this->decodechunked( $data, $lb ) ) )
{
$this->seterror( "Decoding of chunked data failed" );
return false;
}
$this->incoming_payload = $header_data.$lb.$lb.$data;
}
}
else if ( $this->scheme == "https" )
{
$this->debug( "send and receive with cURL" );
$this->incoming_payload = curl_exec( $this->ch );
$data = $this->incoming_payload;
$cErr = curl_error( $this->ch );
if ( $cErr != "" )
{
$err = "cURL ERROR: ".curl_errno( $this->ch ).": ".$cErr."<br>";
foreach ( curl_getinfo( $this->ch ) as $k => $v )
{
$err .= "{$k}: {$v}<br>";
}
$this->debug( $err );
$this->seterror( $err );
curl_close( $this->ch );
return false;
}
$this->debug( "No cURL error, closing cURL" );
curl_close( $this->ch );
if ( ereg( "^HTTP/1.1 100", $data ) )
{
if ( $pos = strpos( $data, "\r\n\r\n" ) )
{
$data = ltrim( substr( $data, $pos ) );
}
else if ( $pos = strpos( $data, "\n\n" ) )
{
$data = ltrim( substr( $data, $pos ) );
}
}
if ( $pos = strpos( $data, "\r\n\r\n" ) )
{
$lb = "\r\n";
}
else if ( $pos = strpos( $data, "\n\n" ) )
{
$lb = "\n";
}
else
{
$this->debug( "no proper separation of headers and document" );
$this->seterror( "no proper separation of headers and document" );
return false;
}
$header_data = trim( substr( $data, 0, $pos ) );
$header_array = explode( $lb, $header_data );
$data = ltrim( substr( $data, $pos ) );
$this->debug( "found proper separation of headers and document" );
$this->debug( "cleaned data, stringlen: ".strlen( $data ) );
foreach ( $header_array as $header_line )
{
$arr = explode( ":", $header_line, 2 );
if ( 1 < count( $arr ) )
{
$this->incoming_headers[strtolower( trim( $arr[0] ) )] = trim( $arr[1] );
}
}
}
if ( isset( $this->incoming_headers['www-authenticate'] ) && strstr( $header_array[0], "401 Unauthorized" ) )
{
if ( substr( "Digest ", $this->incoming_headers['www-authenticate'] ) )
{
$digestString = str_replace( "Digest ", "", $this->incoming_headers['www-authenticate'] );
$digestElements = explode( ", ", $digestString );
while ( list( $key, $val ) = each( $digestElements ) )
{
$tempElement = explode( "=", $val );
$digestRequest[$tempElement[0]] = str_replace( "\"", "", $tempElement[1] );
}
if ( isset( $digestRequest['nonce'] ) )
{
$this->debug( "found nonce in WWW-Authenticate: ".$this->incoming_headers['www-authenticate'] );
$this->setcredentials( $this->username, $this->password, "digest", $digestRequest );
$this->tryagain = true;
return false;
}
}
$this->debug( "HTTP authentication failed" );
$this->seterror( "HTTP authentication failed" );
return false;
}
if ( isset( $this->incoming_headers['content-encoding'] ) && $this->incoming_headers['content-encoding'] != "" && ( strtolower( $this->incoming_headers['content-encoding'] ) == "deflate" || strtolower( $this->incoming_headers['content-encoding'] ) == "gzip" ) )
{
if ( function_exists( "gzuncompress" ) )
{
if ( $this->incoming_headers['content-encoding'] == "deflate" && ( $degzdata = @gzuncompress( $data ) ) )
{
$data = $degzdata;
}
else if ( $this->incoming_headers['content-encoding'] == "gzip" && ( $degzdata = gzinflate( substr( $data, 10 ) ) ) )
{
$data = $degzdata;
}
else
{
$this->seterror( "Errors occurred when trying to decode the data" );
}
$this->incoming_payload = $header_data.$lb.$lb.$data;
}
else
{
$this->seterror( "The server sent deflated data. Your php install must have the Zlib extension compiled in to support this." );
}
}
if ( strlen( $data ) == 0 )
{
$this->debug( "no data after headers!" );
$this->seterror( "no data present after HTTP headers" );
return false;
}
return $data;
}
function setcontenttype( $type, $charset = false )
{
$this->outgoing_headers['Content-Type'] = $type.( $charset ? "; charset=".$charset : "" );
}
function usepersistentconnection( )
{
if ( isset( $this->outgoing_headers['Accept-Encoding'] ) )
{
return false;
}
$this->protocol_version = "1.1";
$this->persistentConnection = true;
$this->outgoing_headers['Connection'] = "Keep-Alive";
return true;
}
}
class soap_server extends nusoap_base
{
var $title = "NuSOAP";
var $version = "0.6.7";
var $revision = "\$Revision: 1.72 \$";
var $error_str = false;
var $debug_str = "";
var $charencoding = true;
var $XMLSchemaVersion = "http://www.w3.org/2001/XMLSchema";
var $soap_defencoding = "gb2312";
var $namespaces = array
(
"SOAP-ENV" => "http://schemas.xmlsoap.org/soap/envelope/",
"xsd" => "http://www.w3.org/2001/XMLSchema",
"xsi" => "http://www.w3.org/2001/XMLSchema-instance",
"SOAP-ENC" => "http://schemas.xmlsoap.org/soap/encoding/",
"si" => "http://soapinterop.org/xsd"
);
var $usedNamespaces = array( );
var $typemap = array
(
"http://www.w3.org/2001/XMLSchema" => array
(
"string" => "string",
"boolean" => "boolean",
"float" => "double",
"double" => "double",
"decimal" => "double",
"duration" => "",
"dateTime" => "string",
"time" => "string",
"date" => "string",
"gYearMonth" => "",
"gYear" => "",
"gMonthDay" => "",
"gDay" => "",
"gMonth" => "",
"hexBinary" => "string",
"base64Binary" => "string",
"normalizedString" => "string",
"token" => "string",
"language" => "",
"NMTOKEN" => "",
"NMTOKENS" => "",
"Name" => "",
"NCName" => "",
"ID" => "",
"IDREF" => "",
"IDREFS" => "",
"ENTITY" => "",
"ENTITIES" => "",
"integer" => "integer",
"nonPositiveInteger" => "integer",
"negativeInteger" => "integer",
"long" => "integer",
"int" => "integer",
"short" => "integer",
"byte" => "integer",
"nonNegativeInteger" => "integer",
"unsignedLong" => "",
"unsignedInt" => "",
"unsignedShort" => "",
"unsignedByte" => "",
"positiveInteger" => ""
),
"http://www.w3.org/1999/XMLSchema" => array
(
"i4" => "",
"int" => "integer",
"boolean" => "boolean",
"string" => "string",
"double" => "double",
"float" => "double",
"dateTime" => "string",
"timeInstant" => "string",
"base64Binary" => "string",
"base64" => "string",
"ur-type" => "array"
),
"http://soapinterop.org/xsd" => array
(
"SOAPStruct" => "struct"
),
"http://schemas.xmlsoap.org/soap/encoding/" => array
(
"base64" => "string",
"array" => "array",
"Array" => "array"
),
"http://xml.apache.org/xml-soap" => array
(
0 => "Map"
)
);
var $xmlEntities = array
(
"quot" => "\"",
"amp" => "&",
"lt" => "<",
"gt" => ">",
"apos" => "'"
);
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 $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[
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -