zoukankan      html  css  js  c++  java
  • 用Zend_xmlrpc构建webservice服务器

    网站需要开通接口供别人调用,用Zend Framework中的Zend_xmlrpc_server来构建一个server端。

    如下:server端

    <?php
    require_once 'Zend/XmlRpc/Server.php';
    /**
     * 返回 json 值
     *
     * @param mixed $value (注意:这是server端中函数的一个形参,必须要在这里体现,传过来是数组,是array,如果是字符串,则是string) 
     * @return  json 
     */
    function jencodeValue($value)
    {
        return json_encode($value);
    }
     
    $server = new Zend_XmlRpc_Server();
    $server->addFunction('jencodeValue');//这里是用addFunction附加一个函数 
    echo $server->handle();//返回一个对象
    ?>

    client端 (进行XMLRPC调用)

    include('Zend/Loader.php');
    Zend_Loader::registerAutoload();
    $client = new Zend_XmlRpc_Client('http://127.0.0.1/test/xmlrpc/index.php');
    $data=array(    //说明:如果传过去的参数是数组,则必须如下要包三层,一个三维数组.
     
                       array(
     
                               array(
                                         "a"=>"Hello World !",
                                         "b"=>"Hello CodeMonkey !"
                                       )
     
                               )
     
                        );
    $result=$client->call('jencodeValue',$data);
    print_r($result);

    结果(json数据):

    [{"a":"Hello World !","b":"Hello CodeMonkey !"}]

  • 相关阅读:
    汇编-实验9
    Starling开源手势库AcheGesture
    Robotlegs2的Starling扩展
    Flash Builder 4.6/4.7 注释以及字体大小修改
    js中函数的理解
    js对象引用赋值后
    var声明提前 undefined
    光棍节程序员闯关秀
    body和普通div背景图宽高百分比的区别
    笔试题
  • 原文地址:https://www.cnblogs.com/liuxgnu/p/3535427.html
Copyright © 2011-2022 走看看