利用nusoap生成wsdl文件

 

第一步,首先下载 nusoap.php  

下载地址  http://sourceforge.net/projects/nusoap/files/nusoap/

server.php  文件 

<?php   

    include_once "lib/nusoap.php"; //导入nusoap.php,本站放在lib目录下    
// Create the server instance 
$server = new soap_server(); 
// Initialize WSDL support 
$server->configureWSDL('registerwsdl', 'urn:registerwsdl'); 
// Register the method to expose 
$server->register('register',                // method name 
    array('username' => 'xsd:string','game_id' => 'xsd:int','fromurl' => 'xsd:string','advertiser' => 'xsd:string','adFrom' => 'xsd:string','adType' => 'xsd:string','pageName' => 'xsd:string','wordid' => 'xsd:string','ip' => 'xsd:string','registertime' => 'xsd:time'),        // input parameters 
    array('return' => 'xsd:array'),      // output parameters 
    'urn:registerwsdl',                      // namespace 
    'urn:registerwsdl#register',                // soapaction 
    'rpc',                                // style 
    'encoded',                            // use 
    'Says hello to the caller'            // documentation 
); 
// Define the method as a PHP function 

   function register($username, $game_id, $fromurl, $advertiser, $adFrom, $adType, $pageName, $wordid, $ip, $registertime) {
        $param = array(
            'tg_account' => $username,
            'tg_gameID' => $game_id,
            'tg_advertiser' => $advertiser,
            'tg_adFrom'=>$adFrom,
            'tg_pageParam' => $fromurl,
            'tg_adType' => $adType,
            'tg_pageName' => $pagename,
            'tg_adsID' => $wordid,
            'tg_ip' => $ip,
            'tg_registerTime' => $registertime
        );
        return $param;
}       
// Use the request to (try to) invoke the service 
$HTTP_RAW_POST_DATA = isset($HTTP_RAW_POST_DATA) ? $HTTP_RAW_POST_DATA : ''; 
$server->service($HTTP_RAW_POST_DATA); 

?> 

以上是生成wsdl的文件的方式,还有一种方法是说利用zend studio 7生成

第二步就是写php的服务端的接口

wsdl.php

<?php

class Wsdl extends CI_Controller {

    function __construct() {
        parent::__construct();
        $this->load->model('tganalysis/register_analysis_model');
    }

    function register($username, $gameid, $fromurl, $advertiser, $adfrom, $pagetype, $pagename, $tgid, $ip, $registertime) {
        //保存注册信息
        $this->register_analysis_model->tg_account = strtoupper($username);
        $this->register_analysis_model->tg_gameID = $gameid;
        $this->register_analysis_model->tg_fromurl = urldecode($fromurl);
        $this->register_analysis_model->tg_advertiser = $advertiser; //广告商投放id
        $this->register_analysis_model->tg_adFrom = $adfrom;
        $this->register_analysis_model->tg_pagetype = $pagetype;
        $this->register_analysis_model->tg_pagename = $pagename;
        $this->register_analysis_model->tg_tgid = $tgid;
        $this->register_analysis_model->tg_ip = $ip;
        $this->register_analysis_model->tg_registerTime = date('Y-m-d H:i:s', $registertime);
        try {
            $this->register_analysis_model->save_tg_register();
        } catch (SoapFault $e) {
            return $e->getMessage();
        }
        return 0;
    }

    function index() {
        ini_set("soap.wsdl_cache_enabled", "0");
        $server = new SoapServer(APPPATH . 'libraries/data/tgRegister.wsdl', array('uri' => "http://gwact.woniu.com/jwl/wsdl?wsdl", 'encoding' => 'utf-8'));
        $server->setClass("wsdl");
        $server->addFunction(array('register'));
        $server->addFunction(SOAP_FUNCTIONS_ALL);
        $server->handle();
    }

}
?>

最后说明以上经过实践证明可以使用,具体的根据自己的情况修改

你可能感兴趣的:(php的接口)