Simple implementation of thinkphpwebservice

Source: Internet
Author: User
Provides various official and user-released code examples. For more information, see thinkphp webservice.
Class Api {
Private $ key = null;
Public function _ construct (){

}

// Set the key
Public function setkey ($ key ){
$ This-> key = $ key;
Return "";
}

// Verify the 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 ");
Ini_set ('soap. wsdl_cache_enabled ', "0"); // note that this option is cached in soap.
$ 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 (2.19 KB download: 423 times)

AD: truly free, domain name + VM + enterprise mailbox = 0 RMB

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.