Credential.php 1.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace Aliyun\Core\Auth;
  3. class Credential
  4. {
  5. private $dateTimeFormat = 'Y-m-d\TH:i:s\Z';
  6. private $refreshDate;
  7. private $expiredDate;
  8. private $accessKeyId;
  9. private $accessSecret;
  10. private $securityToken;
  11. function __construct($accessKeyId, $accessSecret)
  12. {
  13. $this->accessKeyId = $accessKeyId;
  14. $this->accessSecret = $accessSecret;
  15. $this->refreshDate = date($this->dateTimeFormat);
  16. }
  17. public function isExpired()
  18. {
  19. if($this->expiredDate == null)
  20. {
  21. return false;
  22. }
  23. if(strtotime($this->expiredDate)>date($this->dateTimeFormat))
  24. {
  25. return false;
  26. }
  27. return true;
  28. }
  29. public function getRefreshDate()
  30. {
  31. return $this->refreshDate;
  32. }
  33. public function getExpiredDate()
  34. {
  35. return $this->expiredDate;
  36. }
  37. public function setExpiredDate($expiredHours)
  38. {
  39. if($expiredHours>0)
  40. {
  41. return $this->expiredDate = date($this->dateTimeFormat, strtotime("+".$expiredHours." hour"));
  42. }
  43. }
  44. public function getAccessKeyId()
  45. {
  46. return $this->accessKeyId;
  47. }
  48. public function setAccessKeyId($accessKeyId)
  49. {
  50. $this->accessKeyId = $accessKeyId;
  51. }
  52. public function getAccessSecret()
  53. {
  54. return $this->accessSecret;
  55. }
  56. public function setAccessSecret($accessSecret)
  57. {
  58. $this->accessSecret = $accessSecret;
  59. }
  60. }