一、客户端
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();
/**
* 图片上传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();