GoogleOauth.php 1.0 KB

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