GoogleOauth.php 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. <?php
  2. namespace App\libs\google\Gateways;
  3. use Google\Client;
  4. use Illuminate\Support\Facades\Config;
  5. class GoogleOauth
  6. {
  7. private $config;
  8. private $client;
  9. public function __construct()
  10. {
  11. $this->config = Config::get('swdz.goodle');
  12. $this->client = new Client([
  13. 'client_id' => $this->config['client_id'],
  14. 'client_secret' => $this->config['client_secret'],
  15. 'redirect_uri' => $this->config['redirect_uri'],
  16. 'scopes' => $this->config['scopes'],
  17. ]);
  18. }
  19. /**
  20. * APP通过code换取用户信息.
  21. *
  22. * @return array|false
  23. *
  24. * @throws \Psr\Container\ContainerExceptionInterface
  25. * @throws \Psr\Container\NotFoundExceptionInterface
  26. */
  27. public function appAuth()
  28. {
  29. $code = request()->get('code', null);
  30. return $this->client->verifyIdToken($code);
  31. }
  32. /**
  33. * WEB打开授权页面(待补充).
  34. */
  35. public static function webAuth(): void
  36. {
  37. }
  38. }