差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版 两侧同时换到之后的修订记录
im:applet:message [2019/11/06 02:59]
zhangdong
im:applet:message [2019/11/06 03:09]
zhangdong
行 384: 行 384:
 <code javascript>​ <code javascript>​
 // 单聊发送音频消息 // 单聊发送音频消息
-var sendPrivateAudio = function ​() { +uploadRecord(tempFilePath,​ dur){ 
-    var id conn.getUniqueId();                   // 生成本地消息id +    var str WebIM.config.appkey.split("#"​); 
-    var msg new WebIM.message('​audio',​ id)     // 创建音频消息 +    var me this
-    var input document.getElementById('​audio'​);  ​// 选择音频的input +    var token WebIM.conn.context.accessToken 
-    var file = WebIM.utils.getFileUrl(input); ​     ​// 将音频转化为二进制文件 +    wx.uploadFile(
-    var allowType = { +        url: "​https:​//a1.easemob.com/" + str[0] + "/" + str[1] + "/​chatfiles",​ 
-        ​'​mp3'​true+        ​filePathtempFilePath
-        ​'​amr'​true+        ​name"​file"​
-        ​'​wmv'​true +        ​header{ 
-    }; +            "​Content-Type":​ "​multipart/​form-data",​ 
-    ​if ​(file.filetype.toLowerCase() in allowType{ +            Authorization:​ "​Bearer " + token 
-        var option ​{ +        ​}, 
-            apiUrl: WebIM.config.apiURL,​ +        ​success(res){ 
-            filefile+            var id = WebIM.conn.getUniqueId()
-            to'​username'​                      ​// 接收消息对象 +            var msg = new WebIM.message(msgType.AUDIO,​ id); 
-            ​roomTypefalse+            var dataObj ​JSON.parse(res.data);​ 
-            ext{}                             // 扩展消息 +            ​msg.set({ 
-            ​onFileUploadErrorfunction () {      // 消息上传失败 +                ​apiUrl: WebIM.config.apiURL,​ 
-                ​console.log('​onFileUploadError'​); +                ​accessTokentoken
-            }, +                body
-            ​onFileUploadCompletefunction () {   // 消息上传成功 +                    type: msgType.AUDIO, 
-                ​console.log('​onFileUploadComplete'​); +                    url: dataObj.uri + "/" + dataObj.entities[0].uuid,​ 
-            }+                    ​filetype""​
-            success: function () {                // 消息发送成功 +                    ​filenametempFilePath
-                ​console.log('Success'); +                    ​accessTokentoken, 
-            }, +                    ​length:​ Math.ceil(dur / 1000
-            ​flashUpload:​ WebIM.flashUpload +                }, 
-        }+                fromme.data.username.myName,​ 
-        msg.set(option); +                ​to: me.getSendToParam(), 
-        conn.send(msg.body);​ +                ​roomType:​ false
-    }+                ​chatType:​ me.data.chatType,​ 
 +                ​success: function (argument) { 
 +                    disp.fire('em.chat.sendSuccess', id); 
 +                
 +           }); 
 +           if(me.isGroupChat()){ 
 +               msg.setGroup("​groupchat"​)
 +           } 
 +           msg.body.length = Math.ceil(dur / 1000); 
 +           //​console.log('​发送的语音消息',​ msg.body) 
 +           ​WebIM.conn.send(msg.body);​ 
 +       ​} 
 +   });
 }; };
 </​code>​ </​code>​