dever 3 years ago
parent
commit
5b775eb5de
3 changed files with 44 additions and 13 deletions
  1. 16 0
      database/code.php
  2. 4 4
      database/system.php
  3. 24 9
      lib/Base.php

+ 16 - 0
database/code.php

@@ -91,4 +91,20 @@ return array
 			'list'		=> 'date("Y-m-d H:i:s", {cdate})',
 		),
 	),
+
+	'request' => array
+    (
+        'getNew' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'day' => 'yes',
+                'mobile' => 'yes',
+                'state' => 1,
+            ),
+            'type' => 'one',
+            'order' => array('id' => 'desc'),
+        ),
+    ),
 );

+ 4 - 4
database/system.php

@@ -49,9 +49,9 @@ return array
 		'appid'		=> array
 		(
 			'type' 		=> 'varchar-150',
-			'name' 		=> '微信appid',
+			'name' 		=> '微信小程序appid',
 			'default' 	=> '',
-			'desc' 		=> '请输入微信appid',
+			'desc' 		=> '请输入微信小程序appid',
 			'match' 	=> 'option',
 			'search'	=> 'order,fulltext',
 			'update'	=> 'text',
@@ -62,9 +62,9 @@ return array
 		'secret'		=> array
 		(
 			'type' 		=> 'varchar-150',
-			'name' 		=> '微信secret',
+			'name' 		=> '微信小程序secret',
 			'default' 	=> '',
-			'desc' 		=> '请输入微信secret',
+			'desc' 		=> '请输入微信小程序secret',
 			'match' 	=> 'option',
 			'search'	=> 'order,fulltext',
 			'update'	=> 'text',

+ 24 - 9
lib/Base.php

@@ -15,12 +15,17 @@ class Base
 
     const MCODE = 'mcode';
 
-    protected $save;
+    protected $save = false;
+    protected $save_type = 'session';
 
     public function __construct()
     {
         //$this->save = new Save(false, 'cookie');
-        $this->save = new Save(false, 'session');
+        $save_type = $this->save_type = Dever::config('base', 'project')->mobileCode['save'];
+        if ($this->save_type == 'db') {
+            $save_type = 'session';
+        }
+        $this->save = new Save(false, $save_type);
     }
 
     # 返回加密的用户信息
@@ -465,22 +470,30 @@ class Base
 
     protected function mcode($mobile, $code = false)
     {
-        if ($code) {
-            $save = $this->save->get(self::MCODE);
-            return $mobile . '_' . $code == $save;
-        }
-
         $day = date('Ymd', time());
 
         # 检测当前手机号最新一次发送时间,不允许一分钟之内发送
         $param['option_day'] = $day;
         $param['option_mobile'] = $mobile;
 
+        if ($code) {
+            if ($this->save_type == 'db') {
+                $check = Dever::db('passport/code')->getNew($param);
+                if ($check) {
+                    return $check['mobile'] . '_' . $check['code'] == $save;
+                }
+                return false;
+            } else {
+                $save = $this->save->get(self::MCODE);
+                return $mobile . '_' . $code == $save;
+            }
+        }
+
         # 检测当前手机号今天已经发送多少验证码了
         $info = Dever::load('passport/code-total', $param);
 
         if ($info >= 1) {
-            $check = Dever::load('passport/code-one', $param);
+            $check = Dever::db('passport/code')->getNew($param);
 
             if ($check) {
                 if (time() - $check['cdate'] < Dever::config('base', 'project')->mobileCode['time']) {
@@ -506,7 +519,9 @@ class Base
         # 启动发送
         $this->send($mobile, $insert['add_code'], $id);
 
-        $this->save->add(self::MCODE, $mobile . '_' . $code->mcode, Dever::config('base', 'project')->mobileCode['timeout']);
+        if ($this->save_type != 'db') {
+            $this->save->add(self::MCODE, $mobile . '_' . $code->mcode, Dever::config('base', 'project')->mobileCode['timeout']);
+        }
 
         return $code->mcode;
     }