// // 配置信息 // var sWebURL=" ../WebIm2"; // 工作目录 var sFilePath=" ../WebIm2/Userfile/uploadfile/?/"; // 用户上传文件、图片的保存路径,?号会被替换成用户号码 var sSvrIP ="125.76.230.155"; // 服务器地址 var lngPort = 5293; // webim服务端端口 var winWndAry = new Array(); //一个集合,保存打开的聊天窗的句柄 var winNameAry = new Array(); //一个集合,保存所有打开的聊天窗的名字 // 取得登录的号码 var nMyUIN = document.getElementById("Parm").getAttribute("UIN"); // 取得我的昵称 var sMyNick = document.getElementById("Parm").getAttribute("Name"); // 开始右下角提示信息的窗口的类 var MSG1; var isMsnShow = false; var nMsnID = 0; /**//* * 消息构造 */ function CLASS_MSN_MESSAGE(id,width,height,caption,title,message,target,action,Uin,Url,chattype){ this.id = id; nMsnID=id; this.title = title; this.caption= caption; this.message= message; this.target = target; this.action = action; this.width = width?width:200; this.height = height?height:120; this.timeout= 200; this.speed = 20; this.step = 1; this.right = screen.width -1; this.bottom = screen.height; this.left = this.right - this.width; this.top = this.bottom - this.height; this.timer = 0; this.pause = false; this.close = false; this.autoHide = true; this.Uin = Uin; this.Url = Url; this.Pop = null; this.sChatType = chattype; // add by zhz 08.8.21,组号码 } /**//* * 隐藏消息方法 */ CLASS_MSN_MESSAGE.prototype.hide = function(){ if(this.onunload()){ var offset = this.height>this.bottom-this.top?this.height:this.bottom-this.top; var me = this; if(this.timer>0){ window.clearInterval(me.timer); } var fun = function(){ if(me.pause==false||me.close){ var x = me.left; var y = 0; var width = me.width; var height = 0; if(me.offset>0){ height = me.offset; } y = me.bottom - height; if(y>=me.bottom){ window.clearInterval(me.timer); if(me.Pop==undefined) return false; me.Pop.hide(); } else { me.offset = me.offset - me.step; } if(me.Pop==undefined) return false me.Pop.show(x,y,width,height); } } this.timer = window.setInterval(fun,this.speed) } nMsnID = 0; isMsnShow = false; } /**//* * 消息卸载事件,可以重写 */ CLASS_MSN_MESSAGE.prototype.onunload = function() { return true; } /**//* * 消息命令事件,要实现自己的连接,请重写它 * */ CLASS_MSN_MESSAGE.prototype.oncommand = function(){ openwin(this.Url,this.Uin,this.sChatType); this.close = true; this.hide(); } /**//* * 消息显示方法 */ CLASS_MSN_MESSAGE.prototype.show = function(){ var oPopup = window.createPopup(); //IE5.5+ this.Pop = oPopup; var w = this.width; var h = this.height; var str = "
" str += "" str += "" str += "" str += "" str += "" str += "" str += "" str += "" str += "" str += "
" + this.caption + "" str += "×
" str += "
" + this.title + "

" str += "
" + this.message + "
" str += "
" str += "
" str += "
"; oPopup.document.body.innerHTML = str; this.offset = 0; var me = this; oPopup.document.body.onmouseover = function(){me.pause=true;} oPopup.document.body.onmouseout = function(){me.pause=false;} var fun = function(){ var x = me.left; var y = 0; var width = me.width; var height = me.height; if(me.offset>me.height){ height = me.height; } else { height = me.offset; } y = me.bottom - me.offset; if(y<=me.top){ me.timeout--; if(me.timeout==0){ window.clearInterval(me.timer); if(me.autoHide){ me.hide(); } } } else { me.offset = me.offset + me.step; } me.Pop.show(x,y,width,height); } this.timer = window.setInterval(fun,this.speed) var btClose = oPopup.document.getElementById("btSysClose"); btClose.onclick = function(){ me.close = true; me.hide(); } // Edit by zhz 08.7.4 for test var btCommand = oPopup.document.getElementById("btCommand"); btCommand.onclick = function(){ me.oncommand(); } } /**//* ** 设置速度方法 **/ CLASS_MSN_MESSAGE.prototype.speed = function(s){ var t = 20; try { t = praseInt(s); } catch(e){} this.speed = t; } /**//* ** 设置步长方法 **/ CLASS_MSN_MESSAGE.prototype.step = function(s){ var t = 1; try { t = praseInt(s); } catch(e){} this.step = t; } CLASS_MSN_MESSAGE.prototype.rect = function(left,right,top,bottom){ try { this.left = left !=null?left:this.right-this.width; this.right = right !=null?right:this.left +this.width; this.bottom = bottom!=null?(bottom>screen.height?screen.height:bottom):screen.height; this.top = top !=null?top:this.bottom - this.height; } catch(e){} } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // 右下角提示窗口的调用示例 // // intUin=111; // sMsg='test'; // // var MSG1 = new CLASS_MSN_MESSAGE(intUin,250,160,intUin+"邀请你进行对话",'您好,请问有什么能帮到您?',sMsg,'','',intUin,'chatWin.asp?sLanguage=1&nFace=1&v=2&telId=&arrCookieId=103708945593339'); // MSG1.rect(null,null,null,screen.height-10); // MSG1.speed = 10; // MSG1.step = 5; // MSG1.show(); //新的弹出窗口模式 //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //装载Flash document.write(''); document.write(''); document.write(''); document.write(''); document.write(''); //document.write(''); document.write(''); document.write(''); //WebIm通讯部分 var FLASH_ERR_NO_RECIEVER_FIND = 2500; var FLASH_ERR_USER_NOT_ONLINE = 2520; var FLASH_ERR_MSG_NOT_REACH_PEER = 2530; var WEBIM_ERR_CONN_SUCCEED = 3500; var WEBIM_ERR_CONN_FAIL = 3510; var WEBIM_ERR_CONN_BREAK = 3520; var FLASH_ERR_USER_NOT_ONLINE = 2520; var FLASH_ERR_MSG_NOT_REACH_PEER = 2530; var STATUS_OFFLINE = 1; var STATUS_WEBIM_ONLINE = 12 ; // webim在线 var STATUS_WEBIM_INVISIBLE = 14 //webim隐身状态 var STATUS_WEBIM_NA = 15 ; //webim忙/离开状态 var STATUS_EXIT_GROUP = 17; //退出群聊 //////////////////////// var MSG_PICTURE = 23 ; //图片消息类型 var MSG_FILE = 24 ; //Normal text message var MSG_VEDIO = 25 ; //Normal text message var MSG_AUDIO = 26 ; //Normal text message var MSG_TEXT = 27 ; //Normal text message var MSG_URL = 28 ; //URL message This message consists of two parts, separated by 0xFE. First the description of the URL followed by the URL itself. var MSG_FILE_REPLY = 23 ; var MSG_AUDIO_REPLY = 22 ; //Normal text message var MSG_VEDIO_REPLY = 21 ; var MSG_GRANT_QUREY = 29 ; // var MSG_STOP_VEDIO = 30 ; // var MSG_STOP_AUDIO = 31 ; // var MSG_STOP_FILE = 32 ; // / var MSG_GRANT_AUDIO_QUREY = 35 ; // var MSG_GRANT_VEDIO_QUREY = 36 ; // var MSG_GRANT_FILE_QUREY = 37 ; // var MSG_SHARE_FILE = 40 ; // var MSG_TEXT_NA = 41 ; // var MSG_WRITTING_NOW =42;; // var MSG_BATCH_CHAT_REQ = 46 ; // var MSG_GROUP_TEXT = 47 ; // //error code var E_SEND_UDP =10000 ; // var E_NOT_WAIT_NEXT =10001 ; // var E_MSG_NOT_REACH_PEER =10002 ; // var E_USER_ALREADY_LOGIN =10003 ; // var E_USER_NOT_FOUND =10010 ; // var E_USERNAME_EXIST =10020 ; // var E_SOKET_CREATE =10030 ; // var E_IP_RESOLVE =10040 ; // var E_SUCCEED =0 ; // var E_LOGIN_SUC =12000 ; // var E_NO_UIN =12010 ; // var E_PWD =12020 ; // var E_EXPIRED =12021 ; // var E_ACCOUNT_DISABLE =12022 ; // var E_LOGIN_FAIL =12025 ; // var E_NEET_AUTH =12030 ; // var E_FRIEND_REFUSE =12040 var E_ADD_LIST_SUC =12050 ; // var E_ALREDY_LIST_FRIEND =12060 ; // var E_DEL_LIST_SUC =12070 ; // var E_UPDATE_SUC =12080 ; // var E_SEARCH_NO_USER =12090 ; // var E_SEARCH_END =12095 ; // var E_SEARCH_SQL_ERROR =12092 ; // var E_NEED_LOGIN =13000 ; // var E_SEND =13010 ; // var E_NO_CONTACT_LIST =13020 ; // var E_CONTACT_LIST_END =13030 ; // var E_UPDATE_CONTACT_LIST_GROUP_NAME_SUC =13040 ; // var E_PASS_INFO =12100 ; // var SPLIT_TAG = "@`@" var SINGLE = "SINGLE"; var GROUP = "GROUP"; var me; // var nowTime; //add by zhz 08.2.27Login的时间 var nLoginOrNo=0; //记录Login状态,初始状态为0, Login Success后变为1,Login break后变为3 Edit by zhz 08.4.5 var MAX_RELOGIN_TIMES = 3; //最多只能重连接次数 var nReloginTimes=0; //当前已重新连接次数, //获取正确的引用 function getID(swfID) { if (navigator.appName.indexOf("Microsoft") > -1) { me = window[swfID]; } else { me = document[swfID]; } btnConn_onclick(); //调用连接服务器 } //连接服务器 function btnConn_onclick() { me.SetWebIMNetwork(sSvrIP, lngPort); me.ConnectToSvr(); } //匿名登陆 function btnLoginNoName_onclick() { me.LoginNoName(); } //add by zhz 08.2.25 使用用户名字登录 //function LoginWebIM( nUIN:Number, sUserName:String, sEmail:String, sMobile:String, sParentName:String, nStatus:Number, sPass:String) function btnLoginbyUIN() { if(nMyUIN==0) { alert("错误,用户号码出错,请检查!"); return false; } if( sMyNick.lenght <= 0 || sMyNick == undefined ) { sMyNick = nMyUIN; } me.LoginWebIM(nMyUIN,sMyNick,"","","",11,""); } // // 上传好友列表 // Edit by zhz 08.3.27 // 增加一个参数sFriendList,表示要上传的好友列表 // sFriendList的格式为 1001,1002,1003,.....号码之间使用豆号分隔 function btnUploadContactList_onclick(sFriendList) { me.UploadContactList(nMyUIN,sFriendList); } //发送消息,单独发 function Send_Msg(txtDestUIN,TxtSend,MSG_NUM){ me.SendMsgTo(0, txtDestUIN, TxtSend, MSG_NUM ); } //发送信息 function to_btnSend_onclick(aNUM){ var tempString; var temString2; switch (Number(aNUM)){ default : //未知 gq20071106 theTalker="|&*"+theAsker; //temString2="<%= SendServerUIN %>"; break; } btnSend_onclick(temString2,tempString,aNUM); } // // 用户改变登录状态 // 由于用户状态改由从数据库读得,这里不再使用 // function btnStatusChange_onclick(rsf) { var nStatus = 0; // for (var i=0;i3){ btnUploadSendList_onclick(); me.SendMsgBatch(sReceiver, msgTxt, MSG_NUM ); } } function FlashReady(){ getID("CommP2"); } //聊天窗关闭了,要从数组中删除该窗口的名字 function close1(winName){ deloneChatWindow(winName); } //由聊天窗调用的发送信息函数 function sendChatMsg(cId,msg,fuin){ btnSendBatch_onclick(cId,msg,MSG_TEXT); } function btnSendBatch_onclick(txtBatchUIN,TxtSendValue,TxtSendNUM) { Send_Msg(txtBatchUIN,TxtSendValue,TxtSendNUM); } function writeStatus(nfuin,msg,Num){ // btnSend_onclick(nfuin,msg,Num); } ////////////////////////////////////////////////////////// // 主窗体关闭后,向所有已经打开的子窗口发送一个信息 // 通知他们主窗体已经关闭了,不能再使用window.opener // ///////////////////////////////////////////////////////// window.onunload = function () { for(var i=0; i530&&event.clientY<5||event.altKey) { return "强烈建议您在游客未结束此次聊天前,请不要关闭此窗口!" } } } //屏蔽退格键 document.onkeydown = function() { /*if(event.keyCode == 8) { event.returnValue = false; }*/ } window.onbeforeunload=function() { /*if(event.clientX>document.body.clientWidth-5&&event.clientY<0||event.altKey) { window.event.returnValue = "刷新或关闭此窗口将使目前此窗口内的信息丢失!"; }*/ } ///////////////////////////////////////////////////////////////////////////////////////////////////////// // 以下部分代码处理打开的聊天窗 // // // ///////////////////////////////////////////////////////////////////////////////////////////////////////// function openwin(sDesURL,nDesUIN,sType) { if(nDesUIN=="") return false; // 不能和自己聊天 if(nDesUIN==nMyUIN) { alert("您不能和自己聊天!"); return false; } if( nLoginOrNo != 1 ) { alert("对方无响应,请刷新页面!"); return false; } // // tag:多个聊天对象,edit by zhz 08.3.27 // 打开的窗口,使用对方号码+我的号码+窗口类型来命名,避免一个用户使用两个帐号登录,然后和同一个人聊天出现的错误 // 窗口类型值范围: // SINGLE 私聊 // GROUPCHAT 群聊 // var nTmpWinName = nDesUIN + nMyUIN + sType; // 窗口不存在,新建一个窗口,并将新建后的窗口名字添加到集合中 if(false==checkChatWindow(nTmpWinName)) { var tmpObj = window.open (sDesURL, nTmpWinName, "height=413, width=550, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, depended=yes,status=no"); if(tmpObj==null) { alert("为保证能使用本站聊天系统,请允许本站的弹出窗口!"); return false; } if(tmpObj!=null) { addOneChatWindow(tmpObj,nTmpWinName); nMsnID=0; } // // 打开一个聊天窗,就将该好友名单上传给Webim服务器, // 然后如果该好友的状态发生改变,那么我可以实时的收到回调! // 注意btnUploadContactList_onclick参数的格式为号码之间使用豆号分隔 // btnUploadContactList_onclick(nDesUIN+","); return false; } alert("您已经打开一个和该人的聊天窗了!"); } // 检查一个窗口是否已经存在了 function checkChatWindow(winName) { if(winName=="") return false; for(var i = 0; i< winNameAry.length; i++) { if(winNameAry[i]!=undefined && winNameAry[i]==winName) { //说明该窗口已经存在了 return true; } } return false; } // 将一个聊天窗口添加到集合中 function addOneChatWindow(winWnd,winName) { if(winName=="") return false; if(checkChatWindow(winName)==true) return false; winWndAry.push(winWnd); winNameAry.push(winName); } // 关闭一个聊天窗的时候,从集合中删掉该窗口的名字 function deloneChatWindow(winName) { if(winName=="") return false; for(var i=0; i"; break; case 27: sShowMsg +=MessageQueue[i].sContent.split("\\C")[1] + "
"; break; default: sShowMsg +=MessageQueue[i].sContent.split("\\C")[1] + "
"; break; } sDesURL = MessageQueue[i].sShowInURL; sChatType = MessageQueue[i].sChatType; } if(sShowMsg.length>0) { ShowMsnWindow(nUIN,sShowMsg,sDesURL,sChatType); } } //在右下角提示有人想和我聊天 function ShowMsnWindow(nSenderUIN,sMsg,sDesURL,sChatType) { var sTmpMsg = sMsg; sTmpMsg = sTmpMsg.replace(/\\p(\d)(\d{2})/ig,"") //var sTmpSub ="return open(this.href,nSenderUIN);" MSG1 = new CLASS_MSN_MESSAGE(nSenderUIN,250,160,nSenderUIN+"邀请你进行对话",''+sTmpMsg+'','','','',nSenderUIN,sDesURL,sChatType); MSG1.rect(null,null,null,screen.height-10); MSG1.speed = 10; MSG1.step = 5; isMsnShow = true; MSG1.show(); } //在右下角提示有人想和我聊天 // // 只取数组的第一个好友出来显示他的信息,因为每次添加都是从数组 // 末尾添加的,这样可以保证不会出现有人的信息永远取不出来的情况 // function RepetGetMsg() { if(isMsnShow==true) return; for(var i=0;i= MAX_RELOGIN_TIMES ) { // 超过重连次数,不再尝试 return false; } btnConn_onclick(); btnLoginbyUIN(); // nReloginTimes++; // add by zhz 08.7.4记录重新连接次数 } } ///////////////////////////////////////////////////////////////// // add by zhz 08.6.25 // 从收到的信息中提取字体的各项设置 // strSrc : 收到的完整消息内容 // strFindTag : 查找的选项,如字体大小为\t,字体类型为\n等 // 返回查找到的值 ///////////////////////////////////////////////////////////////// function GetValueFromString(strSrc,strFindTag) { if( strSrc.length <= 0 || strFindTag.length <= 0 ) { return ""; } var strTmpMsg; strTmpMsg = strSrc; var nTagIndex; //标志位置 var strNextTag = "\\"; //下一个标置 var nNextTagIndex; //下一个标志位置 nTagIndex = strTmpMsg.indexOf(strFindTag); if( nTagIndex >= 0 ) { //取得下一个/的位置 nNextTagIndex = strTmpMsg.indexOf(strNextTag,nTagIndex + 1); if( nNextTagIndex == -1 ) { return strTmpMsg.substring(nTagIndex+2,strTmpMsg.length); } else { return strTmpMsg.substring(nTagIndex+2,nNextTagIndex); } } return ""; } ////////////////////////////////////////////////////////////////// // // 过滤掉html代码 // ////////////////////////////////////////////////////////////////// function HtmlEncode(strMsg) { if( strMsg.length<=0 ) return ""; var strResult = strMsg; strResult = strResult.replace("<","<"); strResult = strResult.replace(">",">"); return strResult; } function HtmlDecode(strMsg) { if( strMsg.length<=0 ) return "" var strResult = strMsg; strResult = strResult.replace("<","<"); strResult = strResult.replace(">",">"); return strResult; } ///////////////////////////////////////// // 群功能 // ///////////////////////////////////////// // // 参数nGroupID 要进入的群ID号 // function btnMCULogin_onclick(nGroupID,sGroupName) { //进入群 //登录只需要填入用户号码,群组号码,群组名称,以及上线状态就可以了。其它的并没有用到 me.MCULogin(nMyUIN,nGroupID , sGroupName, STATUS_WEBIM_ONLINE, //上线 sMyNick, //用户名可为空 "Pass" , //密码可为空 sMyNick , //称呼,可为空 1, //被加为好友是否需要通过验证, 默认为需要 1, //是否安装了摄像头 1 , //是否安装了麦 10 //头像号,这里随便指定了一个 ); } // // 获取群中在线人员 // nGroupID 群ID号 // function btnMCUReqUserList_onclick(nGroupID) { me.MCUReqUserList(nGroupID); } // // // function btnMCUSend_onclick(nGroupID,nMsgType,sMsgContent) { me.MCUSendMsg(nGroupID, nMsgType, sMsgContent ); } // // 退出群 // nGroupID 群ID号 // function btnMCUOffline_onclick(nGroupID) { me.MCUStatusChange(nGroupID, STATUS_EXIT_GROUP ); //退出群 } ///////////////////////////////以下是MCU相关回调函数////////////////////////// function ExeMCULoginReply(nVer, nUIN, nGroupID, sGroupName) { lmsg("\nExeMCULoginReply 登录成功群: " + nGroupID + "群名字: " + sGroupName ); // LoginMCU Success openwin(sWebURL+'/ChatWin.html?GroupID='+nGroupID+'&MyUIN='+nMyUIN+'&ChatType='+GROUP+'&GroupName='+sGroupName,nGroupID,GROUP); btnMCUReqUserList_onclick(nGroupID); } function ExeMCUGetMsg(nVer, nUIN, nGroupID, nType, sMsg) { switch (Number(nType)) { case MSG_TEXT: case MSG_PICTURE: var sDesURL ="ChatWin.html?GroupID="+nGroupID+"&MyUIN="+nMyUIN+"&ChatType="+GROUP; // tag:多个聊天对象 if(findChatWinIndex(nGroupID+nMyUIN+GROUP)==-1) { //将好友添加到列表中 AddFriendToQueue(nSenderUIN); ///////////////////////////////////////////////////////// var objMsg = new MSGDATA(nType,false,nUIN,nMyUIN,sMsg,sDesURL,GROUP); AddMsgToQueue(objMsg); } else { winWndAry[findChatWinIndex(nGroupID+nMyUIN+GROUP)].showMsg(sMsg,nType); } break; default: break; } lmsg("\nExeMCUGetMsg 获得群内有人发送的信息, 群号是" + nGroupID + "发送者是: " + nUIN + "消息类型" + nType + "消息内容: " + sMsg ); } function ExeMCUUserList(nVer, nGroupID, sUserList) { lmsg("\nExeMCUUserList 获得群内在线人员, 群号是" + nGroupID + "人员列表是: " + sUserList ); // // 查找该群窗口是否打开 // if(findChatWinIndex(nGroupID+nMyUIN+GROUP)==-1) return; var aryUser = new Array(); aryUser = sUserList.split(","); for( var i=0; i< aryUser.length-1; i+=2 ) { if( aryUser[i] == undefined || aryUser[i+1] == undefined ) continue; if( aryUser[i] == "" ) continue; winWndAry[findChatWinIndex(nGroupID+nMyUIN+GROUP)].CreateUserNode(aryUser[i],aryUser[i+1]); } } function ExeMCUStatusChange(nVer, nUIN, nGroupID, nStatus,sUserName) { //alert(sUserName); switch (Number(nStatus)) { // 退出群聊 case STATUS_EXIT_GROUP: { winWndAry[findChatWinIndex(nGroupID+nMyUIN+GROUP)].RemoveUserNode(nUIN); break; } // 群上线,离开,隐身状态 case STATUS_WEBIM_ONLINE: case STATUS_WEBIM_NA: case STATUS_WEBIM_INVISIBLE: { winWndAry[findChatWinIndex(nGroupID+nMyUIN+GROUP)].CreateUserNode(nUIN,sUserName); break; } } lmsg("\nExeMCUStatusChange 获得群内人员上下线事件, 群号是" + nGroupID + "人员" + nUIN + "改变的状态是: " + nStatus ); } function lmsg(str){ //txtLog.value = txtLog.value + str + "\n"; //alert(str); } // // 群聊接口 // 接受参数: // nGroupID 群组号码 // sGroupName 群名称 // function EnterGroupChat(nGroupID,sGroupName) { if( Number(nGroupID)<=0 || sGroupName.length<=0 ) return false; // 检测当前是否已经打开该群窗口 if(true==checkChatWindow(nGroupID+nMyUIN+GROUP)) { alert("该群聊窗口已经打开了"); } else { btnMCULogin_onclick(nGroupID,sGroupName); } } // // 私聊接口 // intOtherUIN 圣方号码 // intMyUIN 我的号码 // function EnterSingleChat(intOtherUIN) { intOtherUIN=intOtherUIN+""; var url=""; var orherUIN=""; orherUIN=intOtherUIN; if(intOtherUIN.indexOf(',')>-1) { orherUIN=intOtherUIN.substring(0,intOtherUIN.indexOf(',')); url=intOtherUIN.substring(intOtherUIN.indexOf(',')+1,intOtherUIN.length); }else { orherUIN=intOtherUIN; } if(orherUIN <=0) { alert("对方不在线,请使用站内留言!"); if(url!="-1") { window.open(url); } return; } try{ var xmlhttp=new ActiveXObject("wwCheck.wwWebCheck"); location.href="im:"+orherUIN+"&畜商通"; }catch(e){ if( Number(orherUIN) <=0 ) return false; openwin(sWebURL+'/ChatWin.html?OtherUIN='+orherUIN+'&MyUIN='+nMyUIN+'&ChatType='+SINGLE,intOtherUIN,SINGLE); } }