GoogleOauth.php 1016 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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. * @throws \Psr\Container\ContainerExceptionInterface
  24. * @throws \Psr\Container\NotFoundExceptionInterface
  25. */
  26. public function appAuth(){
  27. $code = request()->get('code', null);
  28. return $this->client->verifyIdToken($code);
  29. }
  30. /**
  31. * WEB打开授权页面(待补充)
  32. *
  33. * @return void
  34. */
  35. public static function webAuth(){
  36. }
  37. }