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次没有参数的错误,其实还可以通过获取所有输入参数分析得到。
最新文章
- Zabbix监控nginx-rtmp status(html版)
- 1.AutoMapper核心:扁平化
- iOS开发之UIAlertView与UIAlertController的详尽用法说明
- OkHttp:Java 平台上的新一代 HTTP 客户端
- SQL基本CRUD
- 第七课第六节,T语言流程语句( 版本5.0)
- Matlab之矩阵
- WCF 无法生成 client
- Spring MVC之@RequestMapping 详解(转)
- C++程序设计实践指导1.5求两个整数集合并集改写要求实现
- 异步队列 Deferred
- 欢迎来到Devil_lixu的技术博客
- Yii2中限制访问某控制器的IP(IP白名单)
- asp net core 跨平台初体验
- Flask從入門到入土(三)——模板
- Linux显示登录Shell信息
- POJ2947-Widget Factory
- MongoDB 查询 $关键词 方法目录
- Python学习第一章
- NO.8:绝不在构造或者析构过程中调用virtual函数
热门文章
- HDU 1978 How many ways(动态规划)
- hdu 4618(最大回文子矩阵)
- C Primer Plus之指针
- jmeter中线程之间传递参数
- Linux:chmod -R 777 * 是什么意思?
- 创建DB2数据库时报错--SQL1052N 数据库路径不存在(Windows)(转载)
- Android核心分析 之二方法论探讨之概念空间篇
- SQL Server ->;>; GROUPING SETS, CUBE, ROLLUP, GROUPING, GROUPING_ID
- 脉络清晰的BP神经网络讲解,赞
- asp.net MVC3 “System.Web.Mvc.ModelClientValidationRule”问题