菜单

php soap验证

2012年09月12日 - php

soapheader…
Server:

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();

Client:

 1));

	$authvalues = new SoapVar(array('authcode' => '123456789',), SOAP_ENC_OBJECT);

	$header = new SoapHeader('urn:Server', 'auth', $authvalues, false, SOAP_ACTOR_NEXT);

	$client->__setSoapHeaders(array($header));
	$data = $client->getData();

	var_dump($data);
} catch (SoapFault $e) {
	echo $e->faultstring;
}

发表评论

电子邮件地址不会被公开。 必填项已用*标注