本文整理汇总了PHP中xmlrpc_decode函数的典型用法代码示例。如果您正苦于以下问题:PHP xmlrpc_decode函数的具体用法?PHP xmlrpc_decode怎么用?PHP xmlrpc_decode使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了xmlrpc_decode函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: query
public function query($method, $parameters = null)
{
$request = xmlrpc_encode_request($method, $parameters);
$headers = array("Content-type: text/xml", "Content-length: " . strlen($request));
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $this->url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, $request);
if ($this->timeout) {
curl_setopt($curl, CURLOPT_TIMEOUT, $this->timeout);
}
$rawResponse = curl_exec($curl);
$curlErrno = curl_errno($curl);
$curlError = curl_error($curl);
curl_close($curl);
if ($curlErrno) {
throw new NetworkException($curlError, $curlErrno);
}
$result = xmlrpc_decode($rawResponse);
if (xmlrpc_is_fault($result)) {
throw new NetworkException($result['faultString'], $result['faultCode']);
}
return $result;
}
示例2: callRemote
function callRemote($method)
{
// Curl is required so generate a fault if curl functions cannot be found.
if (!$this->curl) {
return array('faultCode' => -1, 'faultString' => 'Curl functions are unavailable.');
}
// The first argument will always be the method name while all remaining arguments need
// to be passed along with the call.
$args = func_get_args();
array_shift($args);
if ($this->xmlrpc) {
// If php has xmlrpc support use the built in functions.
$request = xmlrpc_encode_request($method, $args);
$result = $this->__xmlrpc_call($request);
$decodedResult = xmlrpc_decode($result);
} else {
// If no xmlrpc support is found, use the phpxmlrpc library. This involves containing
// all variables inside the xmlrpcval class.
$encapArgs = array();
foreach ($args as $arg) {
$encapArgs[] = $this->__phpxmlrpc_encapsulate($arg);
}
$msg = new xmlrpcmsg($method, $encapArgs);
$client = new xmlrpc_client($this->url);
$client->verifypeer = false;
$result = $client->send($msg);
if ($result->errno) {
$decodedResult = array('faultCode' => $result->errno, 'faultString' => $result->errstr);
} else {
$decodedResult = php_xmlrpc_decode($result->value());
}
}
return $decodedResult;
}
示例3: xmlrpc_decode
function xmlrpc_decode($xmlrpc_val)
{
$kind = $xmlrpc_val->kindOf();
if ($kind == "scalar") {
return $xmlrpc_val->scalarval();
} else {
if ($kind == "array") {
$size = $xmlrpc_val->arraysize();
$arr = array();
for ($i = 0; $i < $size; $i++) {
$arr[] = xmlrpc_decode($xmlrpc_val->arraymem($i));
}
return $arr;
} else {
if ($kind == "struct") {
$xmlrpc_val->structreset();
$arr = array();
while (list($key, $value) = $xmlrpc_val->structeach()) {
$arr[$key] = xmlrpc_decode($value);
}
return $arr;
}
}
}
}
示例4: rpc_send
/**
* send xml data to OpenNebula RPC server
* @param $method
* @param $argument
*/
function rpc_send($method, $argument)
{
//Using the XML-RPC extension to format the XML package
$request = xmlrpc_encode_request($method, $argument);
$req = curl_init($this->service_url);
//Using the cURL extension to send it off, first creating a custom header block
$headers = array();
array_push($headers, "Content-Type: text/xml");
array_push($headers, "Content-Length: " . strlen($request));
array_push($headers, "\r\n");
//URL to post to
curl_setopt($req, CURLOPT_URL, $this->service_url);
//Setting options for a secure SSL based xmlrpc server
curl_setopt($req, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($req, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($req, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($req, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($req, CURLOPT_HTTPHEADER, $headers);
curl_setopt($req, CURLOPT_POSTFIELDS, $request);
//Finally run
$response = curl_exec($req);
//Close the cURL connection
curl_close($req);
//Decoding the response to be displayed
$result = xmlrpc_decode($response);
return $result;
}
示例5: getcomments
function getcomments($m)
{
$err = '';
$ra = array();
// get the first param
$msgID = xmlrpc_decode($m->getParam(0));
$countID = "{$msgID}_count";
$sql = 'SELECT * FROM phpgw_discuss WHERE msg_id=' . $msgID;
$GLOBALS['phpgw']->db->query($sql, __LINE__, __FILE__);
$count = $GLOBALS['phpgw']->db->num_rows();
while ($data = $GLOBALS['phpgw']->db->next_record()) {
$name = $GLOBALS['phpgw']->db->f('name');
$comment = $GLOBALS['phpgw']->db->f('comment');
// push a new struct onto the return array
$ra[] = CreateObject('phpgwapi.xmlrpcval', array('name' => CreateObject('phpgwapi.xmlrpcval', $name), 'comment' => CreateObject('phpgwapi.xmlrpcval', $comment)), 'struct');
}
// if we generated an error, create an error return response
if ($err) {
return CreateObject('phpgwapi.xmlrpcresp', '', $GLOBALS['xmlrpcerruser'], $err);
} else {
// otherwise, we create the right response
// with the state name
return CreateObject('phpgwapi.xmlrpcresp', CreateObject('phpgwapi.xmlrpcval', $ra, 'array'));
}
}
示例6: ping
/**
* Ping Blog Update Services
*
* @param array $options are name, website, url
*/
function ping($options = array())
{
$type = 'REST';
if (function_exists('xmlrpc_encode_request')) {
$type = 'XML-RPC';
}
switch ($type) {
case 'REST':
// construct parameters
$params = array('name' => $options['name'], 'url' => $options['url']);
$params = array_map('rawurlencode', $params);
$paramString = http_build_query($params);
// Rest Update Ping Services
foreach ($this->__services['rest'] as $serviceApi) {
$requestUrl = $serviceApi . '?' . $paramString;
$response = file_get_contents($requestUrl);
}
break;
case 'XML-RPC':
// construct parameters
$params = array($options['name'], $options['website'], $options['url'], $options['feed']);
$request = xmlrpc_encode_request("weblogUpdates.extendedPing", $params);
$context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request)));
foreach ($this->__services['rpc'] as $endPoint) {
// Ping the services
$file = file_get_contents($endPoint, false, $context);
$response = xmlrpc_decode($file);
//no need to process the response
}
break;
}
}
示例7: getcomments
function getcomments($m)
{
global $xmlrpcerruser;
$err = "";
$ra = array();
// get the first param
if (XMLRPC_EPI_ENABLED == '1') {
$msgID = xmlrpc_decode($m->getParam(0));
} else {
$msgID = php_xmlrpc_decode($m->getParam(0));
}
$dbh = dba_open("/tmp/comments.db", "r", "db2");
if ($dbh) {
$countID = "{$msgID}_count";
if (dba_exists($countID, $dbh)) {
$count = dba_fetch($countID, $dbh);
for ($i = 0; $i < $count; $i++) {
$name = dba_fetch("{$msgID}_name_{$i}", $dbh);
$comment = dba_fetch("{$msgID}_comment_{$i}", $dbh);
// push a new struct onto the return array
$ra[] = array("name" => $name, "comment" => $comment);
}
}
}
// if we generated an error, create an error return response
if ($err) {
return new xmlrpcresp(0, $xmlrpcerruser, $err);
} else {
// otherwise, we create the right response
// with the state name
return new xmlrpcresp(php_xmlrpc_encode($ra));
}
}
示例8: _request
private function _request($request)
{
$context = stream_context_create(array('http' => array('method' => 'POST', 'header' => 'Content-Type: text/xml', 'content' => $request)));
$response = file_get_contents('https://api.loopia.se/RPCSERV', false, $context);
$response = xmlrpc_decode($response);
return $response;
}
示例9: parse
/**
* {@inheritdoc}
*/
public function parse($xmlString, &$isFault)
{
$result = xmlrpc_decode($xmlString, 'UTF-8');
$isFault = false;
$toBeVisited = [&$result];
while (isset($toBeVisited[0]) && ($value =& $toBeVisited[0])) {
$type = gettype($value);
if ($type === 'object') {
$xmlRpcType = $value->{'xmlrpc_type'};
if ($xmlRpcType === 'datetime') {
$value = DateTime::createFromFormat('Ymd\\TH:i:s', $value->scalar, isset($timezone) ? $timezone : ($timezone = new DateTimeZone('UTC')));
} elseif ($xmlRpcType === 'base64') {
if ($value->scalar !== '') {
$value = Base64::serialize($value->scalar);
} else {
$value = null;
}
}
} elseif ($type === 'array') {
foreach ($value as &$element) {
$toBeVisited[] =& $element;
}
}
array_shift($toBeVisited);
}
if (is_array($result)) {
reset($result);
$isFault = xmlrpc_is_fault($result);
}
return $result;
}
示例10: onStartNoticeSave
function onStartNoticeSave($notice)
{
$args = $this->testArgs($notice);
common_debug("Blogspamnet args = " . print_r($args, TRUE));
$request = xmlrpc_encode_request('testComment', array($args));
$context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml\r\n" . "User-Agent: " . $this->userAgent(), 'content' => $request)));
$file = file_get_contents($this->baseUrl, false, $context);
$response = xmlrpc_decode($file);
if (xmlrpc_is_fault($response)) {
throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
} else {
common_debug("Blogspamnet results = " . $response);
if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
} else {
if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
} else {
if (preg_match('/^OK$/', $response)) {
// don't do anything
} else {
throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
}
}
}
}
return true;
}
示例11: xmlrpcCall
function xmlrpcCall($url, $method, $params)
{
// xmlrpc encode parameters
for ($i = 0; $i < count($params); $i++) {
if (get_class($params[$i]) != 'xmlrpcval') {
$params[$i] = xmlrpc_encode($params[$i]);
}
}
// send request
$message = new xmlrpcmsg($method, $params);
debug("XML-RPC message", $message->serialize());
$addr = parse_url($url);
$client = new xmlrpc_client($url, $addr['host'], $addr['port']);
//if($debug)
// $client->setDebug(1);
debug("XML-RPC", "call to " . $url);
$response = $client->send($message);
// process response
debug("XML-RPC Response", $response->serialize());
if (!$response) {
debug("No response", "probably host is unreachable");
} elseif ($response->faultCode() != 0) {
// there was an error
debug("Error response: ", $response->faultCode() . " " . $response->faultString());
} else {
$retval = $response->value();
if ($retval) {
$retval = xmlrpc_decode($retval);
}
debug("Response", $retval);
return $retval;
}
return NULL;
}
示例12: onStartNoticeSave
function onStartNoticeSave($notice)
{
$args = $this->testArgs($notice);
common_debug("Blogspamnet args = " . print_r($args, TRUE));
$requestBody = xmlrpc_encode_request('testComment', array($args));
$request = new HTTPClient($this->baseUrl, HTTPClient::METHOD_POST);
$request->setHeader('Content-Type', 'text/xml');
$request->setBody($requestBody);
$httpResponse = $request->send();
$response = xmlrpc_decode($httpResponse->getBody());
if (xmlrpc_is_fault($response)) {
throw new ServerException("{$response['faultString']} ({$response['faultCode']})", 500);
} else {
common_debug("Blogspamnet results = " . $response);
if (preg_match('/^ERROR(:(.*))?$/', $response, $match)) {
throw new ServerException(sprintf(_("Error from %s: %s"), $this->baseUrl, $match[2]), 500);
} else {
if (preg_match('/^SPAM(:(.*))?$/', $response, $match)) {
throw new ClientException(sprintf(_("Spam checker results: %s"), $match[2]), 400);
} else {
if (preg_match('/^OK$/', $response)) {
// don't do anything
} else {
throw new ServerException(sprintf(_("Unexpected response from %s: %s"), $this->baseUrl, $response), 500);
}
}
}
}
return true;
}
示例13: get_response
public static function get_response($server, $request, &$error = null, $fresh = false)
{
$ch = vpl_jailserver_manager::get_curl($server, $request, $fresh);
$raw_response = curl_exec($ch);
if ($raw_response === false) {
$error = 'request failed: ' . s(curl_error($ch));
curl_close($ch);
return false;
} else {
curl_close($ch);
$error = '';
$response = xmlrpc_decode($raw_response, "UTF-8");
if (is_array($response)) {
if (xmlrpc_is_fault($response)) {
$error = 'xmlrpc is fault: ' . s($response["faultString"]);
} else {
return $response;
}
} else {
$error = 'http error ' . s(strip_tags($raw_response));
$fail = true;
}
return false;
}
}
示例14: sendRequest
private function sendRequest($request)
{
$context = stream_context_create(array('http' => array('method' => "POST", 'header' => "Content-Type: text/xml", 'content' => $request, 'timeout' => $this->timeout)));
$status = @file_get_contents("http://" . $this->host . ":" . $this->port . "/RPC2", false, $context);
$retval = xmlrpc_decode($status);
return $retval;
}
示例15: send
/**
* Sends an XML RPC request to the XML RPC server
* @param $methodName string Name of the XML RPC method to call
* @param $params array Array of parameters to pass to the XML RPC method. Type is detected automatically. For a struct just encode an array within $params.
* @return array Array of returned parameters
*/
public function send($methodName, $params)
{
$request = xmlrpc_encode_request($methodName, $params);
$response = $this->sendRequest($request);
$response = xmlrpc_decode(trim($response));
//Without the trim function returns null
return $response;
}