**SOA**
>很多时候我们在一个服务内需要依赖其他服务接口提供的功能,PHPCAN内置的SOA模块可以很方便的调用其他服务中的接口
###### 配置
~~~
// 1、开启SOA支持
// 在 phpcan/conf/Define.php中设置_SOA为TRUE
define('_SOA', TRUE);
// 2、设置网关地址
// 在 phpcan/conf/Define.php中设置_GATEWAY的地址
define('_GATEWAY', 'http://xxx.xxx.xxx.xxx/');
// 3、在项目配置文件Conf.php中修改以下内容
// 这里以默认项目demo为例,配置文件路径:./work/demo/conf/Conf.php
return [
......
// SOA开发者账号,如有依赖其他服务请填写该项
'SOAUNAME' => '',
// SOA开发者密码,如有依赖其他服务请填写该项
'SOAPWORD' => '',
// 依赖服务编排
'COMPOSER' => [
// KEY为依赖服务的命名空间,在SOA中查看
'xxx' => [
// 依赖服务的版本号,在SOA中查看
'VERSION' => '1.0.1',
// APPID
'APPID' => '',
// 密钥
'SECRET' => ''
]
]
];
// 完成以上配置则可以继续下面的操作
~~~
###### 请求一个GET接口
~~~
// 基本方式示例
\api\Soa::get('/test/xxx/');
// 增加参数id=1
\api\Soa::get('/test/xxx/', [
'id' => 1
]);
~~~
###### 请求一个POST接口
~~~
// 基本方式示例
\api\Soa::post('/test/xxx/', [
// 提交的数据
'xxx' => 'xxx'
]);
~~~
###### 设置超时时间
~~~
\api\Soa::timeout(10)->get('/test/xxx/');
\api\Soa::timeout(10)->post('/test/xxx/', [
'id' => 1
]);
~~~
###### 设置HEADER
~~~
\api\Soa::header([
'name' => 'test'
])->get('/test/xxx/');
\api\Soa::header([
'name' => 'test'
])->post('/test/xxx/', [
'id' => 1
]);
~~~
###### 添加一个并发任务
~~~
\api\Soa::add('rw1', [
// 请求地址
'url' => 'http://127.0.0.1',
// 请求参数
'query' => [
'id' => 1
],
// POST表单数据
'post' => [
'name' => 'test'
],
// header
'header' => [
'name' => 'test'
],
// 超时
'timeout' => 3
]);
// 执行并发任务
\api\Soa::run();
~~~