Home> php教程> php手册> body text

thinkphp webservice简单实现

WBOY
Release: 2016-06-07 11:41:39
Original
1640 people have browsed it

thinkphp webservice简单实现
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");
ini_set('soap.wsdl_cache_enabled', "0");//注意该选项 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 下载:423 次 )

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
    Latest Downloads
    More>
    Web Effects
    Website Source Code
    Website Materials
    Front End Template
    About us Disclaimer Sitemap
    php.cn:Public welfare online PHP training,Help PHP learners grow quickly!