重新封装zend_soap实现http连接安全认证的php代码

Eliza ·
更新时间:2024-09-21
· 725 次阅读

代码如下:
<?php
class MyFramework_Soap_server extends Zend_Soap_Server {
protected $_login = '';
protected $_password = '';
public function __construct($wsdl = null, array $options = null) {
parent::__construct($wsdl,$options);
if(isset($options['login'])){
$this->_login=$options['login'];
$this->_password=$options['password'];
$this->_authenticate();
}
}
private function _authenticate(){
$this->setAuthenticate($this->_login,$this->_password);
}
public function setHttpLogin($login){
$this->_login=$login;
}
public function setHttpPassword($password){
$this->_password=$password;
if(isset($this->_login)){
$this->_authenticate();
}
}
public function setAuthenticate($login,$password){
if ($_SERVER['PHP_AUTH_USER']!=$login || $_SERVER['PHP_AUTH_PW']!=$password) {
header('WWW-Authenticate: Basic realm="MyFramework Realm"');
header('HTTP/1.0 401 Unauthorized');
echo "You must enter a valid login ID and password to access this resource.\n";
exit;
}
}
}
?>

代码如下:
<?php
class Soap_server_test {
public $view = '';
public $params = '';
public $requestObj = '';
public $dbObj = '';
function __construct() {
$this->view = $GLOBALS['view'];
$this->params = $GLOBALS['params'];
$this->requestObj = $GLOBALS['requestObj'];
$this->dbObj = $GLOBALS['dbObj'];
}
function indexAction(){
if(isset($_GET['wsdl'])) {
$autodiscover = new MyFramework_Soap_AutoDiscover();
$autodiscover->setClass('Model_Service_SoapClassSetTest');
$autodiscover->handle();
exit;
} else {
//$options= array('encoding' => 'UTF-8','login'=>'tangjian','password'=>'123456');
$options= array('encoding' => 'UTF-8');
$soap = new MyFramework_Soap_Server("http://tj.MyFramework.com/default/soap_server_test/index?wsdl",$options);
$soap->setHttpLogin('tangjian');
$soap->setHttpPassword('123456');
$soap->setClass('Model_Service_SoapClassSetTest');
$soap->handle();
exit;
}
}
function clientAction() {
//$options= array('encoding' => 'UTF-8','login'=>'tangjian','password'=>'123456',
// 'compression' =>SOAP_COMPRESSION_GZIP);
$options= array('encoding' => 'UTF-8',
'compression' =>SOAP_COMPRESSION_GZIP);
$client = new MyFramework_Soap_Client('http://tj.MyFramework.com/default/soap_server_test/index?wsdl',$options);
$client->setHttpLogin('tangjian');
$client->setHttpPassword('123456');
$result=$client->getPass('tang',"man");
print_r($result);
}
}
?>
您可能感兴趣的文章:PHP中soap的用法实例PHP使用SOAP扩展实现WebService的方法PHP使用SOAP调用.net的WebService数据PHP使用NuSOAP调用Web服务的方法PHP实现Soap通讯的方法PHP XML error parsing SOAP payload on line 1PHP Class SoapClient not found解决方法php实现通过soap调用.Net的WebService asmx文件THINKPHP3.2使用soap连接webservice的解决方法php中curl和soap方式请求服务超时问题的解决PHP使用SOAP调用API操作示例PHP中soap用法示例【SoapServer服务端与SoapClient客户端编写】



php代码 HTTP zend SOAP PHP

需要 登录 后方可回复, 如果你还没有账号请 注册新账号