Rumah >php教程 >php手册 >thinkphp webservice简单实现

thinkphp webservice简单实现

WBOY
WBOYasal
2016-06-07 11:41:391730semak imbas

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元

Kenyataan:
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn