HttpProfile.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. /*
  3. * Copyright (c) 2017-2018 THL A29 Limited, a Tencent company. All Rights Reserved.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing,
  12. * software distributed under the License is distributed on an
  13. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. * KIND, either express or implied. See the License for the
  15. * specific language governing permissions and limitations
  16. * under the License.
  17. */
  18. namespace TencentCloud\Common\Profile;
  19. /**
  20. * http相关参数类
  21. * Class HttpProfile
  22. * @package TencentCloud\Common\Profile
  23. */
  24. class HttpProfile
  25. {
  26. /**
  27. * @var string https访问
  28. */
  29. public static $REQ_HTTPS = "https://";
  30. /**
  31. * @var string http访问
  32. */
  33. public static $REQ_HTTP = "http://";
  34. /**
  35. * @var string post请求
  36. */
  37. public static $REQ_POST = "POST";
  38. /**
  39. * @var string get请求
  40. */
  41. public static $REQ_GET = "GET";
  42. /**
  43. * @var int 时间一分钟
  44. */
  45. public static $TM_MINUTE = 60;
  46. /**
  47. * @var string http请求方法
  48. */
  49. private $reqMethod;
  50. /**
  51. * @var string 请求接入点域名
  52. */
  53. private $endpoint;
  54. /**
  55. * @var integer 请求超时时长,单位为秒
  56. */
  57. private $reqTimeout;
  58. /**
  59. * @var string 请求协议
  60. */
  61. private $protocol;
  62. /**
  63. * HttpProfile constructor.
  64. * @param string $protocol 请求协议
  65. * @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com)
  66. * @param string $reqMethod http请求方法,目前支持POST GET
  67. * @param integer $reqTimeout 请求超时时间,单位:s
  68. */
  69. public function __construct($protocol = null, $endpoint = null, $reqMethod = null, $reqTimeout = null)
  70. {
  71. $this->reqMethod = $reqMethod ? $reqMethod : HttpProfile::$REQ_POST;
  72. $this->endpoint = $endpoint;
  73. $this->reqTimeout = $reqTimeout ? $reqTimeout : HttpProfile::$TM_MINUTE;
  74. $this->protocol = $protocol ? $protocol : HttpProfile::$REQ_HTTPS;
  75. }
  76. /**
  77. * 设置http请求方法
  78. * @param string $reqMethod http请求方法,目前支持POST GET
  79. */
  80. public function setReqMethod($reqMethod)
  81. {
  82. $this->reqMethod = $reqMethod;
  83. }
  84. /**
  85. * 设置请求协议
  86. * @param string $protocol 请求协议(https:// http://)
  87. */
  88. public function setProtocol($protocol) {
  89. $this->protocol = $protocol;
  90. }
  91. /**
  92. * 设置请求接入点域名
  93. * @param string $endpoint 请求接入点域名(xx.[region.]tencentcloudapi.com)
  94. */
  95. public function setEndpoint($endpoint)
  96. {
  97. $this->endpoint = $endpoint;
  98. }
  99. /**
  100. * 设置请求超时时间
  101. * @param integer $reqTimeout 请求超时时间,单位:s
  102. */
  103. public function setReqTimeout($reqTimeout)
  104. {
  105. $this->reqTimeout = $reqTimeout;
  106. }
  107. /**
  108. * 获取请求方法
  109. * @return null|string 请求方法
  110. */
  111. public function getReqMethod()
  112. {
  113. return $this->reqMethod;
  114. }
  115. /**
  116. * 获取请求协议
  117. * @return null|string 请求协议
  118. */
  119. public function getProtocol()
  120. {
  121. return $this->protocol;
  122. }
  123. /**
  124. * 获取请求超时时间
  125. * @return int 请求超时时间
  126. */
  127. public function getReqTimeout()
  128. {
  129. return $this->reqTimeout;
  130. }
  131. /**
  132. * 获取请求接入点域名
  133. * @return null|string 接入点域名
  134. */
  135. public function getEndpoint()
  136. {
  137. return $this->endpoint;
  138. }
  139. }