From 35aa1bac9b8ca21eb00b05cca0aa1d0a28f38ce1 Mon Sep 17 00:00:00 2001 From: DCloud_JSON Date: Fri, 19 Apr 2024 17:59:49 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20=E6=9D=A1=E4=BB=B6?= =?UTF-8?q?=E7=BA=A6=E6=9D=9F=E5=8F=91=E6=B6=88=E6=81=AF=E5=92=8C=E5=8A=A0?= =?UTF-8?q?=E7=BE=A4=E5=BF=85=E9=A1=BB=E7=BB=91=E5=AE=9A=E6=89=8B=E6=9C=BA?= =?UTF-8?q?=E5=8F=B7=E7=A0=81=EF=BC=88=E7=89=B9=E6=AE=8A=E6=9D=83=E9=99=90?= =?UTF-8?q?=E9=99=A4=E5=A4=96=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- uniCloud/cloudfunctions/uni-im-co/msg.js | 21 ++++++++++++++++++- .../database/uni-im-group-join.schema.ext.js | 5 +++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/uniCloud/cloudfunctions/uni-im-co/msg.js b/uniCloud/cloudfunctions/uni-im-co/msg.js index 2d541a1..325a3dd 100644 --- a/uniCloud/cloudfunctions/uni-im-co/msg.js +++ b/uniCloud/cloudfunctions/uni-im-co/msg.js @@ -160,7 +160,7 @@ async function sendMsg(params) { // 创建新会话或者更新已有会话。 // 拿到消息接收者的isMute状态(仅私聊有效) - let {isMute} = await _createOrUpdateConversation(conversation_id, msgData) + let {isMute} = await _createOrUpdateConversation.call(this,conversation_id, msgData) // console.log({ // ...msgData, // conversation_id @@ -402,6 +402,25 @@ async function _createOrUpdateConversation(conversation_id, msgData) { // 不存在,需要先创建会话记录 if (!senderConversation) { + // 除了云函数之间(包括触发器)调用 和 特殊角色用户,需验证是否绑定了手机号码 + if( + this.getClientInfo().source != 'function' && + !this.current_user_role.includes('uni-im-admin') && + !this.current_user_role.includes('staff') + ){ + // 验证账号是否绑定了手机号 + let getUserInfoRes = await db.collection('uni-id-users') + .doc(this.current_uid) + .field({ + email:1, + nickname:1, + role:1 + }) + .get() + if(!getUserInfoRes.data[0].mobile_confirmed){ + throw new Error('账号未绑定手机号,无法发送消息') + } + } // 1.消息发送者 会话数据 senderConversation = { id: conversation_id, diff --git a/uniCloud/database/uni-im-group-join.schema.ext.js b/uniCloud/database/uni-im-group-join.schema.ext.js index 94d755d..2fc5054 100644 --- a/uniCloud/database/uni-im-group-join.schema.ext.js +++ b/uniCloud/database/uni-im-group-join.schema.ext.js @@ -54,6 +54,11 @@ module.exports = { if(res.code){ throw new Error(res.errMsg) } + } + // 5. 判断用户是否已经绑定手机号 + let res3 = await db.collection('uni-id-users').where({_id:userInfo.uid}).get() + if(!res3.data[0].mobile_confirmed){ + throw new Error('你的账号未绑定手机号,不能加入群聊') } } else { throw new Error('非法参数') -- GitLab