console.log('该商户有效'); console.log(document.body); var setting={"float_type":"2","position_type":"1","pos_rleft":"0","pos_tbpx":"30","online_color":"#488bff","online_text":"和我们在线交谈!","offline_text":"和我们在线交谈!"},kf_host='https://liaotian.860086.com',style_mode=parseInt(0); var service_total=parseInt(1); console.log(setting); var head = document.getElementsByTagName('head')[0]; /* 默认样式 */ var d_link = document.createElement('link'); d_link.type='text/css'; d_link.rel = 'stylesheet'; d_link.href =kf_host+'/Public/Store/index/ql_online.css'; head.appendChild(d_link); var script = document.createElement("script"); script.src = kf_host + '/Public/Plugins/push/pusher.min.js'; script.type = "text/javascript"; document.head.appendChild(script); var qlchat={ visiter_id:'', visiter_name:'', avatar:'', product:'', open:function(){ /* 界面风格 */ var web_style=parseInt(setting.float_type),web_div=document.createElement('div'),web_html=''; switch(web_style){ case 1: if(service_total>0){ web_div.className ='com_dom_way show_way_tell'; web_div.style.display='block'; web_div.id ="qlchat_table"; web_html=''; }else{ web_div.className ='com_dom_way show_way_message'; web_div.style.display='block'; web_html=''; } break; case 2: if(service_total>0){ web_div.className ='com_dom_way1 show_way_tell1'; web_div.style.display='block'; web_div.id ="qlchat_table"; web_html=''; }else{ web_div.className ='com_dom_way1 show_way_message1'; web_div.style.display='block'; web_html=''; } break; case 3: if(service_total>0){ web_div.className ='circle_show1'; web_div.style.display='block'; web_div.id ="qlchat_table"; web_html=''; }else{ web_div.className ='circle_show2'; web_div.style.display='block'; web_html=''; } break; default: web_div.className ='qlchat-form'; web_div.id ="qlchat_table"; web_html='

'+setting.offline_text+'

'; break; } web_div.style.background=setting.online_color; var pos_rleft_str=setting.pos_rleft,pos_tbpx_str=setting.pos_tbpx; pos_rleft_str+=setting.position_type==1?'px':'%'; pos_tbpx_str+=setting.position_type==1?'px':'%'; web_div.style.right=pos_rleft_str; web_div.style.bottom=pos_tbpx_str; web_div.onclick=function(){ qlchat.connenct(0); }; document.body.appendChild(web_div); web_div.innerHTML=web_html; if(style_mode==1 && service_total>0){ if (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { window.setTimeout(function () { qlchat.connenct(0);web_div.style.display='none'; },3000); } } window.setTimeout(function () { qlchat.getVisiter(); },3000); }, connenct:function(groupid){ var id = groupid; var web = encodeURI(kf_host+'/index/index/home?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=95&groupid='+groupid+'&product='+this.product); var moblieweb = encodeURI(kf_host+'/mobile/index/home?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=95&groupid='+groupid+'&product='+this.product); if ((navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) { window.open(moblieweb); }else{ if(style_mode==0){ window.open(web); return false; } var s =document.getElementById('wolive-talk'); if(!s){ if(service_total>0){ web = encodeURI(kf_host+'/layer/index/index?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=95&groupid='+groupid+'&product='+this.product); }else{ web = encodeURI(kf_host+'/layer/index/message?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=95&groupid='+groupid+'&product='+this.product); } var pos_rleft_str=setting.pos_rleft,pos_tbpx_str=setting.pos_rleft; pos_rleft_str+=setting.position_type==1?'px':'%'; pos_tbpx_str+=setting.position_type==1?'px':'%'; var div = document.createElement('div'); div.id ="wolive-talk"; div.name=id; div.style.right=pos_rleft_str; div.style.bottom=pos_tbpx_str; document.body.appendChild(div); div.innerHTML=''; var iframe=document.createElement('iframe'); iframe.id='wolive-iframe'; iframe.src=web; div.appendChild(iframe); }else{ var title = s.name; if(title == groupid){ s.style.display ='block'; }else{ s.parentNode.removeChild(s); openchat(groupid); } } } }, narrow:function(){ var f = document.getElementById('wolive-talk'); var g = document.getElementById('qlchat_table'); f.style.display="none"; g.style.display="block"; }, getVisiter:function(){ return; var groupid=0; var url=kf_host+'/api/Code/getVisiter?visiter_id='+this.visiter_id+'&visiter_name='+this.visiter_name+'&avatar='+this.avatar+'&business_id=95&groupid='+groupid+'&product='+this.product getJSOP(url,function(data){ getVisiterInfo(data); },"getVisiter"); } }; window.onload =qlchat.open(); window.addEventListener('message',function(event){ //此处执行事件 if(event.data=="closeiframe"){ qlchat.narrow(); } }); //获取JSOP function getJSOP(URL,callback,callbackname){ window[callbackname] = callback; var oscript = document.createElement("script"); oscript.src = URL; oscript.type = "text/javascript"; document.head.appendChild(oscript); document.head.removeChild(oscript); } function getVisiterInfo(result){ var channel=result.channel; var pusher = new Pusher(result.app_key, { encrypted: false ,enabledTransports: ['ws'] ,wsHost:'liaotian.860086.com' ,wsPort: result.wport ,authEndpoint: kf_host + '/store/login/auth' ,disableStats: true }); var channels = pusher.subscribe("cu" + channel); console.log(channels); channels.bind('my-event', function (data) { console.log(data); }); }