王大坤 1 year ago
parent
commit
6ae137536b

+ 6 - 4
app/Http/Controllers/V1/IndexController.php

@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\V1;
 namespace App\Http\Controllers\V1;
 
 
 use App\Auth;
 use App\Auth;
+use App\libs\google\GoogleOauth;
 use App\libs\helpers\Curl;
 use App\libs\helpers\Curl;
 use App\libs\helpers\LogHelper;
 use App\libs\helpers\LogHelper;
 use App\libs\wechat\auth\WeChat;
 use App\libs\wechat\auth\WeChat;
@@ -24,10 +25,11 @@ class IndexController extends Controller
      */
      */
     public function index(){
     public function index(){
         try {
         try {
-            $weChat = WeChat::General();
-            $userInfo = $weChat->auth('snsapi_userinfo');
-            $userInfo = $weChat->userDetailInfo($userInfo['openid']);
-            var_dump($userInfo);
+            $google = GoogleOauth::appAuth();
+//            $weChat = WeChat::General();
+//            $userInfo = $weChat->auth('snsapi_userinfo');
+//            $userInfo = $weChat->userDetailInfo($userInfo['openid']);
+            var_dump($google);
             return  Response::success();
             return  Response::success();
         }catch (\Exception $exception){
         }catch (\Exception $exception){
             LogHelper::exceptionLog($exception,$this->code);
             LogHelper::exceptionLog($exception,$this->code);

+ 43 - 0
app/libs/google/GoogleOauth.php

@@ -0,0 +1,43 @@
+<?php
+
+namespace App\libs\google;
+
+use Google\Client;
+use Illuminate\Support\Facades\Config;
+
+class GoogleOauth
+{
+    private static $config;
+    private static $client;
+    public function __construct()
+    {
+        self::$config = Config::get('swdz.goodle');
+        self::$client = new Client([
+            'client_id' => self::$config['client_id'],
+            'client_secret' => self::$config['client_secret'],
+            'redirect_uri' => self::$config['redirect_uri'],
+            'scopes' => self::$config['scopes']
+        ]);
+    }
+
+    /**
+     * APP通过code换取用户信息
+     *
+     * @return array|false
+     * @throws \Psr\Container\ContainerExceptionInterface
+     * @throws \Psr\Container\NotFoundExceptionInterface
+     */
+    public static function appAuth(){
+        $code = request()->get('code', null);
+        return self::$client->verifyIdToken($code);
+    }
+
+    /**
+     * WEB打开授权页面(待补充)
+     *
+     * @return void
+     */
+    public static function webAuth(){
+
+    }
+}

+ 0 - 41
app/libs/google/Oauth.php

@@ -1,41 +0,0 @@
-<?php
-
-namespace App\libs\google;
-
-use Google\Client;
-use Illuminate\Support\Facades\Config;
-
-class Oauth
-{
-    public function __construct()
-    {
-        $this->config = Config::get('swdz.goodle');
-        $this->client = new Client([
-            'client_id' => $this->config['client_id'],
-            'client_secret' => $this->config['client_secret'],
-            'redirect_uri' => $this->config['redirect_uri'],
-            'scopes' => $this->config['scopes']
-        ]);
-    }
-
-    /**
-     * APP通过code换取用户信息
-     *
-     * @return array|false
-     * @throws \Psr\Container\ContainerExceptionInterface
-     * @throws \Psr\Container\NotFoundExceptionInterface
-     */
-    public function appAuth(){
-        $code = request()->get('code', null);
-        return $this->client->verifyIdToken($code);
-    }
-
-    /**
-     * WEB打开授权页面(待补充)
-     *
-     * @return void
-     */
-    public function webAuth(){
-
-    }
-}