diff --git a/uniCloud/cloudfunctions/common/uni-im-utils/index.js b/uniCloud/cloudfunctions/common/uni-im-utils/index.js index 3f4a99df2c6e88d2a19f01779158e791e82abbd2..5e9739de94f5fcdd9c92f18598f0bdc0f70b783f 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 7fb55088455f5c215c0a1ebfafa3c49b5c641bce..bcc873b27141eb55d517f5a89420d310438dd9d5 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 dbd02a899ed427007fd2dc0dc4215ac8fa83ceac..e67913edb94aa508d7eeefdf432137d9604d58bd 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('账号未绑定手机号无法加入群聊。请完成绑定后退出本系统并重新登录,再尝试加入群聊。')