Bladeren bron

feat():授权

geek 4 jaren geleden
bovenliggende
commit
516a66c977

+ 10 - 4
application/index/controller/Index.php

@@ -10,6 +10,7 @@ namespace app\index\controller;
 use app\common\service\CommonService;
 use app\index\exception\ApiException;
 use app\index\model\UserModel;
+use app\index\model\VisitorModel;
 use think\console\command\make\Model;
 use think\facade\Cache;
 use think\facade\Session;
@@ -26,14 +27,19 @@ class Index {
         $data = CommonService::getSetData($channelId);
         $info = (new UserModel())::where(['unionid' => Session::get('wxId'), 'channel_id' => $channelId])->find();
         if (empty(Session::get('wxId')) || empty($info)){
-            Cache::set(Session::get('wxId'), '');
             header("Location:".CommonService::getAuthUrl($channelId));
             die();
         }
-        if (empty(Cache::get(Session::get('wxId')))) {
-            Cache::set(Session::get('wxId'), $visitorId);
+        $model = new VisitorModel();
+        $info = $model::where(['unionid' => Session::get('wxId')])->find();
+        if (empty($info)) {
+            $model::where(['unionid' => Session::get('wxId')])->insertGetId([
+                'visitorId' => $visitorId,
+                'unionid' => Session::get('wxId'),
+            ]);
+        } else {
+            $visitorId = $info['visitorId'];
         }
-        $visitorId = Cache::get(Session::get('wxId'));
         //        $params = [
 //            'id'     => $info['channel_id'],
 //            'userid' => $info['unionid'],

+ 1 - 0
application/index/controller/User.php

@@ -11,6 +11,7 @@ use app\common\service\CommonService;
 use app\index\BaseController;
 use app\index\exception\ApiException;
 use app\index\model\UserModel;
+use app\index\model\VisitorModel;
 use think\facade\Cache;
 use think\facade\Session;
 

+ 15 - 0
application/index/model/VisitorModel.php

@@ -0,0 +1,15 @@
+<?php
+/**
+ * Author: luzheng.liu
+ * Time: 2020/12/5 19:52
+ */
+
+namespace app\index\model;
+
+
+use think\Model;
+
+class VisitorModel  extends Model {
+
+    protected $table = 'visitor';
+}