|
|
@ -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>
|
|
|
|