王大坤 1 年之前
父节点
当前提交
70cce3f18b

+ 2 - 1
app/Http/Controllers/V1/IndexController.php

xqd xqd
@@ -3,6 +3,7 @@
 namespace App\Http\Controllers\V1;
 
 use App\Auth;
+use App\libs\google\Google;
 use App\libs\google\GoogleOauth;
 use App\libs\helpers\Curl;
 use App\libs\helpers\LogHelper;
@@ -25,7 +26,7 @@ class IndexController extends Controller
      */
     public function index(){
         try {
-            $google = GoogleOauth::appAuth();
+            $google = Google::GoogleOauth()->appAuth();
 //            $weChat = WeChat::General();
 //            $userInfo = $weChat->auth('snsapi_userinfo');
 //            $userInfo = $weChat->userDetailInfo($userInfo['openid']);

+ 11 - 12
app/libs/google/GoogleOauth.php → app/libs/google/Gateways/GoogleOauth.php

xqd xqd
@@ -1,22 +1,22 @@
 <?php
 
-namespace App\libs\google;
+namespace App\libs\google\Gateways;
 
 use Google\Client;
 use Illuminate\Support\Facades\Config;
 
 class GoogleOauth
 {
-    private static $config;
-    private static $client;
+    private  $config;
+    private  $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']
+        $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']
         ]);
     }
 
@@ -27,10 +27,9 @@ class GoogleOauth
      * @throws \Psr\Container\ContainerExceptionInterface
      * @throws \Psr\Container\NotFoundExceptionInterface
      */
-    public static function appAuth(){
+    public  function appAuth(){
         $code = request()->get('code', null);
-        var_dump($code);
-        return self::$client->verifyIdToken($code);
+        return $this->client->verifyIdToken($code);
     }
 
     /**

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

xqd
@@ -0,0 +1,41 @@
+<?php
+
+namespace App\libs\google;
+
+
+use Symfony\Component\VarExporter\Exception\ClassNotFoundException;
+
+/**
+ * @desc
+ * @method  static \App\libs\google\Gateways\GoogleOauth     GoogleOauth
+ * @package \App\libs\google
+ */
+class Google
+{
+    /**
+     * @param $method
+     * @return mixed
+     */
+    private static function make($method)
+    {
+        $value = ucwords(str_replace(['-', '_'], ' ', $method));
+
+        $gateway = __NAMESPACE__ . '\\Gateways\\' . $value;
+
+        if (class_exists($gateway)) {
+            return new $gateway();
+        }
+        throw new ClassNotFoundException("Gateway [{$method}] Not Exists",$gateway);
+    }
+
+    /**
+     * @desc
+     * @param   string  $method
+     * @param   array   $arguments
+     * @return  mixed
+     */
+    public static function __callStatic($method, $arguments)
+    {
+        return self::make($method, ...$arguments);
+    }
+}

+ 4 - 4
app/libs/wechat/auth/WeChat.php

xqd
@@ -1,13 +1,13 @@
 <?php
 
 namespace App\libs\wechat\auth;
-use Prophecy\Exception\Doubler\ClassNotFoundException;
+use Symfony\Component\VarExporter\Exception\ClassNotFoundException;
 
 /**
  * @desc
- * @method  static \swdz\wechat\auth\Gateways\General     General
- * @method  static \swdz\wechat\auth\Gateways\Mini        Mini
- * @package lc\wechat\auth
+ * @method  static \App\libs\wechat\auth\Gateways\General     General
+ * @method  static \App\libs\wechat\auth\Gateways\Mini        Mini
+ * @package \App\libs\wechat\auth
  */
 class WeChat
 {