• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

php的webservice的soapheader认证问题

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

参数通过类传输:
class authentication_header {  
     private $username;  
     private $password;  
     public function __construct($username, $password) {  
         $this->username = $username;  
         $this->password = $password;  
     }  

服务端:
$wsdl_path = FCPATH.'wsdl/user.wsdl';
$s = new SoapServer($wsdl_path,array('actor' => 'user'));
$s -> setClass("user");
$s -> handle();

客户端:$wsdl_path = 'http://api.mypharma.com/wsdl/user.wsdl';
$authvalues = new authentication_header('liu','1234456');
$header = new SoapHeader('urn:Solsoft_user', 'Authentication', $authvalues, false, 'user');
$client = new SoapClient($wsdl_path,array('trace'=>1));
$client->__setSoapHeaders(array($header));
$a = $client->status(1);
红色是服务类的认证方法名称

服务类:
class user
{
    public $rootPath;
    public $Authenticated;
    public $username;
    public $password;
    function __construct()
    {
        $this->rootPath=dirname(__FILE__);
        require_once $this->rootPath.'/lib/db_class.php';
        require_once $this->rootPath.'/model/api_base_model.php';
    }

    public function Authentication($username,$password)
    {  
        $this->username =$username;
        $this->password =$password;
         if($this->username == 'liumeng' && $this->password == '123456'){
            $this->Authenticated = true;  
         } else {  
            $this->Authenticated = false;   
         }
    }
    
    public function status($id)
    {
        if($this->Authenticated){
            require_once $this->rootPath.'/model/member_model.php';
            $member_model =  new Member_Model();
            $a = $member_model->get_data_by_id($id);
            return json_encode($a);
        }else{
            return json_encode(array('error'=>'wrong username or password!'));
        }
    }
}
红色是传递参数的核心,我试了好长时间才正确,报了N次没有参数的错误,其实还可以通过获取所有输入参数分析得到。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP面试题之实现输出100以内的质数发布时间:2022-07-10
下一篇:
php多路复用(多线程)socket相关应用发布时间:2022-07-10
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap