wesmiler 5 лет назад
Родитель
Сommit
bf63138901

+ 48 - 0
app/Controller/Api/CommonController.php

@@ -0,0 +1,48 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * This file is part of Hyperf.
+ *
+ * @link     https://www.hyperf.io
+ * @document https://hyperf.wiki
+ * @contact  group@hyperf.io
+ * @license  https://github.com/hyperf/hyperf/blob/master/LICENSE
+ *
+ */
+
+namespace App\Controller\Api;
+
+use App\Model\User;
+use Hyperf\HttpServer\Annotation\AutoController;
+
+/**
+ * Class LotteryController
+ * @package App\Controller\Api
+ * @AutoController()
+ */
+class CommonController extends BaseController
+{
+
+    public function verifyCode()
+    {
+        $redis = $this->container->get(\Hyperf\Redis\Redis::class);
+
+        $config = new \EasySwoole\VerifyCode\Conf();
+        $code = new \EasySwoole\VerifyCode\VerifyCode($config);
+
+        //重写验证码
+        // $img_code = mt_rand(1000,9999);
+        // $result = $code->DrawCode($img_code);
+
+        //系统验证码
+        $result = $code->DrawCode();
+        $img_code = $result->getImageCode();
+
+        //写入缓存 用于其他方法验证 并且设置过期时间
+        $redis->set('codes:'.session_id(), $img_code, 180);
+
+        return $result->getImageByte();
+
+    }
+}

+ 14 - 21
app/Middleware/Auth/TokenMiddleware.php

@@ -38,29 +38,22 @@ class TokenMiddleware implements MiddlewareInterface
     public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
     {
 
-//        try {
-            // 根据具体业务判断逻辑走向,这里假设用户携带的token有效
-            $token = $request->getHeaderLine('Authorization') ?? '';
-            if (strlen($token) > 0) {
-                $token = JWTUtil::handleToken($token);
-                if ($token == false || !$this->jwt->checkToken($token)) {
-                    throw new TokenValidException(__('api.1005'), 401);
-                }
-
-                $authId = $token->getClaim('authId');
-                $user = User::where('id', $authId)->where(['enable'=> 'T'])->first();
-                if(!$user){
-                    throw new TokenValidException(__('api.1029'), 401);
-                }
-            }else{
-                //return ApiResource::failed(1010);
-                throw new TokenValidException(__('api.1010'), 401);
+        // 根据具体业务判断逻辑走向,这里假设用户携带的token有效
+        $token = $request->getHeaderLine('Authorization') ?? '';
+        if (strlen($token) > 0) {
+            $token = JWTUtil::handleToken($token);
+            if ($token == false || !$this->jwt->checkToken($token)) {
+                throw new TokenValidException(__('api.1005'), 401);
             }
 
-        /*} catch (\Exception $exception){
-            throw new TokenValidException(__('api.1006'), 401);
-        }*/
-
+            $authId = $token->getClaim('authId');
+            $user = User::where('id', $authId)->where(['enable' => 'T'])->first();
+            if (!$user) {
+                throw new TokenValidException(__('api.1029'), 401);
+            }
+        } else {
+            throw new TokenValidException(__('api.1010'), 401);
+        }
 
         return $handler->handle($request);
     }

+ 2 - 1
composer.json

@@ -38,7 +38,8 @@
         "phper666/hyperf-server-command": "~1.0.0",
         "hyperf/resource": "^2.0",
         "hyperf/translation": "^2.0",
-        "phper666/jwt-auth": "^3.0"
+        "phper666/jwt-auth": "^3.0",
+        "easyswoole/verifycode": "3.x"
     },
     "require-dev": {
         "swoole/ide-helper": "^4.5",

+ 108 - 1
composer.lock

@@ -4,7 +4,7 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "5163f3587c9f0cd7628ffa2397424686",
+    "content-hash": "9348052da358d39ddc01851902b8ecd3",
     "packages": [
         {
             "name": "doctrine/annotations",
@@ -355,6 +355,113 @@
             "time": "2020-05-25T17:44:05+00:00"
         },
         {
+            "name": "easyswoole/spl",
+            "version": "1.3.7",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/easy-swoole/spl.git",
+                "reference": "b9d74dfbeb59086c51616ba09d7728cea7351d05"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/easy-swoole/spl/zipball/b9d74dfbeb59086c51616ba09d7728cea7351d05",
+                "reference": "b9d74dfbeb59086c51616ba09d7728cea7351d05",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-json": "*",
+                "php": ">=7.1.0"
+            },
+            "require-dev": {
+                "easyswoole/phpunit": "^1.0",
+                "easyswoole/swoole-ide-helper": "^1.0"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "EasySwoole\\Spl\\": "src/",
+                    "EasySwoole\\Spl\\Test\\": "test/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "YF",
+                    "email": "291323003@qq.com"
+                }
+            ],
+            "description": "php stander lib",
+            "homepage": "https://www.easyswoole.com/",
+            "keywords": [
+                "async",
+                "easyswoole",
+                "framework",
+                "swoole"
+            ],
+            "support": {
+                "issues": "https://github.com/easy-swoole/spl/issues",
+                "source": "https://github.com/easy-swoole/spl/tree/master"
+            },
+            "time": "2020-04-05T15:50:30+00:00"
+        },
+        {
+            "name": "easyswoole/verifycode",
+            "version": "3.0.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/easy-swoole/verify-code.git",
+                "reference": "d79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/easy-swoole/verify-code/zipball/d79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb",
+                "reference": "d79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "easyswoole/spl": "^1.0",
+                "ext-gd": "*",
+                "php": ">=7.1"
+            },
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "EasySwoole\\VerifyCode\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "authors": [
+                {
+                    "name": "YF",
+                    "email": "291323003@qq.com"
+                },
+                {
+                    "name": "evalor",
+                    "email": "mipone@foxmail.com"
+                }
+            ],
+            "support": {
+                "issues": "https://github.com/easy-swoole/verify-code/issues",
+                "source": "https://github.com/easy-swoole/verify-code/tree/3.0.2"
+            },
+            "time": "2020-07-28T04:12:59+00:00"
+        },
+        {
             "name": "fig/http-message-util",
             "version": "1.1.4",
             "source": {

+ 18 - 0
vendor/composer/InstalledVersions.php

@@ -92,6 +92,24 @@ private static $installed = array (
       ),
       'reference' => 'e864bbf5904cb8f5bb334f99209b48018522f042',
     ),
+    'easyswoole/spl' => 
+    array (
+      'pretty_version' => '1.3.7',
+      'version' => '1.3.7.0',
+      'aliases' => 
+      array (
+      ),
+      'reference' => 'b9d74dfbeb59086c51616ba09d7728cea7351d05',
+    ),
+    'easyswoole/verifycode' => 
+    array (
+      'pretty_version' => '3.0.2',
+      'version' => '3.0.2.0',
+      'aliases' => 
+      array (
+      ),
+      'reference' => 'd79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb',
+    ),
     'fig/http-message-util' => 
     array (
       'pretty_version' => '1.1.4',

+ 3 - 0
vendor/composer/autoload_psr4.php

@@ -94,6 +94,9 @@ return array(
     'GuzzleHttp\\' => array($vendorDir . '/guzzlehttp/guzzle/src'),
     'Fig\\Http\\Message\\' => array($vendorDir . '/fig/http-message-util/src'),
     'FastRoute\\' => array($vendorDir . '/nikic/fast-route/src'),
+    'EasySwoole\\VerifyCode\\' => array($vendorDir . '/easyswoole/verifycode/src'),
+    'EasySwoole\\Spl\\Test\\' => array($vendorDir . '/easyswoole/spl/test'),
+    'EasySwoole\\Spl\\' => array($vendorDir . '/easyswoole/spl/src'),
     'Dotenv\\' => array($vendorDir . '/vlucas/phpdotenv/src'),
     'Doctrine\\Instantiator\\' => array($vendorDir . '/doctrine/instantiator/src/Doctrine/Instantiator'),
     'Doctrine\\Inflector\\' => array($vendorDir . '/doctrine/inflector/lib/Doctrine/Inflector'),

+ 18 - 0
vendor/composer/autoload_static.php

@@ -164,6 +164,12 @@ class ComposerStaticInit9622285a5a7446d42ea979e0e2b28dd5
             'Fig\\Http\\Message\\' => 17,
             'FastRoute\\' => 10,
         ),
+        'E' => 
+        array (
+            'EasySwoole\\VerifyCode\\' => 22,
+            'EasySwoole\\Spl\\Test\\' => 20,
+            'EasySwoole\\Spl\\' => 15,
+        ),
         'D' => 
         array (
             'Dotenv\\' => 7,
@@ -541,6 +547,18 @@ class ComposerStaticInit9622285a5a7446d42ea979e0e2b28dd5
         array (
             0 => __DIR__ . '/..' . '/nikic/fast-route/src',
         ),
+        'EasySwoole\\VerifyCode\\' => 
+        array (
+            0 => __DIR__ . '/..' . '/easyswoole/verifycode/src',
+        ),
+        'EasySwoole\\Spl\\Test\\' => 
+        array (
+            0 => __DIR__ . '/..' . '/easyswoole/spl/test',
+        ),
+        'EasySwoole\\Spl\\' => 
+        array (
+            0 => __DIR__ . '/..' . '/easyswoole/spl/src',
+        ),
         'Dotenv\\' => 
         array (
             0 => __DIR__ . '/..' . '/vlucas/phpdotenv/src',

+ 113 - 0
vendor/composer/installed.json

@@ -523,6 +523,119 @@
             "install-path": "../doctrine/lexer"
         },
         {
+            "name": "easyswoole/spl",
+            "version": "1.3.7",
+            "version_normalized": "1.3.7.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/easy-swoole/spl.git",
+                "reference": "b9d74dfbeb59086c51616ba09d7728cea7351d05"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/easy-swoole/spl/zipball/b9d74dfbeb59086c51616ba09d7728cea7351d05",
+                "reference": "b9d74dfbeb59086c51616ba09d7728cea7351d05",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "ext-json": "*",
+                "php": ">=7.1.0"
+            },
+            "require-dev": {
+                "easyswoole/phpunit": "^1.0",
+                "easyswoole/swoole-ide-helper": "^1.0"
+            },
+            "time": "2020-04-05T15:50:30+00:00",
+            "type": "library",
+            "installation-source": "dist",
+            "autoload": {
+                "psr-4": {
+                    "EasySwoole\\Spl\\": "src/",
+                    "EasySwoole\\Spl\\Test\\": "test/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "Apache-2.0"
+            ],
+            "authors": [
+                {
+                    "name": "YF",
+                    "email": "291323003@qq.com"
+                }
+            ],
+            "description": "php stander lib",
+            "homepage": "https://www.easyswoole.com/",
+            "keywords": [
+                "async",
+                "easyswoole",
+                "framework",
+                "swoole"
+            ],
+            "support": {
+                "issues": "https://github.com/easy-swoole/spl/issues",
+                "source": "https://github.com/easy-swoole/spl/tree/master"
+            },
+            "install-path": "../easyswoole/spl"
+        },
+        {
+            "name": "easyswoole/verifycode",
+            "version": "3.0.2",
+            "version_normalized": "3.0.2.0",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/easy-swoole/verify-code.git",
+                "reference": "d79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/easy-swoole/verify-code/zipball/d79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb",
+                "reference": "d79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb",
+                "shasum": "",
+                "mirrors": [
+                    {
+                        "url": "https://mirrors.aliyun.com/composer/dists/%package%/%reference%.%type%",
+                        "preferred": true
+                    }
+                ]
+            },
+            "require": {
+                "easyswoole/spl": "^1.0",
+                "ext-gd": "*",
+                "php": ">=7.1"
+            },
+            "time": "2020-07-28T04:12:59+00:00",
+            "type": "library",
+            "installation-source": "dist",
+            "autoload": {
+                "psr-4": {
+                    "EasySwoole\\VerifyCode\\": "src"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "authors": [
+                {
+                    "name": "YF",
+                    "email": "291323003@qq.com"
+                },
+                {
+                    "name": "evalor",
+                    "email": "mipone@foxmail.com"
+                }
+            ],
+            "support": {
+                "issues": "https://github.com/easy-swoole/verify-code/issues",
+                "source": "https://github.com/easy-swoole/verify-code/tree/3.0.2"
+            },
+            "install-path": "../easyswoole/verifycode"
+        },
+        {
             "name": "fig/http-message-util",
             "version": "1.1.4",
             "version_normalized": "1.1.4.0",

+ 18 - 0
vendor/composer/installed.php

@@ -79,6 +79,24 @@
       ),
       'reference' => 'e864bbf5904cb8f5bb334f99209b48018522f042',
     ),
+    'easyswoole/spl' => 
+    array (
+      'pretty_version' => '1.3.7',
+      'version' => '1.3.7.0',
+      'aliases' => 
+      array (
+      ),
+      'reference' => 'b9d74dfbeb59086c51616ba09d7728cea7351d05',
+    ),
+    'easyswoole/verifycode' => 
+    array (
+      'pretty_version' => '3.0.2',
+      'version' => '3.0.2.0',
+      'aliases' => 
+      array (
+      ),
+      'reference' => 'd79497dc1b1c7bbaeceb0c62fea6a9a96f7957cb',
+    ),
     'fig/http-message-util' => 
     array (
       'pretty_version' => '1.1.4',