首頁  >  文章  >  php教程  >  thinkphp webservice简单实现

thinkphp webservice简单实现

WBOY
WBOY原創
2016-06-07 11:41:391698瀏覽

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元

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn