Credential.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. namespace common\services\mall\aliyunsts\StsCode\Auth;
  3. /*
  4. * Licensed to the Apache Software Foundation (ASF) under one
  5. * or more contributor license agreements. See the NOTICE file
  6. * distributed with this work for additional information
  7. * regarding copyright ownership. The ASF licenses this file
  8. * to you under the Apache License, Version 2.0 (the
  9. * "License"); you may not use this file except in compliance
  10. * with the License. You may obtain a copy of the License at
  11. *
  12. * http://www.apache.org/licenses/LICENSE-2.0
  13. *
  14. * Unless required by applicable law or agreed to in writing,
  15. * software distributed under the License is distributed on an
  16. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  17. * KIND, either express or implied. See the License for the
  18. * specific language governing permissions and limitations
  19. * under the License.
  20. */
  21. class Credential
  22. {
  23. private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
  24. private $refreshDate;
  25. private $expiredDate;
  26. private $accessKeyId;
  27. private $accessSecret;
  28. private $securityToken;
  29. function __construct($accessKeyId, $accessSecret)
  30. {
  31. $this->accessKeyId = $accessKeyId;
  32. $this->accessSecret = $accessSecret;
  33. $this->refreshDate = date($this->dateTimeFormat);
  34. }
  35. public function isExpired()
  36. {
  37. if($this->expiredDate == null)
  38. {
  39. return false;
  40. }
  41. if(strtotime($this->expiredDate)>date($this->dateTimeFormat))
  42. {
  43. return false;
  44. }
  45. return true;
  46. }
  47. public function getRefreshDate()
  48. {
  49. return $this->refreshDate;
  50. }
  51. public function getExpiredDate()
  52. {
  53. return $this->expiredDate;
  54. }
  55. public function setExpiredDate($expiredHours)
  56. {
  57. if($expiredHours>0)
  58. {
  59. return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour"));
  60. }
  61. }
  62. public function getAccessKeyId()
  63. {
  64. return $this->accessKeyId;
  65. }
  66. public function setAccessKeyId($accessKeyId)
  67. {
  68. $this->accessKeyId = $accessKeyId;
  69. }
  70. public function getAccessSecret()
  71. {
  72. return $this->accessSecret;
  73. }
  74. public function setAccessSecret($accessSecret)
  75. {
  76. $this->accessSecret = $accessSecret;
  77. }
  78. }