ClientProfile.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 HttpProfile http相关参数
  40. */
  41. private $httpProfile;
  42. /**
  43. * @var string 签名方法
  44. */
  45. private $signMethod;
  46. /**
  47. * @var string 忽略内容签名
  48. */
  49. private $unsignedPayload;
  50. /**
  51. * ClientProfile constructor.
  52. * @param string $signMethod 签名算法,目前支持SHA256,SHA1
  53. * @param HttpProfile $httpProfile http参数类
  54. */
  55. public function __construct($signMethod = null, $httpProfile = null)
  56. {
  57. $this->signMethod = $signMethod ? $signMethod : ClientProfile::$SIGN_TC3_SHA256;
  58. $this->httpProfile = $httpProfile ? $httpProfile : new HttpProfile();
  59. $this->unsignedPayload = false;
  60. }
  61. /**
  62. * 设置签名算法
  63. * @param string $signMethod 签名方法,目前支持SHA256,SHA1, TC3
  64. */
  65. public function setSignMethod($signMethod)
  66. {
  67. $this->signMethod = $signMethod;
  68. }
  69. /**
  70. * 设置http相关参数
  71. * @param HttpProfile $httpProfile http相关参数
  72. */
  73. public function setHttpProfile($httpProfile)
  74. {
  75. $this->httpProfile = $httpProfile;
  76. }
  77. /**
  78. * 获取签名方法
  79. * @return null|string 签名方法
  80. */
  81. public function getSignMethod()
  82. {
  83. return $this->signMethod;
  84. }
  85. /**
  86. * 设置是否忽略内容签名
  87. * @param bool $flag true表示忽略签名
  88. */
  89. public function setUnsignedPayload($flag)
  90. {
  91. $this->unsignedPayload = $flag;
  92. }
  93. /**
  94. * 获取是否忽略内容签名标志位
  95. * @return bool
  96. */
  97. public function getUnsignedPayload()
  98. {
  99. return $this->unsignedPayload;
  100. }
  101. /**
  102. * 获取http选项实例
  103. * @return null|HttpProfile http选项实例
  104. */
  105. public function getHttpProfile()
  106. {
  107. return $this->httpProfile;
  108. }
  109. }