|
|
|
@ -1,43 +1,35 @@
|
|
|
|
|
<html>
|
|
|
|
|
<!--[if lt IE 9]>
|
|
|
|
|
<meta charset="utf-8" />
|
|
|
|
|
<script src="https://g.alicdn.com/aliww/ww/json/json.js" charset="utf-8"></script>
|
|
|
|
|
<![endif]-->
|
|
|
|
|
<!-- 自动适配移动端与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"
|
|
|
|
|
charset="utf-8"></script>
|
|
|
|
|
<script src="https://g.alicdn.com/aliww/h5.openim.sdk/1.0.6/scripts/wsdk.js" charset="UTF-8"></script>
|
|
|
|
|
<script src="https://cdn.bootcss.com/jquery/1.10.2/jquery.min.js"></script>
|
|
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
var unreadMap = {};
|
|
|
|
|
var sdk = new WSDK();
|
|
|
|
|
|
|
|
|
|
var queryParam = getQueryString();
|
|
|
|
|
window.imsdk = sdk;
|
|
|
|
|
|
|
|
|
|
function login() {
|
|
|
|
|
sdk.Base.login({
|
|
|
|
|
window.imsdk.Base.login({
|
|
|
|
|
uid: queryParam['uid'],
|
|
|
|
|
appkey: '24960261',
|
|
|
|
|
credential: 'xxxxxx',
|
|
|
|
|
timeout: 4000,
|
|
|
|
|
success: function (data) {
|
|
|
|
|
console.log("login success");
|
|
|
|
|
initUnreadMsgAndContact();
|
|
|
|
|
sdk.Event.on('MSG_RECEIVED', function (data) {
|
|
|
|
|
console.log(data);
|
|
|
|
|
});
|
|
|
|
|
sdk.Base.startListenAllMsg();
|
|
|
|
|
},
|
|
|
|
|
error: function (error) {
|
|
|
|
|
console.log("login fail",error);
|
|
|
|
|
login();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function loadContactList() {
|
|
|
|
|
var str = '';
|
|
|
|
|
for (var key in unreadMap) {
|
|
|
|
|
str += "{" + key + ":" + unreadMap[key] + "}";
|
|
|
|
|
}
|
|
|
|
|
$("#contact").html(str);
|
|
|
|
|
var contact_list = '';
|
|
|
|
|
for (var key in unreadMap) {
|
|
|
|
|
contact_list +=
|
|
|
|
@ -46,80 +38,9 @@
|
|
|
|
|
$("#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) {
|
|
|
|
|
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]) {
|
|
|
|
|
unreadMap[msg_uid] = unreadMap[msg_uid] + 1;
|
|
|
|
|
} else {
|
|
|
|
@ -130,23 +51,11 @@
|
|
|
|
|
|
|
|
|
|
function switchToUser(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>
|
|
|
|
|
window.onload = function () {
|
|
|
|
|
login();
|
|
|
|
|
// login();
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
</script>
|
|
|
|
|