zoukankan      html  css  js  c++  java
  • php的webservice的soapheader认证问题

    参数通过类传输:
    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次没有参数的错误,其实还可以通过获取所有输入参数分析得到。

  • 相关阅读:
    AcWing 243. 一个简单的整数问题2 (树状数组)打卡
    AcWing 241. 楼兰图腾 (树状数组)打卡
    AcWing 233. 换教室 (期望DP+floyd)打卡
    AcWing 234. 放弃测试 (01分数规划)打卡
    AcWing 232. 守卫者的挑战 (期望DP)打卡
    AcWing 231. 天码 (容斥)打卡
    AcWing 230. 排列计数 水题(组合数+错排)打卡
    AcWing 229. 新NIM游戏 (线性基+博弈论)打卡
    AcWing 228. 异或 (dfs+线性基)打卡
    pstStream->pstPack[i].pu8Addr详解
  • 原文地址:https://www.cnblogs.com/kudosharry/p/3262121.html
Copyright © 2011-2022 走看看