zend_soap 实现 web service 用户验证

关于zend_soap如何来进行web service就不多说了

详见http://www.cnblogs.com/zcy_soft/archive/2011/01/10/1932177.html

参考代码:http://download.csdn.net/source/2967369

这个帖子重点讲讲如何用 zend_soap 框架来进行用户验证

必要前提懂的参考代码中的内容

原理:客户端访问服务器,首先发出soapheader信息,先进行验证,如果soapheader中的内容是正确的,

   那么将会改变服务器端改成已经授权,否则就跑出错误

考代代码

客户端SoapController.php  访问地址:http://test.localhost:8080/soap/client

注意:发送的SoapHeader里面,

 "userConfirmation"   :接受soapheader并处理的方法

array("test","888888") :给处理soapheader方法的两个参数

代码
复制代码
    
    
$client = new Zend_Soap_Client( " http://tools.localhost:8080/soapserver/index?wsdl " );
$soapUri = $this -> _WSDL_URI;
$client -> addSoapInputHeader(
new SoapHeader(
$soapUri ,
" userConfirmation " ,
array ( " test " , " 888888 " )
)
);
$xmlConente = file_get_contents ( ' C:\TestPhp\public\t3.xml ' );
echo $client -> SyncCrawlerCV( $xmlConente ); die ;
复制代码

服务器端 SoapserverController.php   wsdl访问地址:http://tools.localhost:8080/soapserver/index?wsdl

注意:

代码
复制代码
    
    
private function handleWSDL() {
$autodiscover = new Zend_Soap_AutoDiscover();
// 类名要注意一致
$autodiscover -> setClass( ' Dhr_SoapService ' );
$autodiscover -> handle();
}

private function handleSOAP() {
$soap = new Zend_Soap_Server( ' http://tools.localhost:8080/soapserver/index?wsdl ' );
$soap -> setClass( ' Dhr_SoapService ' );
$soap -> handle();
}

public function indexAction() {
// 判断请求中是否有wsdl有就自动生成wsdl的uri否则启动soap服务
if ( isset ( $_GET [ ' wsdl ' ])) {
$this -> handleWSDL();
}
else {
$this -> handleSOAP();
}
}
复制代码

服务器端关键代码

代码
复制代码
    
    
class Dhr_SoapService {
public $authorized = false ;
// other param

/* *
* a main function can be sync crawler cv
* @param string $XMLString
* @return string
*/
public function SyncCrawlerCV( $XMLString ) {
$this -> xmlMessageObj = new xmlMessage();
if ( ! $this -> authorized){
$this -> xmlMessageObj -> createSon( ' exceptions ' , ' No login! ' );
return $this -> xmlMessageObj -> getXML();
}
// do something
}
/* *
* method for user comfirmaation
* @param string $userInfo
*/
public function userConfirmation( $userName , $passWord ){
if ( $userName == ' test ' && $passWord == ' 888888 ' ){
$this -> authorized = true ;
}
}
// other function s
}
复制代码
分类:  PhpZEND FRAMEWORK(ZF)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值