Browse Source

H5授权登录

Kirin 2 years ago
parent
commit
da3359b17f
1 changed files with 26 additions and 0 deletions
  1. 26 0
      app/api/controller/AuthController.php

+ 26 - 0
app/api/controller/AuthController.php

@@ -391,4 +391,30 @@ class AuthController
         else
             return app('json')->fail('绑定失败');
     }
+
+
+
+    public static function h5Key()
+    {
+        $time = time();
+        do {
+            $key = md5($time . rand(1000, 9999));
+        } while (CacheService::get($key . '_time'));
+        CacheService::set($key . '_time', $time, 300);
+        return app('json')->success('ok', compact('key', 'time'));
+    }
+
+    public static function h5Auth($key, Request $request)
+    {
+        if (!CacheService::get($key . '_time')) return app('json')->fail('二维码已过期,请刷新。');
+        CacheService::set($key, trim(ltrim($request->header('Authori-zation'), 'Bearer')), 60);
+        return app('json')->success('授权完成');
+    }
+
+    public static function h5Token($key)
+    {
+        $token = CacheService::get($key);
+        if ($token) return app('json')->success('ok', compact('token'));
+        return app('json')->fail('授权失败');
+    }
 }