项目作者: aliyunapi

项目描述 :
适用于阿里云的 GuzzleHttp 中间件
高级语言: PHP
项目地址: git://github.com/aliyunapi/guzzle-subscriber.git
创建时间: 2017-03-28T08:59:57Z
项目社区:https://github.com/aliyunapi/guzzle-subscriber

开源协议:MIT License

下载


aliyun-guzzle

鉴于官方SDK被称为史上最烂外包SDK,所以这个中间件是 GuzzleHttp 专用的,支持阿里云大部分API请求。有需要的自行扩展。
For license information check the LICENSE-file.

Latest Stable Version
Total Downloads

Installation

The preferred way to install this extension is through composer.

Either run

  1. php composer.phar require --prefer-dist aliyunapi/guzzle-subscriber

or add

  1. "aliyunapi/guzzle-subscriber": "~1.0"

to the require section of your composer.json.

使用

  1. use GuzzleHttp\Client;
  2. use GuzzleHttp\HandlerStack;
  3. use aliyun\guzzle\subscriber\Rpc;
  4. $stack = HandlerStack::create();
  5. //跟guzzlephp普通用法唯一的区别就是这里吧中间件加载进来,他会自动帮你签名重新包装请求参数。
  6. $middleware = new Rpc([
  7. 'accessKeyId' => '123456',
  8. 'accessSecret' => '654321',
  9. ]);
  10. $stack->push($middleware);
  11. //这里设置 网关地址,数组参数请参见 http://docs.guzzlephp.org/en/latest/request-options.html
  12. //操作哪个接口对应的 base_uri 就写哪个
  13. $client = new Client([
  14. 'base_uri' => 'http://live.aliyuncs.com/',
  15. 'handler' => $stack,
  16. ]);
  17. //查询参数 https://help.aliyun.com/document_detail/35412.html
  18. //这个页面列出了几个参数就在数组提交几个参数,其他的API接口也一样,只需对应参数给他提交即可。
  19. $res = $client->get('/', [
  20. 'query' => [
  21. 'Action' => 'DescribeLiveStreamOnlineUserNum',
  22. 'DomainName' => 'live.aaa.tv',
  23. 'AppName' => 'live',
  24. 'StreamName' => 'bbb',
  25. ]
  26. ]);
  27. print_r($res->getBody()->getContents());
  28. ////////////////////////////////////////////////////////////////////ROA已经实现了,但是没有条件测试,欢迎提交合并
  29. use GuzzleHttp\Client;
  30. use GuzzleHttp\HandlerStack;
  31. use aliyun\guzzle\subscriber\Roa;
  32. $stack = HandlerStack::create();
  33. //跟guzzlephp普通用法唯一的区别就是这里吧中间件加载进来,
  34. //他会自动帮你签名重新包装请求参数。
  35. $middleware = new Roa([
  36. 'accessKeyId' => '123456',
  37. 'accessSecret' => '654321',
  38. 'version'=>'123456',
  39. ]);
  40. $stack->push($middleware);
  41. $client = new Client([
  42. 'base_uri' => 'http://cs.aliyuncs.com/',
  43. 'handler' => $stack,
  44. ]);
  45. $res = $client->get('/', [
  46. 'query' => [
  47. //etc
  48. ]
  49. ]);
  50. print_r($res->getBody()->getContents());