From 0fe5bd2bd385a3e5cc9939afe21b983f1ab3d2cb Mon Sep 17 00:00:00 2001 From: linju Date: Thu, 7 Nov 2024 20:19:47 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20=E6=96=B0=E5=A2=9E?= =?UTF-8?q?=E9=85=8D=E7=BD=AEcheck=5Fmobile=EF=BC=8C=E7=94=A8=E4=BA=8E?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=9C=A8=E5=8F=91=E8=B5=B7=E4=BC=9A=E8=AF=9D?= =?UTF-8?q?=E5=92=8C=E7=94=B3=E8=AF=B7=E5=8A=A0=E5=85=A5=E7=BE=A4=E8=81=8A?= =?UTF-8?q?=E6=97=B6=EF=BC=8C=E6=98=AF=E5=90=A6=E6=A0=A1=E9=AA=8C=E6=89=8B?= =?UTF-8?q?=E6=9C=BA=E5=8F=B7=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniCloud/cloudfunctions/common/uni-im-utils/index.js | 12 +++++++++++- uniCloud/cloudfunctions/uni-im-co/msg.js | 2 ++ uniCloud/database/uni-im-group-join.schema.ext.js | 7 +++---- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/uniCloud/cloudfunctions/common/uni-im-utils/index.js b/uniCloud/cloudfunctions/common/uni-im-utils/index.js index 3f4a99d..5e9739d 100644 --- a/uniCloud/cloudfunctions/common/uni-im-utils/index.js +++ b/uniCloud/cloudfunctions/common/uni-im-utils/index.js @@ -5,6 +5,15 @@ const dbCmd = db.command const $ = dbCmd.aggregate const md5 = str => crypto.createHash('md5').update(str).digest('hex') +function getConfig(key) { + // 获取 uni-im 配置 + const createConfig = require("uni-config-center"); + const uniImConfig = createConfig({ + pluginId: 'uni-im', // 插件 id + }) + return uniImConfig.config(key) +} + function getConversationId({ group_id, from_uid, @@ -77,5 +86,6 @@ module.exports = { hideUsernameStr, hideEmailStr, hideMobileStr, - checkParam + checkParam, + getConfig } \ No newline at end of file diff --git a/uniCloud/cloudfunctions/uni-im-co/msg.js b/uniCloud/cloudfunctions/uni-im-co/msg.js index 7fb5508..bcc873b 100644 --- a/uniCloud/cloudfunctions/uni-im-co/msg.js +++ b/uniCloud/cloudfunctions/uni-im-co/msg.js @@ -439,7 +439,9 @@ async function _createOrUpdateConversation(conversation_id, msgData, chat_source // 不存在,需要先创建会话记录 else if (!senderConversation) { // 除了云函数之间(包括触发器)调用 和 特殊角色用户,需验证是否绑定了手机号码 + const check_mobile = uniImConfig.config('check_mobile') if ( + check_mobile && this.getClientInfo().source != 'function' && !this.current_user_role.includes('uni-im-admin') && !this.current_user_role.includes('staff') diff --git a/uniCloud/database/uni-im-group-join.schema.ext.js b/uniCloud/database/uni-im-group-join.schema.ext.js index dbd02a8..e67913e 100644 --- a/uniCloud/database/uni-im-group-join.schema.ext.js +++ b/uniCloud/database/uni-im-group-join.schema.ext.js @@ -1,7 +1,6 @@ // schema扩展相关文档请参阅:https://uniapp.dcloud.net.cn/uniCloud/jql-schema-ext.html const db = uniCloud.database() -let t = Date.now() + parseInt(Math.random() * 999999) - +const utils = require('uni-im-utils') module.exports = { trigger: { async beforeCreate({ @@ -56,8 +55,8 @@ module.exports = { throw new Error('你已被拉黑,不能加入此群') } // 4. 判断用户是否已经绑定手机号,系统管理员除外 - console.log('userInfo',userInfo); - if(!userInfo.role.includes('uni-im-admin') && !userInfo.role.includes('staff')){ + const check_mobile = utils.getConfig('check_mobile') + if(check_mobile && !userInfo.role.includes('uni-im-admin') && !userInfo.role.includes('staff')){ let res3 = await db.collection('uni-id-users').where({_id:userInfo.uid}).get() if(!res3.data[0].mobile_confirmed){ throw new Error('账号未绑定手机号无法加入群聊。请完成绑定后退出本系统并重新登录,再尝试加入群聊。') -- GitLab