差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 后一修订版 两侧同时换到之后的修订记录 | ||
im:web:basics:message [2019/07/04 02:11] zhangdong |
im:web:basics:message [2019/12/03 06:57] lizg [接收消息] |
||
---|---|---|---|
行 25: | 行 25: | ||
</code> | </code> | ||
+ | **注意:** 发送ext 扩展消息,可以没有这个字段,但是如果有,值不能是“ext:null”这种形式,否则出错 | ||
===== 发送消息 ===== | ===== 发送消息 ===== | ||
行 33: | 行 34: | ||
* 贴图消息 | * 贴图消息 | ||
+ | | ||
+ | * URL图片消息 | ||
| | ||
* 命令消息 | * 命令消息 | ||
行 51: | 行 54: | ||
msg: 'message content', // 消息内容 | msg: 'message content', // 消息内容 | ||
to: 'username', // 接收消息对象(用户id) | to: 'username', // 接收消息对象(用户id) | ||
- | roomType: false, | + | roomType: false, |
+ | ext: {}, //扩展消息 | ||
success: function (id, serverMsgId) { | success: function (id, serverMsgId) { | ||
console.log('send private text Success'); | console.log('send private text Success'); | ||
行 74: | 行 78: | ||
to: 'group id', // 接收消息对象(群组id) | to: 'group id', // 接收消息对象(群组id) | ||
roomType: false, // 群聊类型,true时为聊天室,false时为群组 | roomType: false, // 群聊类型,true时为聊天室,false时为群组 | ||
+ | ext: {}, // 扩展消息 | ||
success: function () { | success: function () { | ||
console.log('send room text success'); | console.log('send room text success'); | ||
行 98: | 行 103: | ||
to: 'chatroom id', // 接收消息对象(聊天室id) | to: 'chatroom id', // 接收消息对象(聊天室id) | ||
roomType: true, // 群聊类型,true时为聊天室,false时为群组 | roomType: true, // 群聊类型,true时为聊天室,false时为群组 | ||
+ | ext: {}, // 扩展消息 | ||
success: function () { | success: function () { | ||
console.log('send room text success'); | console.log('send room text success'); | ||
行 213: | 行 219: | ||
} | } | ||
}); | }); | ||
+ | </code> | ||
+ | |||
+ | === API === | ||
+ | 示例中使用到的 API | ||
+ | * [[http://webim-h5.easemob.com/jsdoc/out/connection.html#getUniqueId|getUniqueId]] | ||
+ | | ||
+ | * [[http://webim-h5.easemob.com/jsdoc/out/connection.html#send|send]] | ||
+ | |||
+ | ---- | ||
+ | ==== 发送URL图片消息 ==== | ||
+ | |||
+ | * 示例代码为单聊,贴图发送至群组和聊天室时需参考**发送文本消息**修改''roomType''和''msg.setGroup('groupchat')''。 | ||
+ | |||
+ | 单聊通过URL发送图片消息的代码示例如下: | ||
+ | <code javascript> | ||
+ | // 单聊通过URL发送图片消息 | ||
+ | var sendPrivateUrlImg = function () { | ||
+ | var id = conn.getUniqueId(); // 生成本地消息id | ||
+ | var msg = new WebIM.default.message('img', id); // 创建图片消息 | ||
+ | var option = { | ||
+ | body: { | ||
+ | type: 'file', | ||
+ | url: url, | ||
+ | size: { | ||
+ | width: msg.width, | ||
+ | height: msg.height, | ||
+ | }, | ||
+ | length: msg.length, | ||
+ | filename: msg.file.filename, | ||
+ | filetype: msg.filetype | ||
+ | }, | ||
+ | to: 'username', // 接收消息对象 | ||
+ | }; | ||
+ | msg.set(option); | ||
+ | conn.send(msg.body); | ||
+ | } | ||
</code> | </code> | ||
行 230: | 行 272: | ||
msg.set({ | msg.set({ | ||
msg: 'msg', | msg: 'msg', | ||
- | to: 'username', //接收消息对象 | + | to: 'username', //接收消息对象 |
- | action : 'action' //用户自定义,cmd消息必填 | + | action : 'action', //用户自定义,cmd消息必填 |
- | ext :{'extmsg':'extends messages'} //用户自扩展的消息内容(群聊用法相同) | + | ext :{'extmsg':'extends messages'}, //用户自扩展的消息内容(群聊用法相同) |
- | success: function ( id,serverMsgId ) {}//消息发送成功回调 | + | success: function ( id,serverMsgId ) {}//消息发送成功回调 |
}); | }); | ||
行 432: | 行 474: | ||
/** | /** | ||
* 发送撤回消息 | * 发送撤回消息 | ||
- | * @param {Object} option - | + | * @param {Object} option - |
* @param {Object} option.mid - 回撤消息id | * @param {Object} option.mid - 回撤消息id | ||
* @param {Object} option.to - 消息的接收方 | * @param {Object} option.to - 消息的接收方 | ||
+ | * @param {Object} option.type - chat(单聊) groupchat(群组) chatroom(聊天室) | ||
*/ | */ | ||
WebIM.conn.recallMessage(option) | WebIM.conn.recallMessage(option) | ||
行 480: | 行 523: | ||
console.log(list); | console.log(list); | ||
}, | }, | ||
+ | recallMessage: function( message ){}, //收到消息撤回回执 | ||
onReceivedMessage: function(message){}, //收到消息送达服务器回执 | onReceivedMessage: function(message){}, //收到消息送达服务器回执 | ||
onDeliveredMessage: function(message){}, //收到消息送达客户端回执 | onDeliveredMessage: function(message){}, //收到消息送达客户端回执 | ||
行 573: | 行 617: | ||
===== 拉取历史消息 ===== | ===== 拉取历史消息 ===== | ||
- | SDK增值服务。 | + | 漫游消息,SDK增值功能。 |
<code javascript> | <code javascript> | ||
/** | /** | ||
* 获取对话历史消息 | * 获取对话历史消息 | ||
* @param {Object} options | * @param {Object} options | ||
- | * @param {String} options.queue - 对方用户名Id | + | * @param {String} options.queue - 对方用户id(如果用户id内含有大写字母请改成小写字母)/群组id/聊天室id |
* @param {String} options.count - 每次拉取条数 | * @param {String} options.count - 每次拉取条数 | ||
+ | * @param {Boolean} options.isGroup - 是否是群聊,默认为false | ||
* @param {Function} options.success | * @param {Function} options.success | ||
* @param {Funciton} options.fail | * @param {Funciton} options.fail | ||
*/ | */ | ||
+ | var options = { | ||
+ | queue: "test1", | ||
+ | isGroup: false, | ||
+ | count: 10, | ||
+ | success: function(){}, | ||
+ | fail: function(){} | ||
+ | } | ||
WebIM.conn.fetchHistoryMessages(options) | WebIM.conn.fetchHistoryMessages(options) | ||
</code> | </code> | ||
行 602: | 行 654: | ||
<code javascript> | <code javascript> | ||
var bodyId = message.id; // 需要发送已读回执的消息id | var bodyId = message.id; // 需要发送已读回执的消息id | ||
- | var msg = new WebIM.message('read', msgId); | + | var msg = new WebIM.message('read',conn.getUniqueId()); |
msg.set({ | msg.set({ | ||
id: bodyId | id: bodyId |