Sfoglia il codice sorgente

7-6短信验证码记录到redis中

林志杰 5 anni fa
parent
commit
1e9ed1f2a0

+ 34 - 0
app/api/config/cache.php

@@ -0,0 +1,34 @@
+<?php
+
+// +----------------------------------------------------------------------
+// | 缓存设置
+// +----------------------------------------------------------------------
+
+return [
+    // 默认缓存驱动
+    'default' => env('cache.driver', 'file'),
+
+    // 缓存连接方式配置
+    'stores'  => [
+        'file' => [
+            // 驱动方式
+            'type'       => 'File',
+            // 缓存保存目录
+            'path'       => '',
+            // 缓存前缀
+            'prefix'     => '',
+            // 缓存有效期 0表示永久缓存
+            'expire'     => 0,
+            // 缓存标签前缀
+            'tag_prefix' => 'tag:',
+            // 序列化机制 例如 ['serialize', 'unserialize']
+            'serialize'  => [],
+        ],
+        // 更多的缓存连接
+        'redis' => [
+            'host'       => '127.0.0.1',
+            'port'       => 6379,
+            'type'       => 'redis',
+        ]
+    ],
+];

+ 12 - 0
app/api/config/redis.php

@@ -0,0 +1,12 @@
+<?php
+/**
+ * Created by PhpStorm
+ * User: 林志杰
+ * Email: [email protected]
+ * Time: 2020/1/12 20:48
+ */
+
+return [
+    'code_pre' => 'mall_code_pre_',
+    'code_expri' => 60,
+];

+ 3 - 0
app/common/business/Sms.php

@@ -22,6 +22,9 @@ class Sms
         $sms = AliSms::sendCode($phoneNumber, $code);
         if ($sms) {
             // 将验证码记录到redis,并设置失效时间
+            // 检查php环境是否有redis拓展
+            // redis服务
+            cache(config('redis.code_pre').$phoneNumber,$code,config('redis.expire'));
         }
         return true;
     }

+ 1 - 1
app/common/lib/sms/AliSms.php

@@ -53,7 +53,7 @@ class AliSms
                     ],
                 ])
                 ->request();
-            print_r($result->toArray());
+//            print_r($result->toArray());
         } catch (ClientException $e) {
             return false;
 //            echo $e->getErrorMessage() . PHP_EOL;