Credential.php 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. /*
  3. * Licensed to the Apache Software Foundation (ASF) under one
  4. * or more contributor license agreements. See the NOTICE file
  5. * distributed with this work for additional information
  6. * regarding copyright ownership. The ASF licenses this file
  7. * to you under the Apache License, Version 2.0 (the
  8. * "License"); you may not use this file except in compliance
  9. * with the License. You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing,
  14. * software distributed under the License is distributed on an
  15. * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  16. * KIND, either express or implied. See the License for the
  17. * specific language governing permissions and limitations
  18. * under the License.
  19. */
  20. namespace Mrgoon\AliyunSmsSdk\Auth;
  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. }