PreApiAccessToken.php 901 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace app\frontend\modules\accessToken;
  3. use app\common\models\ApiAccessToken;
  4. class PreApiAccessToken extends ApiAccessToken
  5. {
  6. public function touchAttributes()
  7. {
  8. //30天过期
  9. $this->expires_at = $this->getExpiresAt();
  10. $this->uniacid = (int)\YunShop::app()->uniacid;
  11. $this->access_token = $this->getAccessToken();
  12. $this->revoked = false;
  13. }
  14. private function getAccessToken()
  15. {
  16. return base64_encode(md5(md5($this->uniacid) . time() . range(0, 10000)));
  17. }
  18. private function getExpiresAt()
  19. {
  20. return time() + 60 * 60 * 24 * 30;
  21. }
  22. public function toArray()
  23. {
  24. $this->touchAttributes();
  25. return parent::toArray();
  26. }
  27. //public function
  28. public function save(array $options = [])
  29. {
  30. $this->touchAttributes();
  31. return parent::save($options);
  32. }
  33. }