Token.php 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. namespace app\extra\dyLife;
  3. use yzh52521\EasyHttp\Http;
  4. class Token extends BasicLife
  5. {
  6. /**
  7. * 获取AccessToken
  8. * https://developer.open-douyin.com/docs/resource/zh-CN/mini-app/develop/server/basic-abilities/interface-request-credential/non-user-authorization/get-client_token
  9. * @param string $grantType
  10. * @return array
  11. */
  12. public function getAccessToken(string $grantType = 'client_credential'): array
  13. {
  14. $data = [
  15. "client_key" => $this->config['appid'],
  16. "client_secret" => $this->config['secret'],
  17. "grant_type" => $grantType
  18. ];
  19. return $this->curlPostApi("oauth/client_token/",$data);
  20. }
  21. public function getAccessTokenUser(string $code = "", string $grantType = 'authorization_code'): array
  22. {
  23. $data = [
  24. "client_key" => $this->config['appid'],
  25. "client_secret" => $this->config['secret'],
  26. "code" => $code,
  27. "grant_type" => $grantType
  28. ];
  29. return $this->curlPostApi("oauth/access_token/",$data);
  30. }
  31. }