您现在的位置是:网站首页> C#技术
C#自研框架中LayIM使用
- C#技术
- 2024-08-21
- 820人已阅读
C#自研框架中LayIM使用
打开指定用户对话界面
console.log("menuChat");
/*发送即时消息*/
var mineId = $(this).parent().data('id');
var moldId = $(this).parent().data('mold');
var mineName = $(this).parent().attr('imname');
var mineFace = $(this).parent().attr('imface');
console.log(mineId);
layim.chat({
type: moldId == 1 ? "friend" : "group",
name: mineName,
avatar: mineFace,
id: mineId
//status: '好友当前离线状态'
});
框架中打开指定对话框
try
{
var m_IMPack={};
m_IMPack.msgtype="talk";
m_IMPack.user={};
m_IMPack.user.id="15954448597820000003000";
m_IMPack.user.name="xzt";
m_IMPack.user.avatar="http://www.1xn1.com/upfiles/images/202007/0c28e37988cd4119b6a77653c1ef847b.jpg";
window.parent.postMessage(JSON.stringify(m_IMPack),'*');//IM 所在的window获得ifame的window,默认im位于顶级窗口
}
catch(err){
//在此处理错误
console.log(err);
}
框架LayIM嵌入页面
http://www.1xn1.com/IMessage/index.aspx?mainurl=http://www.1xn1.com/userblog/sysMain.aspx?bIM=false
LayIM与外部通讯采用浏览器自带的message
IMessage模块:JsonMode\即时通讯\View\public\js\impc.js和JsonMode\即时通讯\View\public\js\imphone.js
内部处理外部发送的消息
var savemine = res.mine;
window.addEventListener('message', function (e) {
//console.log(e);
//console.log(savemine);
try {
m_IMPack = JSON.parse(e.data);
if (m_IMPack.msgtype == "talk") {
layim.chat({
id: m_IMPack.user.id
, name: m_IMPack.user.name
, type: 'friend' //friend、group等字符,如果是group,则创建的是群聊
, avatar: m_IMPack.user.avatar
});
}
}
catch (err) {
}
return;
if (e.data == "hello") {
layim.chat({
id: "15954448597820000003000"
, name: 'xzt'
, type: 'friend' //friend、group等字符,如果是group,则创建的是群聊
, avatar: 'http://www.test.bslzg.com/upfiles/images/202007/0c28e37988cd4119b6a77653c1ef847b.jpg'
});
}
});
上一篇:C#经验总结