我知道了。
这是基于 phpxmlrpc 库的完整、最简单的 XML-RPC 服务器。
<?php
// Complete, simplest possible XMLRPC Server implementation
// file: domain.com/xmlrpc.php
include "lib/xmlrpc.inc"; // from http://phpxmlrpc.sourceforge.net/
include "lib/xmlrpcs.inc"; // from http://phpxmlrpc.sourceforge.net/
// function that handles example.add XML-RPC method
// (function "mapping" is defined in `new xmlrpc_server` constructor parameter.
function add ($xmlrpcmsg)
{
$a = $xmlrpcmsg->getParam(0)->scalarval(); // first parameter becomes variable $a
$b = $xmlrpcmsg->getParam(1)->scalarval(); // second parameter becomes variable $b
$result = $a+$b; // calculating result
$xmlrpcretval = new xmlrpcval($result, "int"); // creating value object
$xmlrpcresponse = new xmlrpcresp($xmlrpcretval); // creating response object
return $xmlrpcresponse; // returning response
}
// creating XML-RPC server object that handles 1 method
$s = new xmlrpc_server(
array(
"example.add" => array( // xml-rpc function/method name
"function" => "add", // php function name to use when "example.add" is called
"signature" => array(array($xmlrpcInt, $xmlrpcInt, $xmlrpcInt)), // signature with defined IN and OUT parameter types
"docstring" => 'Returns a+b.' // description of method
)
)
);
?>
我不完全了解scalarval()
方法对参数的作用,我认为它只是将对象转换为常规变量/值,并且可以与字符串一起使用。