HuaweiRequest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace app\admin\common;
  3. class HuaweiRequest
  4. {
  5. public $method = '';
  6. public $scheme = '';
  7. public $host = '';
  8. public $uri = '';
  9. public $query = array();
  10. public $headers = array();
  11. public $body = '';
  12. function __construct()
  13. {
  14. $args = func_get_args();
  15. $i = count($args);
  16. if ($i == 0) {
  17. $this->construct(NULL, NULL, NULL, NULL);
  18. } elseif ($i == 1) {
  19. $this->construct($args[0], NULL, NULL, NULL);
  20. } elseif ($i == 2) {
  21. $this->construct($args[0], $args[1], NULL, NULL);
  22. } elseif ($i == 3) {
  23. $this->construct($args[0], $args[1], $args[2], NULL);
  24. } else {
  25. $this->construct($args[0], $args[1], $args[2], $args[3]);
  26. }
  27. }
  28. function construct($method, $url, $headers, $body)
  29. {
  30. if ($method != NULL) {
  31. $this->method = $method;
  32. }
  33. if ($url != NULL) {
  34. $spl = explode("://", $url, 2);
  35. $scheme = 'http';
  36. if (count($spl) > 1) {
  37. $scheme = $spl[0];
  38. $url = $spl[1];
  39. }
  40. $spl = explode("?", $url, 2);
  41. $url = $spl[0];
  42. $query = array();
  43. if (count($spl) > 1) {
  44. foreach (explode("&", $spl[1]) as $kv) {
  45. $spl = explode("=", $kv, 2);
  46. $key = $spl[0];
  47. if (count($spl) == 1) {
  48. $value = "";
  49. } else {
  50. $value = $spl[1];
  51. }
  52. if ($key != "") {
  53. $key = urldecode($key);
  54. $value = urldecode($value);
  55. if (array_key_exists($key, $query)) {
  56. array_push($query[$key], $value);
  57. } else {
  58. $query[$key] = array($value);
  59. }
  60. }
  61. }
  62. }
  63. $spl = explode("/", $url, 2);
  64. $host = $spl[0];
  65. if (count($spl) == 1) {
  66. $url = "/";
  67. } else {
  68. $url = "/" . $spl[1];
  69. }
  70. $this->scheme = $scheme;
  71. $this->host = $host;
  72. $this->uri = urldecode($url);
  73. $this->query = $query;
  74. }
  75. if ($headers != NULL) {
  76. $this->headers = $headers;
  77. }
  78. if ($body != NULL) {
  79. $this->body = $body;
  80. }
  81. }
  82. }