如何显示PHP XML-RPC调用的返回值?

问题描述 投票:-2回答:1

我似乎找不到任何代码来显示调用的返回值。

我在下面的链接中运行软件供应商提供的xml-lib。

https:/support.sippysoft.comsupportsolutionsarticles3000013653-xml-rpc-api-sign-up-html-page-fresh-version-。

<?php

include 'xmlrpc/xmlrpc.inc';


function listAccounts()
{
   //$params = array(new xmlrpcval(array("i_account"=> new xmlrpcval('14719', "string")), 'struct'));

    $msg = new xmlrpcmsg('listAccounts');

    /* replace here URL  and credentials to access to the API */
    $cli = new xmlrpc_client('https://DOMAINHERE/xmlapi/xmlapi');
    $cli->setSSLVerifyPeer(false);
    $cli->setSSLVerifyHost(false);
    $cli->setCredentials('USERNAME', 'PASSWORD', CURLAUTH_DIGEST);

    $r = $cli->send($msg, 20);
    if ($r->faultCode()) {
      error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
      print_r ($r->faultString());
      return false;
    }
    else
    {
    return $r->value();

    // I need something here to write returned values to normal PHP variable

    }
}

php xml-rpc
1个回答
0
投票

好的,谢谢halfer的评论。

我成功地解决了这个问题,并在库中的代码中找到了一个函数来解决这个问题。

非常感谢你的指点,它真的帮了大忙。

我是新的php和xml和学习曲线是相当高的,但感谢。

为别人参考也许在未来这里是纠正的代码与最后2行,为我做的神奇。

<?php
include 'xmlrpc/xmlrpc.inc';


        // $params = array(new xmlrpcval(array("offset"=> new xmlrpcval("1", "int")
        //                                ,"i_customer"=> new xmlrpcval("321", "int")
        //                                 ), 'struct'));

       $params = array(new xmlrpcval(array("i_customer"=> new xmlrpcval("321", "int")

                                           ), 'struct'));

       $msg = new xmlrpcmsg('listAccounts', $params);

       /* replace here URL  and credentials to access to the API */
       $cli = new xmlrpc_client('DOMAIN');
       $cli->setSSLVerifyPeer(false);
       $cli->setdebug(0);
       $r = $cli->send($msg, 20);       /* 20 seconds timeout */

       if ($r->faultCode()) {
         error_log("Fault. Code: " . $r->faultCode() . ", Reason: " . $r->faultString());
         echo $r->faultString();
       }

       // now lets decode the xml response..
        $values=php_xmlrpc_decode($r->value());
        var_dump ($values['accounts'][0][username]);

?>
© www.soinside.com 2019 - 2024. All rights reserved.