差别
这里会显示出您选择的修订版和当前版本之间的差别。
两侧同时换到之前的修订记录 前一修订版 后一修订版 | 前一修订版 后一修订版 两侧同时换到之后的修订记录 | ||
im:web:basics:message [2019/07/05 02:34] jk [发送命令消息] |
im:web:basics:message [2019/09/25 03:01] huanxinfudh [拉取历史消息] |
||
---|---|---|---|
行 33: | 行 33: | ||
* 贴图消息 | * 贴图消息 | ||
+ | | ||
+ | * URL图片消息 | ||
| | ||
* 命令消息 | * 命令消息 | ||
行 51: | 行 53: | ||
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: | 行 77: | ||
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: | 行 102: | ||
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: | 行 218: | ||
} | } | ||
}); | }); | ||
+ | </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> | ||
行 432: | 行 473: | ||
/** | /** | ||
* 发送撤回消息 | * 发送撤回消息 | ||
- | * @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) | ||
行 573: | 行 615: | ||
===== 拉取历史消息 ===== | ===== 拉取历史消息 ===== | ||
- | 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: | 行 652: | ||
<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 |