Browse Source

增加后台site存redis和增加IMuserid前缀

panda 4 months ago
parent
commit
521134362e

+ 11 - 0
application/common.php

@@ -100,6 +100,17 @@ if (!function_exists('cdnurl')) {
     }
 }
 
+/**
+ * 自动拼im id前缀
+ * @param $user_id
+ * @return mixed
+ */
+if (!function_exists('im_prefix')) {
+    function im_prefix($user_id)
+    {
+        return config('tencent_im.chat_prefix').$user_id;
+    }
+}
 
 if (!function_exists('is_really_writable')) {
 

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

@@ -26,7 +26,7 @@ class Auth
     //默认配置
     protected $config = [];
     protected $options = [];
-    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar'];
+    protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'group_id'];
 
     public function __construct($options = [])
     {
@@ -390,7 +390,7 @@ class Auth
         $userinfo = array_merge($userinfo, Token::get($this->_token));
 
         $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
-
+        $userinfo['chat_id'] = im_prefix($userinfo['id']);
         return $userinfo;
     }
     public function getUserinfo()
@@ -401,7 +401,7 @@ class Auth
         $userinfo = array_merge($userinfo, Token::get($this->_token));
 
         $userinfo['avatar'] = localpath_to_netpath($userinfo['avatar']);
-
+        $userinfo['chat_id'] = im_prefix($userinfo['id']);
         return $userinfo;
     }
 

+ 6 - 0
application/common/model/Config.php

@@ -2,6 +2,8 @@
 
 namespace app\common\model;
 
+use app\utils\RedisKeyEnum;
+use app\utils\RedisUtil;
 use think\Model;
 
 /**
@@ -225,6 +227,10 @@ class Config extends Model
             }
             $config[$value['name']] = $value['value'];
         }
+        // 记录数据到redis
+        if (!RedisUtil::getInstance(RedisKeyEnum::FA_SITE_SETUP)->set(json_encode($config, JSON_UNESCAPED_UNICODE))){
+            return false;
+        }
         file_put_contents(
             CONF_PATH . 'extra' . DS . 'site.php',
             '<?php' . "\n\nreturn " . var_export_short($config) . ";\n"

+ 1 - 8
application/config.php

@@ -332,13 +332,6 @@ return [
         'secret_key' => "",
     ],
 
-    //环信 IM
-    'easemob' => [
-        'appkey'        => '',
-        'client_id'     => '',
-        'client_secret' => '',
-    ],
-
     //微信小程序 鲁享途中
     'wxMiniProgram' => [
         'appid'  => 'wx9a7153e5b40d9663',
@@ -349,12 +342,12 @@ return [
     'tencent_im' => [
         'sdkappid' => '',
         'identifier' => '',
-
         //trtc回调秘钥
         'callback_secret' => '',
         'key' => '',
         'SecretId' => '',
         'SecretKey' => '',
+        'chat_prefix' => Env::get('tencent_im.IM_CHAT_PREFIX','im'),
     ],
 
     //阿里云短信配置