YurunPHP內置Soap支持,可以搭配PHP的SoapServer類使用。
由于文字可能表述不清,大多數內容將以代碼形式展現。
#### 配置文件
添加自動加載
~~~
'AUTOLOAD_RULES' => array(
array('type'=>'Word','word'=>'SoapControl','path'=>'Ex/Lib/Soap'),
array('type'=>'Word','word'=>'SoapParser','path'=>'Ex/Lib/Soap'),
array('type'=>'Word','word'=>'SoapProxy','path'=>'Ex/Lib/Soap'),
array('type'=>'Word','word'=>'ClassToWsdl','path'=>'Ex/Lib/Soap/PHPWsdl'),
array('type'=>'Word','word'=>'WSDL','path'=>'Ex/Lib/Soap/PHPWsdl'),
),
~~~
#### 控制器
~~~
<?php
class ServiceControl extends SoapControl
{
/**
* 服務首頁動作名
*/
protected $index = 'index';
/**
* wsdl文檔動作名
*/
protected $wsdl = 'wsdl';
/**
* 服務接口執行動作名
*/
protected $exec = 'exec';
/**
* 服務接口測試頁面動作名
*/
protected $test = 'test';
/**
* wsdl中的Style
*/
protected $wsdlStyle = 'document';
/**
* wsdl中的use
*/
protected $wsdlUse = 'literal';
/**
* 是否啟用緩存
*/
protected $cacheStatus = true;
/**
* 友好展示頁面
* @param mixed $serviceName
* @return mixed
*/
public function index($serviceName)
{
$this->__index($serviceName);
}
/**
* wsdl文件
* @param mixed $serviceName
* @return mixed
*/
public function wsdl($serviceName)
{
$this->__wsdl($serviceName);
}
/**
* webservice調用入口
* @param mixed $serviceName
* @return mixed
*/
public function exec($serviceName)
{
$this->__exec($serviceName);
}
/**
* 測試入口
* @param mixed $serviceName
* @param mixed $methodName
* @return mixed
*/
public function test($serviceName,$methodName)
{
$this->__test($serviceName,$methodName);
}
}
~~~
#### 路由
路由這一步其實無關緊要,使用默認的規則訪問也可以,如果想要Url美觀,可以參考我給的示例自行修改。
~~~
'rules' => array(
'Service/[serviceName:word]/[methodName:word]/test' => 'Test/Service/test',
'Service/[serviceName:word]/[action:word]' => 'Test/Service/$2',
'Service/[serviceName:word]' => 'Test/Service/index',
)
~~~
這樣配置,路徑就是這樣的
> index:http://xxx.com/Service/服務名
> wsdl:http://xxx.com/Service/服務名/wsdl
> exec:http://xxx.com/Service/服務名/exec
> test:http://xxx.com/Service/服務名/方法名/test
#### 服務文件
一般放在對應模塊的Lib目錄下
`Test.class.php`
~~~
<?php
/**
* 測試接口
* @namespace http://www.baidu.com/
*/
class Test
{
/**
* 加法1
* @soap
* @param int $a1 數字1
* @param int $b1 數字2
* @return int
*/
public function add($a1,$b1)
{
return $a1 + $b1;
}
/**
* 減法
* @soap
* @param int $a 數字1
* @param int $b 數字2
* @return int[]
*/
public function sub($a,$b)
{
return array($a,$b);
}
public function test1()
{
}
private function test2()
{
}
}
~~~
> namespace可以自行修改
> 開放出來的soap方法只有add和sub,也就是依靠注釋來識別哪個是soap方法。
> 參數和返回值一定要詳細注釋,否則生成的wsdl不對,調用不出來。
- 序言
- 有些話想說
- 基礎入門
- 簡介
- 下載安裝YurunPHP
- 運行環境
- 開發規范
- 目錄結構
- 模塊
- 控制器
- 自動加載
- 手動加載
- 項目配置
- 入口文件
- 項目目錄結構
- 配置文件
- 驅動配置
- 數據庫配置
- 項目初始化處理
- 框架編譯
- 項目部署
- 控制器
- 創建控制器
- 加載模版顯示頁面
- AJAX返回數據
- 模型
- 創建模型
- 實例化模型
- 數據管理
- 連貫操作
- distinct
- field
- from
- where
- wherePk
- group
- having
- order
- limit
- join
- page
- headTotal/footTotal
- 連貫操作收尾方法
- select
- selectPage
- buildSQL
- selectValue
- selectBy
- getBy
- getByPk
- random
- inc
- dec
- add
- edit
- delete
- 合計函數
- save
- 執行SQL語句
- 創建數據并驗證
- 字段映射
- 增刪改查前置和后置
- Response類
- GET/POST/COOKIE/REQUEST
- Cookie
- Session
- 如何自定義Session存儲
- 數據庫操作
- 常用操作
- 查詢記錄
- 存儲過程
- 數據庫函數
- MSSQL
- 視圖
- 調用視圖
- 給視圖傳值
- 模版引擎
- 輸出
- 使用PHP代碼
- 模版標簽
- if
- switch
- for
- counter
- foreach
- include
- js/css/image
- url
- origin
- 模版常量替換
- 后臺視圖控件
- 通用屬性用法
- 數據集綁定
- 下拉框(select)
- 單選框(radio)
- 單選框組(radiogroup)
- 選擇框(checkbox)
- 選擇框組(checkboxgroup)
- 表格(table)
- 文本框(textbox)
- 分頁條(pagebar)
- 數據驗證
- 驗證方法
- between
- betweenEqual
- empty_str
- not_empty_str
- regex
- length
- lengthChar
- mobile
- tel
- phone
- postcode
- url
- ip
- lt/gt/ltEqual/gtEqual
- equal/unequal
- in/notin
- idcard
- 路由
- 路由配置
- 自定義分層
- 緩存
- 緩存配置
- 使用緩存
- 配置
- 配置驅動配置
- 使用配置
- 過濾域名
- 日志
- 日志驅動配置
- 文件日志
- 事件
- 事件列表
- 插件
- 多語言支持
- 定時任務
- API接口開發
- CLI命令行模式
- Soap WebService