Server端
<?php
class Server {
private $authenticated = false;
public function auth($authcode) {
if($authcode === "123456789") {
$this->authenticated = true;
return true;
} else {
throw new SoapFault("403", "403 Forbidden");
}
}
public function getData() {
if(!$this->authenticated) {
throw new SoapFault("403", "403 Forbidden");
}
$data = array(
"text" => "ni mei a"
);
return json_encode($data);
}
}
/*//生成wsdl文件
include("SoapDiscovery.class.php");
$disco = new SoapDiscovery("Server","Server");
$handle = fopen("server.wsdl", "w+");
fwrite($handle, $disco->getWSDL());
fclose($handle);
*/
$objSoapServer = new SoapServer("server.wsdl");
// $objSoapServer->setClass("Server");
$serv = new Server;
$objSoapServer->setObject($serv);
$objSoapServer->handle();<?php
class Server {
priva