2025-07-18 13:06:06 +08:00
|
|
|
|
"use strict";
|
|
|
|
|
|
const common_vendor = require("../../common/vendor.js");
|
|
|
|
|
|
function goEasylogin(goeasy, id, avatar, nickname) {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:5", "`````````````````goEasylogin`````````````````", id, avatar, nickname);
|
|
|
|
|
|
goeasy.connect({
|
|
|
|
|
|
id,
|
|
|
|
|
|
//im必填,最大长度60字符
|
|
|
|
|
|
data: { "avatar": avatar, "nickname": nickname },
|
|
|
|
|
|
//必须是一个对象,im必填,最大长度300字符,显示在会话列表中
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:10", "IM连接成功");
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:13", "IM连接失败, code:" + error.code + ",error:" + error.content);
|
|
|
|
|
|
},
|
|
|
|
|
|
onProgress: function(attempts) {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:16", "IM连接或自动重连中", attempts);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function goEasylogout(goeasy) {
|
|
|
|
|
|
goeasy.disconnect({
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:25", "IM断开成功");
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:28", "IM断开失败, code:" + error.code + ",error:" + error.content);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function getConversationList(goeasy) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
im.latestConversations({
|
|
|
|
|
|
onSuccess: function(result) {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:39", "获取会话列表成功", result);
|
|
|
|
|
|
resolve(result.content);
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
|
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:43", "获取会话列表失败, code:" + error.code + " content:" + error.content);
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "获取会话列表失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-18 13:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function getConversationMessages(goeasy, userid, imestamp) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
im.history({
|
|
|
|
|
|
id: userid,
|
|
|
|
|
|
//用户id或者群id
|
|
|
|
|
|
type: common_vendor.jo.IM_SCENE.PRIVATE,
|
|
|
|
|
|
//群聊:GoEasy.IM_SCENE.GROUP, 客服:GoEasy.IM_SCENE.CS,
|
|
|
|
|
|
lastTimestamp: imestamp,
|
|
|
|
|
|
//上次查询结果里最后一条消息的时间戳,首次查询传入null即可
|
|
|
|
|
|
limit: 30,
|
|
|
|
|
|
//可选项,返回的消息条数,默认为10条,最多30条
|
|
|
|
|
|
onSuccess: function(result) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:63", "获取消息列表成功", result);
|
2025-07-18 13:06:06 +08:00
|
|
|
|
resolve(result.content);
|
|
|
|
|
|
},
|
|
|
|
|
|
//查询成功
|
|
|
|
|
|
onFailed: function(error) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:67", "获取消息列表失败, code:" + error.code + " content:" + error.content);
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "获取消息列表失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-18 13:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
//查询失败
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function sendMessage(goeasy, userid, message, avatar, nickname) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
let textMessage = im.createTextMessage({
|
|
|
|
|
|
text: message,
|
|
|
|
|
|
//消息内容
|
|
|
|
|
|
to: {
|
|
|
|
|
|
type: common_vendor.jo.IM_SCENE.PRIVATE,
|
|
|
|
|
|
//私聊还是群聊,群聊为GoEasy.IM_SCENE.GROUP
|
|
|
|
|
|
id: userid,
|
|
|
|
|
|
//接收方用户id
|
|
|
|
|
|
data: { "avatar": avatar, "nickname": nickname }
|
|
|
|
|
|
//接收方用户扩展数据, 任意格式的字符串或者对象,用于更新会话列表conversation.data
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
im.sendMessage({
|
|
|
|
|
|
message: textMessage,
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
resolve(textMessage);
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:98", "发送消息失败,code:" + error.code + " ,error " + error.content);
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "发送消息失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-18 13:06:06 +08:00
|
|
|
|
reject(error);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function messageRead(goeasy, userid) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
im.markMessageAsRead({
|
|
|
|
|
|
id: userid,
|
|
|
|
|
|
type: common_vendor.jo.IM_SCENE.PRIVATE,
|
|
|
|
|
|
//群聊:GoEasy.IM_SCENE.GROUP, 客服消息:GoEasy.IM_SCENE.CS,
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
resolve();
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:121", "标记私聊已读失败", error);
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "标记私聊已读失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-18 13:06:06 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2025-07-21 22:10:59 +08:00
|
|
|
|
function sendCustomMessage(goeasy, type, userid, order, avatar, nickname) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
var customMessage = im.createCustomMessage({
|
|
|
|
|
|
type,
|
|
|
|
|
|
//字符串,可以任意自定义类型
|
|
|
|
|
|
payload: order,
|
|
|
|
|
|
to: {
|
|
|
|
|
|
type: common_vendor.jo.IM_SCENE.PRIVATE,
|
|
|
|
|
|
//私聊还是群聊,群聊为GoEasy.IM_SCENE.GROUP
|
|
|
|
|
|
id: userid,
|
|
|
|
|
|
//接收方用户id
|
|
|
|
|
|
data: { "avatar": avatar, "nickname": nickname }
|
|
|
|
|
|
//好友扩展数据, 任意格式的字符串或者对象,用于更新会话列表conversation.data
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
im.sendMessage({
|
|
|
|
|
|
message: customMessage,
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
resolve(customMessage);
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:153", "Failed to send message,code:" + error.code + ",error" + error.content);
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "发送自定义消息失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-21 22:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function conversationTop(goeasy, conversation, top) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
im.topConversation({
|
|
|
|
|
|
conversation,
|
|
|
|
|
|
top,
|
|
|
|
|
|
//或者 false
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
resolve("成功");
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:174", "失败:", error);
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "置顶会话失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-21 22:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function conversationDelete(goeasy, conversation) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
im.removeConversation({
|
|
|
|
|
|
conversation,
|
|
|
|
|
|
onSuccess: function() {
|
|
|
|
|
|
resolve("删除会话成功");
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
2025-07-25 16:39:52 +08:00
|
|
|
|
common_vendor.index.__f__("log", "at components/goEasyTool/tool.js:193", error);
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "删除会话失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
function sendGroupMessage(goeasy, message) {
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
|
|
|
var im = goeasy.im;
|
|
|
|
|
|
im.sendMessage({
|
|
|
|
|
|
message,
|
|
|
|
|
|
onSuccess: () => {
|
|
|
|
|
|
resolve(message);
|
|
|
|
|
|
},
|
|
|
|
|
|
onFailed: function(error) {
|
|
|
|
|
|
common_vendor.index.showToast({
|
|
|
|
|
|
title: "发送消息失败",
|
|
|
|
|
|
icon: "none"
|
|
|
|
|
|
});
|
2025-07-21 22:10:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
exports.conversationDelete = conversationDelete;
|
|
|
|
|
|
exports.conversationTop = conversationTop;
|
2025-07-18 13:06:06 +08:00
|
|
|
|
exports.getConversationList = getConversationList;
|
|
|
|
|
|
exports.getConversationMessages = getConversationMessages;
|
|
|
|
|
|
exports.goEasylogin = goEasylogin;
|
|
|
|
|
|
exports.goEasylogout = goEasylogout;
|
|
|
|
|
|
exports.messageRead = messageRead;
|
2025-07-21 22:10:59 +08:00
|
|
|
|
exports.sendCustomMessage = sendCustomMessage;
|
2025-07-25 16:39:52 +08:00
|
|
|
|
exports.sendGroupMessage = sendGroupMessage;
|
2025-07-18 13:06:06 +08:00
|
|
|
|
exports.sendMessage = sendMessage;
|
|
|
|
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/components/goEasyTool/tool.js.map
|