ソースを参照

h5登录接口

lizhen_gitee 1 年間 前
コミット
f12edad3d0
1 ファイル変更40 行追加1 行削除
  1. 40 1
      application/api/controller/User.php

+ 40 - 1
application/api/controller/User.php

@@ -20,7 +20,7 @@ use think\Db;
  */
 class User extends Api
 {
-    protected $noNeedLogin = ['login', 'onLogin', 'mobilelogin', 'register', 'resetpwd', 'changemobile', 'third', 'getUserOpenid', 'wxMiniProgramLogin','getNickName','wechatlogin','bindmobile'];
+    protected $noNeedLogin = ['login', 'onLogin', 'h5register', 'mobilelogin', 'register', 'resetpwd', 'changemobile', 'third', 'getUserOpenid', 'wxMiniProgramLogin','getNickName','wechatlogin','bindmobile'];
     protected $noNeedRight = '*';
 
     public function _initialize()
@@ -36,7 +36,46 @@ class User extends Api
         $this->success('', ['welcome' => $this->auth->nickname]);
     }
 
+    public function h5register()
+    {
+        $mobile = input('mobile');
+        $captcha = input('captcha');
+        $invite_no = input('invite_no','');
+
+        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) {
+            $this->error('该手机号已经注册过了');
+        } else {
+            $extend = [];
+            if(!empty($invite_no)){
+                $inviteUserInfo = \app\common\model\User::where(["invite_no" => $invite_no])->find();
+                if (!$inviteUserInfo) {
+                    //$this->error("查询不到该邀请码用户信息!");
+                }else{
+                    $extend['pre_userid'] = $inviteUserInfo['id'];
+                }
+
+            }
+
+
+            $ret = $this->auth->register($mobile, Random::alnum(), $mobile, $extend);
+        }
+        if ($ret) {
+            $this->success('注册成功');
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 
     /**
      * 手机验证码登录