<?php

//WeCaller电话客服系统
//独立窗口进入客服, web和移动端统一链接文件, 如要选择进入某用户组请加参数, 如：..../kefu.php?a=632678691&g=客服组id

//正式开始
$a = 0;
if(isset($_GET['a'])) $a = intval($_GET['a']);

if($a !== 632678691) die('Access denied.'); //简单地防止直接访问当前文件

?>

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<script type="text/javascript">
//获取cookie
function wecaller_getCookie(n){
	var a = document.cookie.match(new RegExp("(^| )" + n + "=([^;]*)(;|$)"));
	if (a != null) return a[2];
	return "";
}

//WeCaller安装后所在URL, 相对地址或绝对地址, 以 / 结尾
var wecaller_url = "./";

//原网站用户id ---用户接口
var wecaller_id = wecaller_getCookie("wecaller_id");

//原网站用户名或昵称fullname ---用户接口
var wecaller_fn = wecaller_getCookie("wecaller_fn");

//防机器人编码
var wecaller_code = 632678691;

//判断是否为移动设备
var wecaller_mobile = navigator.userAgent.match(/(iPhone|Android|iPod|ios|iPad|Windows ce|Windows mobile|Micromessenger|webOS|Ucweb|UCBrowser|BlackBerry|midp|rv:1.2.3.4)/i);

var wecaller_link = "";

window.onload=function(){
	//当前页面URL
	var url = window.location.href;

	//指定的客服组id
	var wecaller_groupid = parseInt(url.substring(url.indexOf("g=") + 2));

	//来自页面的URL
	var fromurl = '';

	if(typeof(document.referrer) != 'undefined' && document.referrer.length > 0) {
		fromurl = document.referrer;
	}else{
		try {
			if (typeof(opener.location.href) != 'undefined' && opener.location.href.length > 0) {
				fromurl = opener.location.href;
			}
		}catch(e){}
	}

	url = fromurl ?  window.btoa(fromurl) : window.btoa(url);

	//根据设备跳转的链接不同
	if(wecaller_mobile){ //mobile
		wecaller_link = "mobile/wecaller.php";
	}else{ //web
		wecaller_link = "wecaller.php";
	}

	window.location.href = wecaller_url + wecaller_link + "?a=" + wecaller_code + "&group=" + wecaller_groupid + "&id=" + wecaller_id + "&fn=" + wecaller_fn + "&r=" + Math.random() + "&url=" + url;
}
</script>
</head>
<body>
</body>
</html>