瀏覽代碼

批量注册

lizhen_gitee 3 月之前
父節點
當前提交
3381b69da8

+ 41 - 0
application/api/controller/Demo.php

@@ -7,6 +7,8 @@ use think\Db;
 use app\common\library\Uploadvideo;
 use app\utils\RedisKeyEnum;
 use app\utils\RedisUtil;
+use think\Validate;
+use app\common\library\Sms;
 /**
  * 示例接口
  */
@@ -65,4 +67,43 @@ class Demo extends Api
 
     }
 
+
+    //////////////////////////////////////////////////////
+    private function getmobile(){
+        $start = 19300000000;
+        $mobile = RedisUtil::getInstance(RedisKeyEnum::MOBILE_REGISTER)->incr();
+        return $start + $mobile;
+    }
+
+    public function auto_register()
+    {
+        $mobile = $this->getmobile();
+        $captcha = '1212';
+        if (!$mobile || !$captcha) {
+            $this->error(__('Invalid parameters'));
+        }
+        if (!Validate::regex($mobile, "^1\d{10}$")) {
+            $this->error(__('Mobile is incorrect'));
+        }
+        if (!Sms::check($mobile, $captcha, 'mobilelogin')) {
+            $this->error(__('Captcha is incorrect'));
+        }
+        $user = \app\common\model\User::getByMobile($mobile);
+        if ($user) {
+            if ($user->status != 1) {
+                $this->error(__('Account is locked'));
+            }
+            //如果已经有账号则直接登录
+            $ret = $this->auth->direct($user->id);
+        } else {
+            $ret = $this->auth->register('', '', '', $mobile, []);
+        }
+        if ($ret) {
+            Sms::flush($mobile, 'mobilelogin');
+            $this->success(__('Logged in successful'), $this->auth->getUserinfo());
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
+
 }

+ 0 - 4
application/api/controller/User.php

@@ -61,10 +61,6 @@ class User extends Api
     }
 
 
-
-
-
-
     /**
      * 退出登录
      * @ApiMethod (POST)

+ 1 - 0
application/utils/RedisKeyEnum.php

@@ -16,4 +16,5 @@ class RedisKeyEnum
     const VOTE_RECORD              = 'VOTE_RECORD:';                     //用户今天投票次数
     const EAXM_TIMES               = 'EAXM_TIMES:';                     //用户今天答题次数
     const EAXM_RIGHT               = 'EAXM_RIGHT:';                     //用户今天答对次数
+    const MOBILE_REGISTER          = 'MOBILE_REGISTER:';                     //手机注册机
 }

+ 7 - 0
application/utils/RedisUtil.php

@@ -364,6 +364,13 @@ class RedisUtil
         return $redis->hGetAll($key);
     }
 
+    public function incr()
+    {
+        $redis = $this->Redis;
+        $key   = $this->Key;
+        return $redis->incr($key);
+    }
+
     public function incrby_expire($num,$second)
     {
         $redis = $this->Redis;