PHP群:95885625 Hbuilder+MUI群:81989597 站长QQ:634381967
    您现在的位置: 首页 > 开发编程 > ThinkPhp教程 > 正文

    thinkphp webservice简单实现

    作者:w634381967来源:网络浏览:时间:2020-09-30 00:07:50我要评论
    导读:thinkphp webservice简单实现<?phpclass Api {private $key=null;public function __construct() {}//设置keypublic function set...
    thinkphp webservice简单实现
    <?php
    class Api {
    private $key=null;
    public function __construct() {

    }

    //设置key
    public function setkey($key){
    $this->key = $key;
    return "";
    }

    //验证key
    private function check_key(){
    if($this->key=='xxx'){
    return true;
    }
    return false;
    }

    public function getInfo($lastupdt){
    return "1231";
    }


    }
    class WbsAction extends Action {
    protected function _initialize(){
    $this->url = "http://localhost/xx/";
    import("SoapDiscovery");
    }

    public function index() {
    if (IS_POST) {
    $servidorSoap = new SoapServer($this->url."?wsdl");
    $servidorSoap->setClass('Api');
    $servidorSoap->handle();
    }else{
    $disco = new SoapDiscovery('Api','MyApi');
    header("Content-type: text/xml");
    if (isset($_SERVER['QUERY_STRING']) && strcasecmp($_SERVER['QUERY_STRING'],'wsdl')==0) {
    echo $disco->getWSDL();
    }
    else {
    echo $disco->getDiscovery();
    }
    }

    }

    public function test(){
    $time = I("t");
    $client = new SoapClient($this->url."?wsdl");
    $client->setkey('xxxx');
    //$client = new Api();
    try {
    //$result = $client->select('ieliwb');
    $result = $client->getInfo("$time");
    var_dump($result);
    }
    catch (SoapFault $f){
    echo "Error Message: {$f->getMessage()}";
    }
    }
    }


    SoapDiscovery.class.zip
    转载请注明(B5教程网)原文链接:https://b5.mxunkeji.com/content-83-1021-1.html
    相关热词搜索: