Browse Source

新的盒子用户登录方式

lizhen_gitee 9 months ago
parent
commit
0ad8fe4fac

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

@@ -16,7 +16,7 @@ use app\common\library\Wechat;
  */
 class User extends Api
 {
-    protected $noNeedLogin = ['login', 'mobilelogin', 'wechatlogin', 'bindmobile','register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
+    protected $noNeedLogin = ['login', 'mobilelogin', 'tvuser_login', 'wechatlogin', 'bindmobile','register', 'resetpwd', 'changeemail', 'changemobile', 'third'];
     protected $noNeedRight = '*';
 
     public function _initialize()
@@ -213,6 +213,49 @@ class User extends Api
 
     }
 
+    //电视盒子用户登录。
+    public function tvuser_login(){
+        $tv_userid   = input('tv_userid','');
+        $tv_mobile   = input('tv_mobile','');
+        $tv_signtime = input('tv_signtime','');
+        $tv_sign     = input('tv_sign','');
+        if(empty($tv_userid) || empty($tv_mobile) || empty($tv_signtime) || empty($tv_sign)){
+            $this->error('登录参数缺失');
+        }
+
+        //验签
+        $salt = 'be7bcf1499b0fec801406f6aafbd04c4';
+        $get_sign = md5(md5($tv_userid) . $tv_signtime . $salt);
+        if($tv_sign != $get_sign){
+            $this->error('验签失败');
+        }
+        if(time() - $tv_signtime > 300){
+            //测试临时屏蔽
+            $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 {
+            $extend = ['tv_mobile'=>$tv_mobile];
+            $ret = $this->auth->tv_register($tv_userid,$extend);
+        }
+
+        if ($ret) {
+            $this->success(__('Logged in successful'), $this->auth->getUserinfo_simple());
+        } else {
+            $this->error($this->auth->getError());
+        }
+    }
 
     //用户详细资料
     public function userInfo(){

+ 2 - 4
application/api/controller/tvuser/Tvdoctor.php

@@ -2,12 +2,12 @@
 
 namespace app\api\controller\tvuser;
 
-use app\common\controller\Apitv;
+use app\common\controller\Api;
 use think\Db;
 /**
  * 首页接口
  */
-class Tvdoctor extends Apitv
+class Tvdoctor extends Api
 {
     protected $noNeedLogin = ['*'];
     protected $noNeedRight = ['*'];
@@ -104,8 +104,6 @@ class Tvdoctor extends Apitv
         $this->success(1,$newlist);
     }
 
-
-
     //关注某人,取关
     public function follow_one(){
         $follow_uid = input('doctor_id',0);

+ 3 - 3
application/common/library/Auth.php

@@ -239,7 +239,7 @@ class Auth
         }
         return true;
     }
-    public function tv_register($tv_userid = '')
+    public function tv_register($tv_userid = '',$extend = [])
     {
         if(empty($tv_userid)){
             $this->setError('盒子用户id必填');
@@ -256,7 +256,7 @@ class Auth
 
         $data = [
             'tv_userid' => $tv_userid,
-            'nickname'  => '盒子用户',
+            'nickname'  => '电视盒子用户',
             'comefrom'  => 2,
             'avatar'    => config('site.user_default_avatar'),
         ];
@@ -268,7 +268,7 @@ class Auth
             'prevtime'  => $time,
             'status'    => 1
         ]);
-
+        $params = array_merge($params, $extend);
         //账号注册时需要开启事务,避免出现垃圾数据
         Db::startTrans();
         try {