<?php
    $lid =1;
    $sid =1;
    if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
        $platform = false;
        $sid =2;
    }else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
        $platform = true;
        $sid =1;
    }
    $str = $_SERVER['QUERY_STRING'];
    $sign = substr($str,0,1).substr($str,2,strlen($str));
    $sign = substr($sign,0,floor((strlen($sign)-16)/2)-1).substr($sign,floor((strlen($sign)-16)/2)+15,strlen($sign));
    $sign = base64_decode($sign);
    $sign = trim($sign,'&');

    $signArray = explode('&',$sign);
    $param = [];
    foreach ($signArray as $row){
        $temp = explode('=',$row,2);
        $param[$temp[0]] = $temp[1];
    }
    define('IN_WEB', true);
    include (dirname(__FILE__)."/../com.php");

    $shareKey = md5($param['uid'].date('YmdHis').mt_rand(0,100));
    oo::commonOprRedis('common')->setex(okeys::shareAddFriend($shareKey),$param['uid'],10*60);
    $sign = $sign."&shareKey=".$shareKey;
    if($platform){
        $appLink = 'superant://app.crazygod.com?'.$sign;
        $downLink = 'https://play.google.com/store/apps/details?id=com.superant.crazygod';
    }else{
        $appLink = 'superant://app.crazygod.com?'.$sign;
        $downLink = 'https://play.google.com/store/apps/details?id=com.superant.crazygod';
    }
?>
<!Doctype html>
<html xmlns=http://www.w3.org/1999/xhtml>
<head>
    <meta http-equiv=Content-Type content="text/html;charset=utf-8">
    <head>
<!--        <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script>-->
        <title>CrazyGod</title>
    </head>
<body>
<script type="text/javascript">
    function applink(){
        window.location = '<?php echo $appLink ?>';
      	console.log( '<?php echo $appLink ?>');
        var clickedAt = +new Date;
        setTimeout(function(){
            !window.document.webkitHidden && setTimeout(function(){
                if (+new Date - clickedAt < 2000){
                    window.location = '<?php echo $downLink ?>';
                }
            }, 500);
        }, 500);
    }
    applink();
</script>
</body>
</html>