kira 6 years ago
parent 6cf637bfec
commit a6245606a5

@ -1,5 +1,6 @@
<html> <html>
<!--[if lt IE 9]> <!--[if lt IE 9]>
<meta charset="utf-8"/>
<script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script> <script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script>
<![endif]--> <![endif]-->
<!-- 自动适配移动端与pc端 --> <!-- 自动适配移动端与pc端 -->
@ -17,14 +18,16 @@
appkey: 24960261, appkey: 24960261,
credential: 'xxxxxx', credential: 'xxxxxx',
touid: window.touid, touid: window.touid,
logo: 'http://img.alicdn.com/tps/i3/TB12LD9IFXXXXb3XpXXSyFWJXXX-82-82.png', logo:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805672266&di=2b24a1579255192f7456d64872c65b39&imgtype=0&src=http%3A%2F%2Fimage.coolapk.com%2Ffeed%2F2016%2F1113%2F661664_1479013815_7771.jpg.m.jpg',
toAvatar:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805672266&di=2b24a1579255192f7456d64872c65b39&imgtype=0&src=http%3A%2F%2Fimage.coolapk.com%2Ffeed%2F2016%2F1113%2F661664_1479013815_7771.jpg.m.jpg',
pluginUrl: 'http://192.168.0.43:9001/service_contact_list.html?uid=' pluginUrl: 'http://192.168.0.43:9001/service_contact_list.html?uid='
+ window.uid, + window.uid,
onLoginSuccess: function (data) { onLoginSuccess: function (data) {
WKIT.Conn.sdk.Event.on('MSG_RECEIVED', function (data) { WKIT.Conn.sdk.Event.on('MSG_RECEIVED', function (data) {
document.getElementById("J_wkitPluginFrame").contentWindow
.updateContractList(data.data); updateContractList(data.data);
}); });
initUnreadMsgAndContact();
WKIT.Conn.sdk.Base.startListenAllMsg(); WKIT.Conn.sdk.Base.startListenAllMsg();
} }
}); });
@ -33,7 +36,66 @@
function switchTouid(touid) { function switchTouid(touid) {
WKIT.switchTouid({ WKIT.switchTouid({
touid: touid, touid: touid,
logo:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805672266&di=2b24a1579255192f7456d64872c65b39&imgtype=0&src=http%3A%2F%2Fimage.coolapk.com%2Ffeed%2F2016%2F1113%2F661664_1479013815_7771.jpg.m.jpg',
// Avatar:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805782509&di=98f7fa48980696f8eddf7eb617a834a3&imgtype=0&src=http%3A%2F%2Fi2.hdslb.com%2Fbfs%2Fface%2F98dbd049061292bca8625caf91cff1b41ee999cd.jpg',
toAvatar:'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1531805782509&di=98f7fa48980696f8eddf7eb617a834a3&imgtype=0&src=http%3A%2F%2Fi2.hdslb.com%2Fbfs%2Fface%2F98dbd049061292bca8625caf91cff1b41ee999cd.jpg'
}); });
WKIT.Conn.sdk.Chat.setReadState({
touid: touid,
timestamp: Math.floor((+new Date()) / 1000),
success: function (data) {
console.log('set read state success', data);
},
error: function (error) {
console.log('set read state fail', error);
}
});
document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[touid] = 0;
document.getElementById("J_wkitPluginFrame").contentWindow.loadContactList();
}
function initUnreadMsgAndContact() {
WKIT.Conn.sdk.Base.getRecentContact({
count: 40,
success: function (data) {
var cnts = data.data.cnts;
for (var i = cnts.length - 1; i >= 0; i--) {
document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[WKIT.Conn.sdk.Base.getNick(cnts[i].to)] = 0;
}
getUnreadMsgCount();
},
error: function (error) {
console.log('get contact msg count fail', error);
}
})
}
function getUnreadMsgCount() {
WKIT.Conn.sdk.Base.getUnreadMsgCount({
count: 40,
success: function (data) {
var unreads = data.data;
for (var i = unreads.length - 1; i >= 0; i--) {
document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[ WKIT.Conn.sdk.Base.getNick(unreads[i].contact)] =
unreads[i].msgCount;
}
document.getElementById("J_wkitPluginFrame").contentWindow.loadContactList();
},
error: function (error) {
console.log('get recent contact fail', error);
}
});
}
function updateContractList(data) {
var msg = data.msgs[0];
var msg_uid = WKIT.Conn.sdk.Base.getNick(msg.from);
if (document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[msg_uid]) {
document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[msg_uid] = document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[msg_uid] + 1;
} else {
document.getElementById("J_wkitPluginFrame").contentWindow.unreadMap[msg_uid] = 1;
}
document.getElementById("J_wkitPluginFrame").contentWindow.loadContactList();
} }
</script> </script>
</html> </html>

@ -1,43 +1,35 @@
<html> <html>
<!--[if lt IE 9]> <!--[if lt IE 9]>
<meta charset="utf-8" />
<script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script> <script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script>
<![endif]--> <![endif]-->
<!-- 自动适配移动端与pc端 --> <!-- 自动适配移动端与pc端 -->
<script src="https://g.alicdn.com/aliww/??h5.openim.sdk/1.0.6/scripts/wsdk.js,h5.openim.kit/0.3.3/scripts/kit.js" <script src="https://g.alicdn.com/aliww/h5.openim.sdk/1.0.6/scripts/wsdk.js" charset="UTF-8"></script>
charset="utf-8"></script>
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script> <script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
<script> <script>
var unreadMap = {}; var unreadMap = {};
var sdk = new WSDK(); var sdk = new WSDK();
window.imsdk = sdk;
var queryParam = getQueryString();
function login() { function login() {
sdk.Base.login({ window.imsdk.Base.login({
uid: queryParam['uid'], uid: queryParam['uid'],
appkey: '24960261', appkey: '24960261',
credential: 'xxxxxx', credential: 'xxxxxx',
timeout: 4000, timeout: 4000,
success: function (data) { success: function (data) {
console.log("login success");
initUnreadMsgAndContact(); initUnreadMsgAndContact();
sdk.Event.on('MSG_RECEIVED', function (data) {
console.log(data);
});
sdk.Base.startListenAllMsg();
}, },
error: function (error) { error: function (error) {
console.log("login fail",error);
login(); login();
} }
}); });
} }
function loadContactList() { function loadContactList() {
var str = '';
for (var key in unreadMap) {
str += "{" + key + ":" + unreadMap[key] + "}";
}
$("#contact").html(str);
var contact_list = ''; var contact_list = '';
for (var key in unreadMap) { for (var key in unreadMap) {
contact_list += contact_list +=
@ -46,80 +38,9 @@
$("#contact_list").html(contact_list); $("#contact_list").html(contact_list);
} }
function initUnreadMsgAndContact() {
sdk.Base.getRecentContact({
count: 40,
success: function (data) {
var cnts = data.data.cnts;
for (var i = cnts.length - 1; i >= 0; i--) {
unreadMap[sdk.Base.getNick(cnts[i].to)] = 0;
}
getUnreadMsgCount();
},
error: function (error) {
console.log('get contact msg count fail', error);
}
})
}
function getUnreadMsgCount() {
sdk.Base.getUnreadMsgCount({
count: 40,
success: function (data) {
var unreads = data.data;
for (var i = unreads.length - 1; i >= 0; i--) {
unreadMap[sdk.Base.getNick(unreads[i].contact)] =
unreads[i].msgCount;
}
loadContactList();
},
error: function (error) {
console.log('get recent contact fail', error);
}
});
}
function setReadState(touid) {
sdk.Chat.setReadState({
touid: touid,
timestamp: Math.floor((+new Date()) / 1000),
success: function (data) {
},
error: function (error) {
console.log('set read state fail', error);
}
});
}
function startListenMsg(touid) {
sdk.Chat.startListenMsg({touid: 'touid'});
}
function stopListenMsg() {
sdk.Chat.stopListenMsg();
}
function getQueryString() {
var qs = location.search.substr(1), // 获取url中"?"符后的字串
args = {}, // 保存参数数据的对象
items = qs.length ? qs.split("&") : [], // 取得每一个参数项,
item = null,
len = items.length;
for (var i = 0; i < len; i++) {
item = items[i].split("=");
var name = decodeURIComponent(item[0]),
value = decodeURIComponent(item[1]);
if (name) {
args[name] = value;
}
}
return args;
}
function updateContractList(data) { function updateContractList(data) {
var msg = data.msgs[0]; var msg = data.msgs[0];
var msg_uid = sdk.Base.getNick(msg.from); var msg_uid = window.imsdk.Base.getNick(msg.from);
if (unreadMap[msg_uid]) { if (unreadMap[msg_uid]) {
unreadMap[msg_uid] = unreadMap[msg_uid] + 1; unreadMap[msg_uid] = unreadMap[msg_uid] + 1;
} else { } else {
@ -130,23 +51,11 @@
function switchToUser(touid) { function switchToUser(touid) {
parent.switchTouid(touid); parent.switchTouid(touid);
sdk.Chat.setReadState({
touid: touid,
timestamp: Math.floor((+new Date()) / 1000),
success: function(data){
console.log('set read state success', data);
},
error: function(error){
console.log('set read state fail', error);
}
});
unreadMap[touid]=0;
loadContactList();
} }
</script> </script>
<script> <script>
window.onload = function () { window.onload = function () {
login(); // login();
}; };
</script> </script>

@ -1,5 +1,6 @@
<html> <html>
<!--[if lt IE 9]> <!--[if lt IE 9]>
<meta charset="utf-8" />
<script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script> <script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script>
<![endif]--> <![endif]-->
<!-- 自动适配移动端与pc端 --> <!-- 自动适配移动端与pc端 -->

Loading…
Cancel
Save