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元