php soap header请求验证

一、客户端
1、使用类进行HEAD验证

   /**
    * 图片上传SOAP_CLIENT
    *
    */
    function upimg_soap_client(){       
        try{
             //声明head验证类
            $soap_cls = new soap_head_cls('abc', '123');

           
            //声明SOAP客户端
            $client = new SoapClient(null, array('uri'=> 'http://abc.com', 'location' => 'http://abc.com/webserver/upimg_webserver.php', 'trace' => true));
           
            //声明SOAP变量,为对象模式           
            $soap_var = new SoapVar($soap_cls, SOAP_ENC_OBJECT, 'proving_user', 'http://abc.com');   
    
            $header = new SoapHeader('http://abc.com', 'proving_user', $soap_var, true);               
           
            //head请求,验证
            $client->__setSoapHeaders(array($header));

            //客户端请求
            $call_val = $client->__soapCall('upimg', array());
        } catch(SoapFault $e){
            //客户端异常
           
            echo $e->getMessage();
            exit;
        }
    }

    /**
    * soap_head类
    */
    class soap_head_cls{
        var $name;      //账户
        var $pwd;       //密码
        function __construct($name, $pwd){
            $this->name = $name;
            $this->pwd = $pwd;
        }
    }


2、使用数组进行HEAD验证
   /**
    * 图片上传SOAP_CLIENT
    *
    */
    function upimg_soap_client(){       
        try{                       
            //声明SOAP客户端
            $client = new SoapClient(null, array('uri'=> 'http://abc.com', 'location' => 'http://abc.com/webserver/upimg_webserver.php', 'trace' => true));
           
            //声明SOAP变量,为数组模式
             $soap_var = array('name' => 'abc', 'pwd' => 123);
            $header = new SoapHeader('http://abc.com', 'proving_user', $soap_var, true);               
           
            //head请求,验证
            $client->__setSoapHeaders(array($header));

            //客户端请求
            $call_val = $client->__soapCall('upimg', array());
        } catch(SoapFault $e){
            //客户端异常
           
            echo $e->getMessage();
            exit;
        }
    }

二、服务器端

    define('LOGIN_DOMAIN', 'abc.com');
    define('LOGIN_ACCOUNT', 'abc');
    define('LOGIN_PWD', '123');
   
   
    /**
    * 图片上传类
    */
    class img_upload{
       
        //是否登录状态
        private $is_login = false;
       
        //异常    1域错误    2账户错误       3密码错误       4账户不存在或不是数组       0登录成功
        private $exception;
   
        /**
        * 验证用户
        *
        * @param mixed $user    用户数组       
        */
        function proving_user($user){
            if(!$user || !is_array($user)){
                $this->exception = 4;
            }
           
            if(strtolower($user['domain']) != LOGIN_DOMAIN){
                $this->exception = 1;
                return;
            }
           
            if(strtolower($user['account']) != LOGIN_ACCOUNT){
                $this->exception = 2;
                return;
            }
           
            if($user['pwd'] != LOGIN_PWD){
                $this->exception = 3;
                return;
            }
           
            $this->exception = 0;
        }
       
        /**
        * 上传图片
        *
        * @param mixed $img_ary     图片数组
        */
        function upimg($img_ary){
            if($this->exception > 0){
                return $this->exception;
            }
        }
    }       
   
    $soap_server = new SoapServer(null, array('uri' => 'http://abc.com'));
    $soap_server->setClass('img_upload');   
    $soap_server->handle();
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值