ClientProfile.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  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. * client可选参数类
  21. * Class ClientProfile
  22. * @package TencentCloud\Common\Profile
  23. */
  24. class ClientProfile
  25. {
  26. /**
  27. * @var string hmacsha1算法
  28. */
  29. public static $SIGN_HMAC_SHA1 = "HmacSHA1";
  30. /**
  31. * @var string hmacsha256算法
  32. */
  33. public static $SIGN_HMAC_SHA256 = "HmacSHA256";
  34. /**
  35. * @var string 签名V3
  36. */
  37. public static $SIGN_TC3_SHA256 = "TC3-HMAC-SHA256";
  38. /**
  39. * @var string Chinese simplified
  40. */
  41. public static $ZH_CN = "zh-CN";
  42. /**
  43. * @var string English
  44. */
  45. public static $EN_US = "en-US";
  46. /**
  47. * @var HttpProfile http相关参数
  48. */
  49. private $httpProfile;
  50. /**
  51. * @var string 签名方法
  52. */
  53. private $signMethod;
  54. /**
  55. * @var string 忽略内容签名
  56. */
  57. private $unsignedPayload;
  58. /**
  59. * @var boolean
  60. */
  61. private $checkPHPVersion;
  62. /**
  63. * @var string
  64. */
  65. private $language;
  66. /**
  67. * ClientProfile constructor.
  68. * @param string $signMethod 签名算法,目前支持SHA256,SHA1
  69. * @param HttpProfile $httpProfile http参数类
  70. */
  71. public function __construct($signMethod = null, $httpProfile = null)
  72. {
  73. $this->signMethod = $signMethod ? $signMethod : ClientProfile::$SIGN_TC3_SHA256;
  74. $this->httpProfile = $httpProfile ? $httpProfile : new HttpProfile();
  75. $this->unsignedPayload = false;
  76. $this->checkPHPVersion = true;
  77. //$this->language = ClientProfile::$ZH_CN;
  78. }
  79. /**
  80. * 设置签名算法
  81. * @param string $signMethod 签名方法,目前支持SHA256,SHA1, TC3
  82. */
  83. public function setSignMethod($signMethod)
  84. {
  85. $this->signMethod = $signMethod;
  86. }
  87. /**
  88. * 设置http相关参数
  89. * @param HttpProfile $httpProfile http相关参数
  90. */
  91. public function setHttpProfile($httpProfile)
  92. {
  93. $this->httpProfile = $httpProfile;
  94. }
  95. /**
  96. * 获取签名方法
  97. * @return null|string 签名方法
  98. */
  99. public function getSignMethod()
  100. {
  101. return $this->signMethod;
  102. }
  103. /**
  104. * 设置是否忽略内容签名
  105. * @param bool $flag true表示忽略签名
  106. */
  107. public function setUnsignedPayload($flag)
  108. {
  109. $this->unsignedPayload = $flag;
  110. }
  111. /**
  112. * 获取是否忽略内容签名标志位
  113. * @return bool
  114. */
  115. public function getUnsignedPayload()
  116. {
  117. return $this->unsignedPayload;
  118. }
  119. public function getCheckPHPVersion()
  120. {
  121. return $this->checkPHPVersion;
  122. }
  123. public function setCheckPHPVersion($flag)
  124. {
  125. $this->checkPHPVersion = $flag;
  126. }
  127. public function getLanguage()
  128. {
  129. return $this->language;
  130. }
  131. /**
  132. * @param string $language Valid values: zh-CN, en-US
  133. */
  134. public function setLanguage($language)
  135. {
  136. $this->language = $language;
  137. }
  138. /**
  139. * 获取http选项实例
  140. * @return null|HttpProfile http选项实例
  141. */
  142. public function getHttpProfile()
  143. {
  144. return $this->httpProfile;
  145. }
  146. }