master
kira 6 years ago
parent 58ade45bca
commit f4ffe14bfa

@ -3,22 +3,27 @@
<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" charset="utf-8"></script> <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> <script>
window.uid='taki'; window.uid = 'taki';
window.touid='mitsuha'; window.touid = 'mitsuha';
window.onload = function(){ window.onload = function () {
WKIT.init({ WKIT.init({
container: document.getElementById('J_demo'), container: document.getElementById('J_demo'),
width: 700, width: 700,
height: 500, height: 500,
uid: window.uid, uid: window.uid,
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: 'http://img.alicdn.com/tps/i3/TB12LD9IFXXXXb3XpXXSyFWJXXX-82-82.png',
pluginUrl: 'http://192.168.0.43:9001/service_contact_list.html?uid='+window.uid pluginUrl: 'http://192.168.0.43:9001/service_contact_list.html?uid='
}); + window.uid,
onMsgReceived: function (data) {
document.getElementById("J_wkitPluginFrame").contentWindow.updateContractList(data);
}
});
} }
</script> </script>
</html> </html>

@ -9,24 +9,24 @@
<script> <script>
var unreadMap = {}; var unreadMap = {};
var sdk = new WSDK(); var sdk = new WSDK();
var queryParam = getQueryString(); var queryParam = getQueryString();
function login() { function login() {
sdk.Base.login({ sdk.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) {
initUnreadMsgAndContact(); initUnreadMsgAndContact();
console.log('login success', data); console.log('login success', data);
sdk.Base.startListenAllMsg(); },
}, error: function (error) {
error: function (error) { console.log('get login msg count fail', error);
console.log('get login msg count fail', error); }
} });
});
} }
function loadContactList() { function loadContactList() {
@ -44,51 +44,51 @@
function initUnreadMsgAndContact() { function initUnreadMsgAndContact() {
sdk.Base.getRecentContact({ sdk.Base.getRecentContact({
count: 40, count: 40,
success: function (data) { success: function (data) {
console.log('get contact msg count success', data); console.log('get contact msg count success', data);
var cnts = data.data.cnts; var cnts = data.data.cnts;
for (var i = cnts.length - 1; i >= 0; i--) { for (var i = cnts.length - 1; i >= 0; i--) {
unreadMap[sdk.Base.getNick(cnts[i].to)] = 0; unreadMap[sdk.Base.getNick(cnts[i].to)] = 0;
} }
getUnreadMsgCount(); getUnreadMsgCount();
}, },
error: function (error) { error: function (error) {
console.log('get contact msg count fail', error); console.log('get contact msg count fail', error);
} }
}) })
} }
function getUnreadMsgCount() { function getUnreadMsgCount() {
sdk.Base.getUnreadMsgCount({ sdk.Base.getUnreadMsgCount({
count: 40, count: 40,
success: function (data) { success: function (data) {
console.log('get unread msg count success', data); console.log('get unread msg count success', data);
var unreads = data.data; var unreads = data.data;
for (var i = unreads.length - 1; i >= 0; i--) { for (var i = unreads.length - 1; i >= 0; i--) {
unreadMap[sdk.Base.getNick(unreads[i].contact)] = unreadMap[sdk.Base.getNick(unreads[i].contact)] =
unreads[i].msgCount; unreads[i].msgCount;
} }
loadContactList(); loadContactList();
}, },
error: function (error) { error: function (error) {
console.log('get recent contact fail', error); console.log('get recent contact fail', error);
} }
}); });
} }
function setReadState(touid) { function setReadState(touid) {
sdk.Chat.setReadState({ sdk.Chat.setReadState({
touid: touid, touid: touid,
timestamp: Math.floor((+new Date()) / 1000), timestamp: Math.floor((+new Date()) / 1000),
success: function (data) { success: function (data) {
console.log('set read state success', data); console.log('set read state success', data);
}, },
error: function (error) { error: function (error) {
console.log('set read state fail', error); console.log('set read state fail', error);
} }
}); });
} }
function startListenMsg(touid) { function startListenMsg(touid) {
@ -106,16 +106,26 @@
item = null, item = null,
len = items.length; len = items.length;
for(var i = 0; i < len; i++) { for (var i = 0; i < len; i++) {
item = items[i].split("="); item = items[i].split("=");
var name = decodeURIComponent(item[0]), var name = decodeURIComponent(item[0]),
value = decodeURIComponent(item[1]); value = decodeURIComponent(item[1]);
if(name) { if (name) {
args[name] = value; args[name] = value;
} }
} }
return args; return args;
} }
function updateContractList(data) {
var msg =data.msgs[0];
var msg_uid = sdk.Base.getNick(msg.from);
if(unreadMap[msg_uid]){
unreadMap[msg_uid] = unreadMap[msg_uid]+1;
}else {
unreadMap[msg_uid] = 1;
}
loadContactList();
}
</script> </script>
<script> <script>
window.onload = function () { window.onload = function () {

@ -3,20 +3,20 @@
<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" charset="utf-8"></script> <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> <script>
window.onload = function(){ window.onload = function () {
WKIT.init({ WKIT.init({
container: document.getElementById('J_demo'), container: document.getElementById('J_demo'),
width: 700, width: 700,
height: 500, height: 500,
uid: 'mitsuha', uid: 'mitsuha',
appkey: 24960261, appkey: 24960261,
credential: 'xxxxxx', credential: 'xxxxxx',
touid: 'taki', touid: 'taki',
logo: 'http://img.alicdn.com/tps/i3/TB12LD9IFXXXXb3XpXXSyFWJXXX-82-82.png', logo: 'http://img.alicdn.com/tps/i3/TB12LD9IFXXXXb3XpXXSyFWJXXX-82-82.png',
pluginUrl: 'http://www.taobao.com/market/seller/openim/plugindemo.php' });
});
} }
</script> </script>
</html> </html>
Loading…
Cancel
Save