Browse Source

changestatus

lizhen_gitee 3 years ago
parent
commit
0e7edd9bad
3 changed files with 34 additions and 3 deletions
  1. 25 2
      application/chat/Events.php
  2. 1 1
      application/database.php
  3. 8 0
      thinkphp/helper.php

+ 25 - 2
application/chat/Events.php

@@ -35,7 +35,7 @@ class Events
 
         App::initCommon();
 
-        /*$info = Db::name('mt_admin')->find(1);
+        /*$info = Db::name('admin')->find(1);
         dump($info);*/
 
     }
@@ -47,9 +47,32 @@ class Events
      */
     public static function onMessage($client_id, $message)
     {
-        dump($message);
+        $message = json_decode($message,true);
+        if($message['action'] == 'changestatus'){
+            self::changestatus($message);
+        }else{
+            echo 'default';
+            dump($message);
+        }
         return ;
     }
+
+
+	/*{
+        'action':'changestatus',
+         "uid": "1",
+         "type": "video",'audio'
+         "value": "0",或‘1’
+         "nowtime": "1234567890 ",
+         "token": "edbf8a75-8e36-41f5-989f-7b3d067ccc83"
+    }*/
+    private static function changestatus($message){
+        //dump($message);
+        if(isset($message['uid']) && isset($message['value'])){
+            redis_set($message['uid'],$message['value']);
+        }
+        return;
+    }
    
     /**
      * 当客户端断开连接时

+ 1 - 1
application/database.php

@@ -29,7 +29,7 @@ return [
     // 数据库编码默认采用utf8
     'charset'         => 'utf8',
     // 数据库表前缀
-    'prefix'          => '',
+    'prefix'          => 'mt_',
     // 数据库调试模式
     'debug'           => true,
     // 数据库部署方式:0 集中式(单一服务器),1 分布式(主从服务器)

+ 8 - 0
thinkphp/helper.php

@@ -350,6 +350,14 @@ if (!function_exists('cache')) {
      * @param string    $tag 缓存标签
      * @return mixed
      */
+    function redis_set($name,$value,$expire = null){
+        $cache = Cache::connect(['type'=>'Redis']);
+        return $cache->set('mt_matching_uid_'.$name, $value, $expire);
+    }
+    function redis_get($name){
+        $cache = Cache::connect(['type'=>'Redis']);
+        return $cache->get('mt_matching_uid_'.$name);
+    }
     function cache($name, $value = '', $options = null, $tag = null)
     {
         if (is_array($options)) {