allen 3 anos atrás
pai
commit
29f2c9f77f
2 arquivos alterados com 22 adições e 123 exclusões
  1. 8 95
      app/index/controller/Index.php
  2. 14 28
      app/index/view/index/index.html

+ 8 - 95
app/index/controller/Index.php

@@ -30,93 +30,19 @@ class Index extends Controller
 {
     public function index()
     {
-        FacadeLog::info("cookies:" . json_encode(Request::post()));
-        $sub = "";
-        $uid = 0;
-        FacadeLog::info($_COOKIE);
-        if (!empty($_COOKIE['SUB'])) {
+        FacadeLog::info("index cookies: ". json_encode($_COOKIE));
+        if (!empty($_COOKIE['SUB']) && strpos($_SERVER["HTTP_USER_AGENT"],"Weibo")) {
             $sub = $_COOKIE['SUB'];
+            $isWebo = 1;
         } else {
+            $isWebo = 0;
             // 只在调试模式下开启从POST参数中获取UID,方便测试联调
             if (env('app_debug')) {
                 $sub = Request::post('cookie');
-                $uid = $sub;
-            } else {
-                return $this->response(403, 'not login.');
-            }
-        }
-        FacadeLog::info($sub);
-        $userInfoRes = (new WeiboService($uid))->userinfo($sub);
-        if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
-            return $this->response(403, $userInfoRes['msg'] ?? '没有登录');
-        }
-
-        // 使用客户端信息生成token
-        $token = md5($_SERVER['HTTP_USER_AGENT'] . $_SERVER['HTTP_ACCEPT_ENCODING'] . $_SERVER['HTTP_ACCEPT_LANGUAGE'] . $_SERVER['HTTP_REFERER'] . get_client_ip(0) . $userInfoRes['data']['uid']);
-        $user = $userInfoRes['data'];
-
-        $userInfo = Db::table('awards_user_info')->where('uid', $user['uid'])->find();
-        $count = 0;
-        $isShare = 0;
-        if (empty($userInfo)) {
-            $userAttr = [
-                'uid' => $user['uid'],
-                'portrait' => $user['profile_image_url'],
-                'nickname' => $user['name'],
-                'is_share' => 0,
-                'count' => 1,
-                'create_at' => time()
-            ];
-            if (0 == Db::table('awards_user_info')->insert($userAttr)) {
-                return $this->response(5001, '系统错误,请稍后再试~');
             }
-        } else {
-            $count = Db::table('awards_user_task_log')->where('uid', $user['uid'])->count('id');
-            $isShare = $userInfo['is_share'];
         }
-
-        // 生成加密用的密钥和向量
-        $cipher = "aes-256-gcm";
-        $ivlen = openssl_cipher_iv_length($cipher);
-        $iv = bin2hex(openssl_random_pseudo_bytes($ivlen));
-        $aesKey = bin2hex(openssl_random_pseudo_bytes(32));
-        $user = array_merge($user, [
-            'aes_key' => $aesKey,
-            'ase_iv' => $iv,
-        ]);
-        $cacheUser = [
-            'aes_key' => $aesKey,
-            'ase_iv' => $iv,
-            'uid' => $user['uid'],
-        ];
-
-        $activity = Db::table('awards_activity')->where('begin_at', '<=', time())
-            ->where('end_at', '>=', time())->find();
-
-        $isBeginActivity = 1;
-        if (empty($activity)) {
-            $isBeginActivity = 0;
-        }
-
-        $userInfo = [];
-        if ($count > 0) {
-            $userInfo = Db::table('awards_user_task_log')->alias('l')
-                ->leftJoin('awards_user_info u', 'l.uid = u.uid')
-                ->field(['u.nickname', 'u.portrait', 'u.uid', 'l.duration', 'l.number'])
-                ->order('l.number', 'desc')
-                ->order('l.duration', 'asc')
-                ->find();
-        }
-
-        // 缓存用户信息1天
-        Cache::set('u:' . $token, json_encode($cacheUser), 86400);
-
-        $this->assign('user', $user);
-        $this->assign('token', $token);
-        $this->assign('isShare', $isShare);
-        $this->assign('count', $count);
-        $this->assign('isBeginActivity', $isBeginActivity);
-        $this->assign('task', $userInfo);
+        $this->assign('sub', $sub);
+        $this->assign('isWeibo', $isWebo);
 
         $this->fetch();
     }
@@ -149,22 +75,9 @@ class Index extends Controller
      */
     public function checkLogin()
     {
-        FacadeLog::info("cookies:" . json_encode(Request::post()));
-        $sub = "";
+        FacadeLog::info("checkLogin cookies:" . json_encode(Request::post()));
+        $sub = Request::post('cookie');
         $uid = 0;
-        FacadeLog::info($_COOKIE);
-        if (!empty($_COOKIE['SUB'])) {
-            $sub = $_COOKIE['SUB'];
-        } else {
-            // 只在调试模式下开启从POST参数中获取UID,方便测试联调
-            if (env('app_debug')) {
-                $sub = Request::post('cookie');
-                $uid = $sub;
-            } else {
-                return $this->response(403, 'not login.');
-            }
-        }
-        FacadeLog::info($sub);
         $userInfoRes = (new WeiboService($uid))->userinfo($sub);
         if (empty($userInfoRes) || $userInfoRes['ok'] != 1) {
             return $this->response(403, $userInfoRes['msg'] ?? '没有登录');

+ 14 - 28
app/index/view/index/index.html

@@ -192,35 +192,22 @@
     // 微博端判断
     var isWeibo = false;
     var ua = navigator.userAgent.toLowerCase();//获取判断用的对象
-    // if(window.location.host == 'local.sina.com'){
-    //     // 模拟本地微博端
-    //     isWeibo = true;
-    //     sub = getPara('sub');
-    // }else{
-    //      if (ua.match(/WeiBo/i) == "weibo") {
-    //         isWeibo = true;
-    //     } else {
-    //         showMessage('请使用微博客户端打开');
-    //         // onOpen();
-    //     }
-    // }
-
-    isWeibo = true;
-    sub = getPara('sub');
-    console.log("isWeibo = " + isWeibo)
-
-    var sub = '';
-
-    if(isWeibo){
-        // 微博端
-        sub = getCookie('SUB') || getCookie('sub');
-
-        if(window.location.host == 'local.sina.com'){
-            sub = getPara('sub');
-        }
-    }else{
+    if(window.location.host == 'local.sina.com'){
+        // 模拟本地微博端
+        isWeibo = true;
         sub = getPara('sub');
+    }else{
+         if (ua.match(/WeiBo/i) == "weibo") {
+            isWeibo = true;
+        } else {
+            showMessage('请使用微博客户端打开');
+            // onOpen();
+        }
     }
+
+    isWeibo = '<?php echo $isWeibo; ?>';
+    sub = '<?php echo $sub; ?>';
+    console.log("isWeibo = " + isWeibo)
     console.log('sub = ' + sub)
 
     // uid
@@ -229,7 +216,6 @@
         noLogin();
     }
 
-
     //未登录状态下跳转 scheme:
     function noLogin() {
         window.location.href = `sinaweibo://login?redirect_scheme=${(encodeURIComponent(location.href))} `;