日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区

您的位置:首頁技術文章
文章詳情頁

PHP xml-rpc遠程調用

瀏覽:21日期:2024-01-11 08:30:35

從網上找來的XML-RPC庫,對于開發小型的外部通訊接口很有用,把這個代碼保存為xml-rpc.inc.php

<?php/*從網上找來的XML-RPC庫,對于開發小型的外部通訊接口很有用*/function & XML_serialize($data, $level = 0, $prior_key = NULL){#assumes a hash, keys are the variable names$xml_serialized_string = '';while(list($key, $value) = each($data)){$inline = false;$numeric_array = false;$attributes = '';#echo 'My current key is '$key', called with prior key '$prior_key'<br>';if(!strstr($key, ' attr')){ #if it's not an attributeif(array_key_exists('$key attr', $data)){while(list($attr_name, $attr_value) = each($data['$key attr'])){#echo 'Found attribute $attribute_name with value $attribute_value<br>';$attr_value = &htmlspecialchars($attr_value, ENT_QUOTES);$attributes .= ' $attr_name='$attr_value'';}}if(is_numeric($key)){#echo 'My current key ($key) is numeric. My parent key is '$prior_key'<br>';$key = $prior_key;}else{#you can't have numeric keys at two levels in a row, so this is ok#echo 'Checking to see if a numeric key exists in data.';if(is_array($value) and array_key_exists(0, $value)){# echo ' It does! Calling myself as a result of a numeric array.<br>';$numeric_array = true;$xml_serialized_string .= XML_serialize($value, $level, $key);}#echo '<br>';}if(!$numeric_array){$xml_serialized_string .= str_repeat('t', $level) . '<$key$attributes>';if(is_array($value)){$xml_serialized_string .= 'rn' . XML_serialize($value, $level+1);}else{$inline = true;$xml_serialized_string .= htmlspecialchars($value);}$xml_serialized_string .= (!$inline ? str_repeat('t', $level) : '') . '</$key>rn';}}else{#echo 'Skipping attribute record for key $key<bR>';}}if($level == 0){$xml_serialized_string = '<?xml version='1.0' ?>rn' . $xml_serialized_string;return $xml_serialized_string;}else{return $xml_serialized_string;}}class XML {var $parser; #a reference to the XML parservar $document; #the entire XML structure built up so farvar $current; #a pointer to the current item - what is thisvar $parent; #a pointer to the current parent - the parent will be an arrayvar $parents; #an array of the most recent parent at each levelvar $last_opened_tag;function XML($data=null){$this->parser = xml_parser_create();xml_parser_set_option ($this->parser, XML_OPTION_CASE_FOLDING, 0);xml_set_object($this->parser, $this);xml_set_element_handler($this->parser, 'open', 'close');xml_set_character_data_handler($this->parser, 'data');# register_shutdown_function(array($this, 'destruct'));}function destruct(){xml_parser_free($this->parser);}function parse($data){$this->document = array();$this->parent = $this->document;$this->parents = array();$this->last_opened_tag = NULL;xml_parse($this->parser, $data);return $this->document;}function open($parser, $tag, $attributes){#echo 'Opening tag $tag<br>n';$this->data = '';$this->last_opened_tag = $tag; #tag is a stringif(array_key_exists($tag, $this->parent)){#echo 'There's already an instance of '$tag' at the current level ($level)<br>n';if(is_array($this->parent[$tag]) and array_key_exists(0, $this->parent[$tag])){ #if the keys are numeric#need to make sure they're numeric (account for attributes)$key = count_numeric_items($this->parent[$tag]);#echo 'There are $key instances: the keys are numeric.<br>n';}else{#echo 'There is only one instance. Shifting everything around<br>n';$temp = $this->parent[$tag];unset($this->parent[$tag]);$this->parent[$tag][0] = $temp;if(array_key_exists('$tag attr', $this->parent)){#shift the attributes around too if they exist$temp = $this->parent['$tag attr'];unset($this->parent['$tag attr']);$this->parent[$tag]['0 attr'] = $temp;}$key = 1;}$this->parent = $this->parent[$tag];}else{$key = $tag;}if($attributes){$this->parent['$key attr'] = $attributes;}$this->parent[$key] = array();$this->parent = $this->parent[$key];array_unshift($this->parents, $this->parent);}function data($parser, $data){#echo 'Data is '', htmlspecialchars($data), ''<br>n';if($this->last_opened_tag != NULL){$this->data .= $data;}}function close($parser, $tag){#echo 'Close tag $tag<br>n';if($this->last_opened_tag == $tag){$this->parent = $this->data;$this->last_opened_tag = NULL;}array_shift($this->parents);$this->parent = $this->parents[0];}}function & XML_unserialize($xml){$xml_parser = new XML();$data = $xml_parser->parse($xml);$xml_parser->destruct();return $data;}function & XMLRPC_parse($request){if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_parse', '<p>Received the following raw request:</p>' . XMLRPC_show($request, 'print_r', true));}$data = &XML_unserialize($request);if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_parse', '<p>Returning the following parsed request:</p>' . XMLRPC_show($data, 'print_r', true));}return $data;}function & XMLRPC_prepare($data, $type = NULL){if(is_array($data)){$num_elements = count($data);if((array_key_exists(0, $data) or !$num_elements) and $type != 'struct'){ #it's an arrayif(!$num_elements){ #if the array is emptyempty$returnvalue = array('array' => array('data' => NULL));}else{$returnvalue['array']['data']['value'] = array();$temp = $returnvalue['array']['data']['value'];$count = count_numeric_items($data);for($n=0; $n<$count; $n++){$type = NULL;if(array_key_exists('$n type', $data)){$type = $data['$n type'];}$temp[$n] = XMLRPC_prepare($data[$n], $type);}}}else{ #it's a structif(!$num_elements){ #if the struct is emptyempty$returnvalue = array('struct' => NULL);}else{$returnvalue['struct']['member'] = array();$temp = $returnvalue['struct']['member'];while(list($key, $value) = each($data)){if(substr($key, -5) != ' type'){ #if it's not a type specifier$type = NULL;if(array_key_exists('$key type', $data)){$type = $data['$key type'];}$temp[] = array('name' => $key, 'value' => XMLRPC_prepare($value, $type));}}}}}else{ #it's a scalarif(!$type){if(is_int($data)){$returnvalue['int'] = $data;return $returnvalue;}elseif(is_float($data)){$returnvalue['double'] = $data;return $returnvalue;}elseif(is_bool($data)){$returnvalue['boolean'] = ($data ? 1 : 0);return $returnvalue;}elseif(preg_match('/^d{8}Td{2}:d{2}:d{2}$/', $data, $matches)){ #it's a date$returnvalue['dateTime.iso8601'] = $data;return $returnvalue;}elseif(is_string($data)){$returnvalue['string'] = htmlspecialchars($data);return $returnvalue;}}else{$returnvalue[$type] = htmlspecialchars($data);}}return $returnvalue;}function & XMLRPC_adjustValue($current_node){if(is_array($current_node)){if(isset($current_node['array'])){if(!is_array($current_node['array']['data'])){#If there are no elements, return an emptyempty arrayreturn array();}else{#echo 'Getting rid of array -> data -> value<br>n';$temp = $current_node['array']['data']['value'];if(is_array($temp) and array_key_exists(0, $temp)){$count = count($temp);for($n=0;$n<$count;$n++){$temp2[$n] = &XMLRPC_adjustValue($temp[$n]);}$temp = $temp2;}else{$temp2 = &XMLRPC_adjustValue($temp);$temp = array($temp2);#I do the temp assignment because it avoids copying,# since I can put a reference in the array#PHP's reference model is a bit silly, and I can't just say:# $temp = array(&XMLRPC_adjustValue($temp));}}}elseif(isset($current_node['struct'])){if(!is_array($current_node['struct'])){#If there are no members, return an emptyempty arrayreturn array();}else{#echo 'Getting rid of struct -> member<br>n';$temp = $current_node['struct']['member'];if(is_array($temp) and array_key_exists(0, $temp)){$count = count($temp);for($n=0;$n<$count;$n++){#echo 'Passing name {$temp[$n][name]}. Value is: ' . show($temp[$n][value], var_dump, true) . '<br>n';$temp2[$temp[$n]['name']] = &XMLRPC_adjustValue($temp[$n]['value']);#echo 'adjustValue(): After assigning, the value is ' . show($temp2[$temp[$n]['name']], var_dump, true) . '<br>n';}}else{#echo 'Passing name $temp[name]<br>n';$temp2[$temp['name']] = &XMLRPC_adjustValue($temp['value']);}$temp = $temp2;}}else{$types = array('string', 'int', 'i4', 'double', 'dateTime.iso8601', 'base64', 'boolean');$fell_through = true;foreach($types as $type){if(array_key_exists($type, $current_node)){#echo 'Getting rid of '$type'<br>n';$temp = $current_node[$type];#echo 'adjustValue(): The current node is set with a type of $type<br>n';$fell_through = false;break;}}if($fell_through){$type = 'string';#echo 'Fell through! Type is $type<br>n';}switch ($type){case 'int': case 'i4': $temp = (int)$temp; break;case 'string': $temp = (string)$temp; break;case 'double': $temp = (double)$temp; break;case 'boolean': $temp = (bool)$temp; break;}}}else{$temp = (string)$current_node;}return $temp;}function XMLRPC_getParams($request){if(!is_array($request['methodCall']['params'])){#If there are no parameters, return an emptyempty arrayreturn array();}else{#echo 'Getting rid of methodCall -> params -> param<br>n';$temp = $request['methodCall']['params']['param'];if(is_array($temp) and array_key_exists(0, $temp)){$count = count($temp);for($n = 0; $n < $count; $n++){#echo 'Serializing parameter $n<br>';$temp2[$n] = &XMLRPC_adjustValue($temp[$n]['value']);}}else{$temp2[0] = &XMLRPC_adjustValue($temp['value']);}$temp = $temp2;return $temp;}}function XMLRPC_getMethodName($methodCall){#returns the method namereturn $methodCall['methodCall']['methodName'];}function XMLRPC_request($site, $location, $methodName, $params = NULL, $user_agent = NULL){$site = explode(':', $site);if(isset($site[1]) and is_numeric($site[1])){$port = $site[1];}else{$port = 80;}$site = $site[0];$data['methodCall']['methodName'] = $methodName;$param_count = count($params);if(!$param_count){$data['methodCall']['params'] = NULL;}else{for($n = 0; $n<$param_count; $n++){$data['methodCall']['params']['param'][$n]['value'] = $params[$n];}}$data = XML_serialize($data);if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_request', '<p>Received the following parameter list to send:</p>' . XMLRPC_show($params, 'print_r', true));}$conn = fsockopen ($site, $port); #open the connectionif(!$conn){ #if the connection was not opened successfullyif(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_request', '<p>Connection failed: Couldn't make the connection to $site.</p>');}return array(false, array('faultCode'=>10532, 'faultString'=>'Connection failed: Couldn't make the connection to $site.'));}else{$headers ='POST $location HTTP/1.0rn' .'Host: $sitern' .'Connection: closern' .($user_agent ? 'User-Agent: $user_agentrn' : '') .'Content-Type: text/xmlrn' .'Content-Length: ' . strlen($data) . 'rnrn';fputs($conn, '$headers');fputs($conn, $data);if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_request', '<p>Sent the following request:</p>nn' . XMLRPC_show($headers . $data, 'print_r', true));}#socket_set_blocking ($conn, false);$response = '';while(!feof($conn)){$response .= fgets($conn, 1024);}fclose($conn);#strip headers off of response$data = XML_unserialize(substr($response, strpos($response, 'rnrn')+4));if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_request', '<p>Received the following response:</p>nn' . XMLRPC_show($response, 'print_r', true) . '<p>Which was serialized into the following data:</p>nn' . XMLRPC_show($data, 'print_r', true));}if(isset($data['methodResponse']['fault'])){$return = array(false, XMLRPC_adjustValue($data['methodResponse']['fault']['value']));if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_request', '<p>Returning:</p>nn' . XMLRPC_show($return, 'var_dump', true));}return $return;}else{$return = array(true, XMLRPC_adjustValue($data['methodResponse']['params']['param']['value']));if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_request', '<p>Returning:</p>nn' . XMLRPC_show($return, 'var_dump', true));}return $return;}}}function XMLRPC_response($return_value, $server = NULL){$data['methodResponse']['params']['param']['value'] = $return_value;$return = XML_serialize($data);if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_response', '<p>Received the following data to return:</p>nn' . XMLRPC_show($return_value, 'print_r', true));}header('Connection: close');header('Content-Length: ' . strlen($return));header('Content-Type: text/xml');header('Date: ' . date('r'));if($server){header('Server: $server');}if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_response', '<p>Sent the following response:</p>nn' . XMLRPC_show($return, 'print_r', true));}echo $return;}function XMLRPC_error($faultCode, $faultString, $server = NULL){$array['methodResponse']['fault']['value']['struct']['member'] = array();$temp = $array['methodResponse']['fault']['value']['struct']['member'];$temp[0]['name'] = 'faultCode';$temp[0]['value']['int'] = $faultCode;$temp[1]['name'] = 'faultString';$temp[1]['value']['string'] = $faultString;$return = XML_serialize($array);header('Connection: close');header('Content-Length: ' . strlen($return));header('Content-Type: text/xml');header('Date: ' . date('r'));if($server){header('Server: $server');}if(defined('XMLRPC_DEBUG') and XMLRPC_DEBUG){XMLRPC_debug('XMLRPC_error', '<p>Sent the following error response:</p>nn' . XMLRPC_show($return, 'print_r', true));}echo $return;}function XMLRPC_convert_timestamp_to_iso8601($timestamp){#takes a unix timestamp and converts it to iso8601 required by XMLRPC#an example iso8601 datetime is '20010822T03:14:33'return date('YmdTH:i:s', $timestamp);}function XMLRPC_convert_iso8601_to_timestamp($iso8601){return strtotime($iso8601);}function count_numeric_items($array){return is_array($array) ? count(array_filter(array_keys($array), 'is_numeric')) : 0;}function XMLRPC_debug($function_name, $debug_message){$GLOBALS['XMLRPC_DEBUG_INFO'][] = array($function_name, $debug_message);}function XMLRPC_debug_print(){if($GLOBALS['XMLRPC_DEBUG_INFO']){echo '<table border='1' width='100%'>n';foreach($GLOBALS['XMLRPC_DEBUG_INFO'] as $debug){echo '<tr><th style='vertical-align: top'>$debug[0]</th><td>$debug[1]</td></tr>n';}echo '</table>n';unset($GLOBALS['XMLRPC_DEBUG_INFO']);}else{echo '<p>No debugging information available yet.</p>';}}function XMLRPC_show($data, $func = 'print_r', $return_str = false){ob_start();$func($data);$output = ob_get_contents();ob_end_clean();if($return_str){return '<pre>' . htmlspecialchars($output) . '</pre>n';}else{echo '<pre>', htmlspecialchars($output), '</pre>n';}}?>

服務端程序例子,server.php

<?include 'xml-rpc.inc.php';//定義可被遠程調用的方法$xmlrpc_methods=array();$xmlrpc_methods['insertRecords']='insertRecords';//獲得用戶傳入的方法名和參數$xmlrpc_request = XMLRPC_parse($HTTP_RAW_POST_DATA);$methodName = XMLRPC_getMethodName($xmlrpc_request);$params = XMLRPC_getParams($xmlrpc_request);if (!isset($xmlrpc_methods[$methodName])){XMLRPC_error('1','你所調用的方法不存在');}else {$xmlrpc_methods[$methodName]($params);}function insertRecords($params){if (emptyempty($params)){XMLRPC_error('2','參數出錯');}XMLRPC_response(XMLRPC_prepare('http://www.emtit.com'));}?>

PHP客戶端調用服務端方法例子

<?phpinclude_once 'xml-rpc.inc';$params=array(2,3);$result=XMLRPC_request('127.0.0.1','/services/server.php','insertRecords',$params);//服務端文件放在services文件夾下print_r($result);?>

標簽: PHP
日本不卡不码高清免费观看,久久国产精品久久w女人spa,黄色aa久久,三上悠亚国产精品一区二区三区
免播放器亚洲一区| 麻豆视频在线看| 悠悠资源网久久精品| 久久久夜精品| 尤物tv在线精品| 91久久亚洲| 视频在线观看一区二区三区| 美国欧美日韩国产在线播放| 蜜桃91丨九色丨蝌蚪91桃色| 蜜桃av一区二区| 久久国内精品自在自线400部| 久久精品99国产精品| 精品国产亚洲一区二区三区在线 | 久久福利精品| 中文字幕日韩亚洲| 国产精品视频3p| 久久婷婷久久| 天堂av一区| 国产综合色区在线观看| 欧美专区一区二区三区| 国产精品主播| 国产综合视频| 国产日韩亚洲欧美精品| 电影亚洲精品噜噜在线观看| 老鸭窝亚洲一区二区三区| 国产精品一国产精品k频道56| 精品视频国产| 中文一区在线| 精品91福利视频| 好看不卡的中文字幕| 日韩动漫一区| 成人精品动漫一区二区三区| 日韩在线卡一卡二| 久久婷婷国产| 麻豆成人在线| 久久一区欧美| 蜜臀精品一区二区三区在线观看| 国产精品2区| 亚洲免费一区二区| 高清av一区| 日韩高清成人在线| 91精品一区二区三区综合在线爱 | 国产精品99在线观看| 亚洲免费在线| 日韩av福利| 国产精品宾馆| 蜜桃视频第一区免费观看| 色综合狠狠操| 欧美日韩一区二区三区四区在线观看 | 日韩av网站在线免费观看| 成人一二三区| 欧美在线不卡| 国产亚洲在线观看| 欧美一级鲁丝片| 国产精品伦一区二区| 人人爽香蕉精品| 久久久久久黄| 久久亚洲精品中文字幕| 97久久超碰| 日韩精品一级中文字幕精品视频免费观看 | 狠狠躁少妇一区二区三区| 日本亚洲最大的色成网站www | 国产一区一一区高清不卡| 日精品一区二区三区| 尹人成人综合网| 成人羞羞视频播放网站| 精品视频高潮| 免费精品一区| 国产伦精品一区二区三区在线播放| 欧美高清一区| 日本精品不卡| 亚洲精品88| 精品国产免费人成网站| 精品一区二区三区亚洲| 国产精品天天看天天狠| 亚洲精品四区| 久久成人精品| 日韩一级欧洲| 欧美日韩国产免费观看| 丝袜av一区| 日韩欧美二区| 涩涩av在线| 群体交乱之放荡娇妻一区二区| 国产成人精品福利| 精品视频在线你懂得| 精品国产一区二区三区av片| 国产探花一区二区| 国产欧美高清| 国产欧美日韩在线观看视频| 欧美日本三区| 国产精品伊人| 国产毛片久久久| 欧美xxxx性| 久久精品国产福利| 欧美好骚综合网| 吉吉日韩欧美| 天堂日韩电影| jiujiure精品视频播放| 亚洲手机视频| 在线亚洲观看| 蜜桃av一区二区在线观看| 亚洲1区在线| 欧美精品中文字幕亚洲专区| 麻豆成人在线观看| 超碰在线99| 亚洲国产影院| 亚洲在线国产日韩欧美| 亚洲精品大片| 国产乱子精品一区二区在线观看 | 麻豆91在线播放| 成人影视亚洲图片在线| 久久久精品午夜少妇| 久久视频国产| 蜜臀久久99精品久久久久宅男| 91亚洲无吗| 你懂的国产精品| 欧美日韩精品免费观看视欧美高清免费大片 | 久久精品国内一区二区三区水蜜桃| 亚洲精品.com| 久久亚洲精品伦理| 日韩成人午夜精品| 国产精品黄色| 韩国精品主播一区二区在线观看| 国产二区精品| 日本精品另类| 91视频久久| 国产精品嫩草99av在线| 日韩黄色av| av资源亚洲| 亚洲另类av| 久久女人天堂| 亚洲一区不卡| 欧美精品1区| 麻豆精品蜜桃| 91av一区| 久久久久久久久久久妇女| 亚洲一区二区免费看| 国产日韩一区二区三区在线播放| jizzjizz中国精品麻豆| 视频一区二区三区在线| 你懂的国产精品| 99视频精品免费观看| 国产精品任我爽爆在线播放| 日韩成人亚洲| 国产伦精品一区二区三区在线播放 | 国产激情精品一区二区三区| 久久亚洲精品中文字幕蜜潮电影| 亚洲精品福利| 岛国av在线网站| 亚洲精品在线a| 久久夜夜操妹子| 日本亚洲欧美天堂免费| 久久三级福利| 国产丝袜一区| 美女被久久久| 日韩免费小视频| 欧美亚洲网站| 亚洲尤物在线| av一区在线| 欧美国产日本| 免费在线成人网| 亚洲精品一级二级| 欧美国产另类| 蜜臀91精品一区二区三区| 精品捆绑调教一区二区三区| 国产探花在线精品| 视频一区中文字幕| 久久久久久美女精品| 国产精品tv| 美女日韩在线中文字幕| 超碰在线99| 国产精品日韩精品中文字幕| 一级欧美视频| 亚洲激情黄色| 欧美日韩一区二区三区视频播放| 国产精品久久久久9999高清| 亚洲一区av| 亚洲欧洲另类| 日韩一区二区三区免费播放| 国产精品久久久亚洲一区| 中文不卡在线| 亚洲免费一区二区| 久久中文视频| 中文在线а√在线8| 国产精品99久久免费| 日本高清久久| 亚洲最新av| 水蜜桃久久夜色精品一区的特点| 激情91久久| 亚洲免费精品| 狠狠色狠狠色综合日日tαg| 婷婷激情久久| 久久天堂av| 国产精品麻豆久久| 首页国产精品| 亚洲三级欧美| 国产日韩电影| 日韩大片在线观看| 精精国产xxxx视频在线野外| 日韩精品免费一区二区三区|