Browse Source

电视盒子用户自动登录+注册

lizhen_gitee 9 months ago
parent
commit
595ca4cb3f
1 changed files with 41 additions and 20 deletions
  1. 41 20
      application/common/controller/Apitv.php

+ 41 - 20
application/common/controller/Apitv.php

@@ -79,16 +79,6 @@ class Apitv
     {
         $this->request = is_null($request) ? Request::instance() : $request;
 
-        if(config('site.apisite_switch') == 0){
-            $controllername = $this->request->controller();
-            $controllername = strtolower($controllername);
-
-            if(!in_array($controllername,['notify','easemob','payios'])){
-                $notice = config('site.apisite_notice') ?: '全站维护中';
-                $this->error($notice);
-            }
-        }
-
         // 控制器初始化
         $this->_initialize();
         //日志
@@ -104,6 +94,43 @@ class Apitv
         }
     }
 
+    //电视盒子用户登录
+    private function tvuser_login(){
+        $tv_userid = input('tv_userid','');
+        $tv_sign   = input('tv_sign','');
+        if(empty($tv_userid) || empty($tv_sign)){
+            $this->error('登录参数缺失');
+        }
+
+        //验签
+        $salt = '123456';
+        $get_sign = md5(md5($tv_userid) . $salt);
+        if($tv_sign != $get_sign){
+            $this->error('验签失败');
+        }
+
+        //找到用户
+        $user = Db::name('user')->where('tv_userid',$tv_userid)->find();
+        if ($user) {
+            if ($user['status'] == -1) {
+                $this->error('账号已注销');
+            }
+            if ($user['status'] != 1) {
+                $this->error(__('Account is locked'));
+            }
+            //如果已经有账号则直接登录
+            $ret = $this->auth->direct($user['id']);
+        } else {
+            $ret = $this->auth->tv_register($tv_userid);
+        }
+
+        if ($ret) {
+
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
+
     /**
      * 初始化操作
      * @access protected
@@ -126,7 +153,8 @@ class Apitv
         $actionname = strtolower($this->request->action());
 
         // token
-        $token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
+        //$token = $this->request->server('HTTP_TOKEN', $this->request->request('token', \think\Cookie::get('token')));
+        $this->tvuser_login();
 
         $path = str_replace('.', '/', $controllername) . '/' . $actionname;
         // 设置当前请求的URI
@@ -134,7 +162,7 @@ class Apitv
         // 检测是否需要验证登录
         if (!$this->auth->match($this->noNeedLogin)) {
             //初始化
-            $this->auth->init($token);
+            //$this->auth->init($token);
             //检测是否登录
             if (!$this->auth->isLogin()) {
                 $this->error(__('Please login first'), null, 401);
@@ -147,14 +175,7 @@ class Apitv
                 }
             }*/
         } else {
-            // 如果有传递token才验证是否登录状态
-            if ($token) {
-                $this->auth->init($token);
-                //传就必须传对
-                if (!$this->auth->isLogin()) {
-                    $this->error(__('Please login first'), null, 401);
-                }
-            }
+            
         }
 
         $upload = \app\common\model\Config::upload();