Candy 6 lat temu
rodzic
commit
0474c3c67a
1 zmienionych plików z 36 dodań i 0 usunięć
  1. 36 0
      thinkphp/application/index/controller/ApiCommon.php

+ 36 - 0
thinkphp/application/index/controller/ApiCommon.php

@@ -0,0 +1,36 @@
+<?php
+/**
+ * Created by PhpStorm.
+ * User: Titan 名字就是密码
+ * Date: 2019/6/4
+ * Time: 17:02
+ */
+
+namespace app\index\controller;
+
+
+use think\Controller;
+use think\Request;
+
+class ApiCommon extends Controller
+{
+    public function _initialize()
+    {
+        parent::_initialize();
+        /*获取头部信息*/
+
+        $header = Request::instance()->header();
+
+        if(!isset($header['authkey'])){
+            header('Content-Type:application/json; charset=utf-8');
+            exit(json_encode(['code'=>103, 'error'=>'非法操作'],JSON_UNESCAPED_UNICODE));
+        }
+        $authKey = $header['authkey'];
+        $cache = cache('Auth_'.$authKey);
+        if(empty($authKey) || empty($cache)){
+            header('Content-Type:application/json; charset=utf-8');
+            exit(json_encode(['code'=>103, 'error'=>'登录已失效'],JSON_UNESCAPED_UNICODE));
+        }
+        cache('Auth_'.$authKey, $cache, 7200);
+    }
+}