Token.php 692 B

1234567891011121314151617181920212223242526272829303132
  1. <?php
  2. namespace WeWork\ApiCache;
  3. use WeWork\Traits\CorpIdTrait;
  4. use WeWork\Traits\HttpClientTrait;
  5. use WeWork\Traits\SecretTrait;
  6. class Token extends AbstractApiCache
  7. {
  8. use CorpIdTrait, SecretTrait, HttpClientTrait;
  9. /**
  10. * @return string
  11. */
  12. protected function getCacheKey(): string
  13. {
  14. $unique = md5($this->secret);
  15. return md5('wework.api.token.' . $unique);
  16. }
  17. /**
  18. * @return string
  19. */
  20. protected function getFromServer(): string
  21. {
  22. $data = $this->httpClient->get('gettoken', ['corpid' => $this->corpId, 'corpsecret' => $this->secret]);
  23. return $data['access_token'];
  24. }
  25. }