简介小程序聊天群,发语音、文字、图片(微信群发语音、图片)

本站:VPS评测参考推荐/专注分享VPS主机优惠信息!若您是商家可以在本站进行投稿,查看详情!此外我们还提供软文收录、PayPal代付、广告赞助等服务,查看详情!
我们发布的部分优惠活动文章可能存在时效性,购买时建议在本站搜索商家名称可查看相关文章充分了解该商家!若非中文页面可使用Edge浏览器同步翻译!PayPal代付/收录合作

可以创建群,邀请群成员,显示群成员列表,发送图片,设置群公告,踢人,禁所有人,禁个人,发送语音消息等功能。

效果图:

实施代码:

页面结构

ltview class = 博 gt ltview class = top _ bo gt lt视图bindtap = 数字 gt群({ { user number } });{ console . log( # 39;上传成功 # 39;,RES)let imgUrl = RES . fileid wx . cloud . call function({ name: ;新闻 ,// data: { // imgUrl: imgUrl // },data: { _qunId: qunId,_ openId:wx . getstoragesync( # 39;openId # 39),//消息正文: # 39;',//message img: imgur,//time dataTime: util.nowTime(),//avatar send outhand:wx . getstoragesync( # 39;userInfo # 39).avatarUrl,//昵称send outname:wx . getstoragesync( # 39;userInfo # 39).昵称},成功(RES){ console . log( # 39;图片发送成功 # 39;,res) },fail(RES){ console . log( # 39;退货失败 # 39;,res) } }) },}) },})})},onLoad:function(options){ console . log(options)that = this qunId = options . qunId this . on msg(options . qunId);that . user fun()that . forbidden()},//获取群成员user fun(){ db . collection( # 39;qunUserList # 39).where({ qunId: qunId })。get({ success:function(Res){ console . log(666666666,Res)that . setdata({ user number:Res . data . length,userlist: res.data}}}},//群公告notice(){ wx . show modal({ title: # 39;集团公告 # 39;,内容:this.data.userList[0]。qunTitle,showCancel: false,success(RES){ if(RES . confirm){//console . log( # 39;用户点击OK # 39}}}}},//发送消息sendout (e) {console.log (1111,e)let title = e . detail . value if(title = = # 39;'){ wx . show toast({ title: # 39;请输入聊天内容 # 39;,图标: # 39;无 # 39;,}) } else { var data = { _qunId: qunId,_ openId:wx . getstoragesync( # 39;openId # 39),//消息正文:标题,//消息img: # 39;',//time dataTime: util.nowTime(),//avatar send outhand:wx . getstoragesync( # 39;userInfo # 39).avatarUrl,//昵称send outname:wx . getstoragesync( # 39;userInfo # 39).昵称} console . log(data)wx . cloud . call function({ name: ;新闻 ,data: data,success(RES){ console . log( # 39;发送消息 # 39;,RES)that . setdata({ title: # 39;'}) },fail(RES){ console . log( # 39;登录失败 # 39;,res)}}},/* *用户点击右上角分享*/onshareappmessage:function(){ },//手指点击录音voice _ ing _ start:function(){ console . log( # 39;用手指点击录音 # 39;)wx . show toast({ title: # 39;按住录音并释放发送 # 39;,图标: # 39;无 # 39;})this . setdata({ voice _ ing _ start _ date:new date()。gettime(),//记录开始点击的时间}) constoptions = {duration: 10000,//指定记录的持续时间,单位ms sleRate: 8000,//采样率numberOfChannels: 1,//记录通道号encodibrate:24000,//编码比特率格式: # 39;mp3 # 39,//音频格式,有效值aac/mp3音频源: # 39;auto # 39,frameSize: 12,//以KB为单位指定帧大小} recorder.start(options) //开始录制this . animation = wx . create animation({ duration:1200,})//播放按钮动画this . animation . scale(0.8,0.8);//还原that . setdata({ spreading animation:that . animation . export()})},on ready:function(){ this . on _ recorder();},//记录监控事件on _ recorder:function(){ console . log( # 39;听事件 # 39;);recorder . onstart((RES)= gt;{ console . log( # 39;开始录制 # 39;);})recorder . onstop((RES)= gt;{ let { tempFilePath } = resconsole . log( # 39;停止录制,临时路径 # 39;,tempfile path);var x =新日期()。getTime()-this . data . voice _ ing _ start _ date if(x gt;1000) {让时间戳=新日期()。getTime();wx . cloud . uploadfile({ cloudPath: ;声音/ ;+时间戳+ # 39;. mp3 # 39,filePath: tempFilePath,success:RES = gt;{ console . log( # 39;上传成功 # 39;,RES)that . setdata({ sound URL:RES . fileid,})var data = { _ qunId: # 39;fb16 f 7905 E4 BFA 24009098 DC 34 b 910 c 8 # 39;,_ openId:wx . getstoragesync( # 39;openId # 39),//消息正文: # 39;',voice: res.fileID,img: # 39;',//time dataTime: util.nowTime(),//avatar send outhand:wx . getstoragesync( # 39;userInfo # 39).avatarUrl,//昵称send outname:wx . getstoragesync( # 39;userInfo # 39).昵称} console . log(data)wx . cloud . call function({ name: ;新闻 ,data: data,success(RES){ console . log( # 39;发送语音发送 # 39;,res) },fail(RES){ console . log( # 39;发送语音失败 # 39;,res) } }) },})} })recorder . onframerecorded((RES)= gt;{ return console . log( # 39;on frame recorded RES . frame buffer # 39;RES . frame buffer);string _ base64 = wx . arraybuffertobase 64(RES . frame buffer)console . log( # 39;string _ base64-- # 39;,string _ base64)}}},//释放录音voice _ ing _ end:function(){ console . log( # 39;松开手指进行录制 # 39;)that . setdata({ voice _ icon _ click:false,animation data:{ } })this . animation = ;";var x =新日期()。getTime()-this . data . voice _ ing _ start _ date if(x lt;1000){ console . log( # 39;停止录音,通话不到1秒!')wx . show modal({ title: # 39;提示 # 39;,内容: # 39;说话超过1秒!',})recorder . stop();} else {//录音停止,recorder.stop()开始上传;}},//点击语音图片voice _ icon _ Click:function(){ this . setdata({ voice _ icon _ Click:!This.data.voice _ icon _ click})}})以上是小程序聊天群的详情,发送语音、文字、图片。更多请关注本站其他相关文章!

本文由本站刊发,转载请注明:简介小程序聊天群,发语音、文字、图片(微信群发语音、图片) https://本站.com/79109.html

推荐站内搜索:美国防攻击服务器、高防美国服务器、香港服务器哪家快、免费代理服务器、香港服务器、香港云主机、icp备案、国外空间租用、移动服务器托管、ftp空间、