<?php
$first=json_decode(file_get_contents("conn/config.json"))->first;

if($first=="1"){
    Header("Location: install");
    die();
}
require 'conn/conn.php';
require 'conn/function.php';

$s=array_keys($_GET);
$s=intval(dec10($s[0]));
$action=$_GET["action"];
if($action=="up"){
	$id=intval($_GET["id"]);
	$time=date('Y-m-d H:i:s');
	mysqli_query($conn,"insert into sl_orders(O_title,O_attach,O_money,O_time) values('短网址升级永久','$id',".$C_urlprice.",'$time')");
	$notify_url=gethttp().$_SERVER["HTTP_HOST"]."/pay/notify_url.php";
	$return_url=gethttp().$_SERVER["HTTP_HOST"]."/pay/return_url.php";
	$no=getrs("select O_id from sl_orders where O_title='短网址升级永久' and O_time='$time' order by O_id desc","O_id");
	$sign=strtolower(md5("body=短网址升级永久&fee=".$C_urlprice."&no=".date('YmdHis').$no."&notify_url=".$notify_url."&pid=".$C_pid."&remark=".$no."&return_url=".$return_url."&key=".$C_pkey));
	Header("Location: https://7-pay.cn/pay.php?body=短网址升级永久&fee=".$C_urlprice."&no=".date('YmdHis').$no."&notify_url=".$notify_url."&pid=".$C_pid."&remark=".$no."&return_url=".urlencode($return_url)."&sign=".$sign);
}
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimal-ui">
    <title><?php echo $C_title?></title>
    <meta name="description" content="<?php echo $C_description?>" />
    <meta name="keywords" content="<?php echo $C_keyword?>" />
    <link href="media/<?php echo $C_ico?>" rel="shortcut icon" />
	<link href="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/css/bootstrap.min.css" rel="stylesheet">
	<script src="https://cdn.bootcdn.net/ajax/libs/jquery/2.2.4/jquery.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/twitter-bootstrap/3.4.1/js/bootstrap.min.js"></script>
	<script src="https://cdn.bootcdn.net/ajax/libs/qrcodejs/1.0.0/qrcode.min.js"></script>
	<style type="text/css">
	html{height: 100%}
	body{background: #f7f7f7;height: 100%}
	.main{width: 100%;max-width: 750px;margin:0px auto;padding: 10px;background: #ffffff;box-shadow: 0 2px 17px 2px #DDDDDD;padding: 30px;position: relative;margin-bottom: 20px;}
	.pop {width: 100%;height: 100%;position: fixed;top: 0;left: 0;background: rgba(0,0,0,.7);z-index: 999;}
	#msg{font-size: 12px;color: #ff0000;}
</style>
<script type="text/javascript">
function creat(){
	$("#copymsg").html("");
	$.ajax({
	        type: "post",
	        url: "creat.php",
	        data: $("#form").serialize(),
	        success: function(data) {
				data=JSON.parse(data);
				if(data.code=="success"){
					$('#myModal').modal('show');
					$("#short").val(data.short);
					$("#urlup").attr("href","?action=up&id="+data.id);
		            qrcode.makeCode(data.short);

		            $("#msg").html("");
		            if(data.vip==1){
		            	$("#vip").hide();
		            }
				}else{
					$("#msg").html(data.msg);
				}
	        }
	    })
}
function copy(){
		var e=document.getElementById("short");//对象是content 
        e.select(); //选择对象 
        document.execCommand("Copy"); //执行浏览器复制命令
        $("#copymsg").html("复制成功");
	}
function isWeiXin(){
        var ua = window.navigator.userAgent.toLowerCase();
        if (ua.match(/MicroMessenger/i) == 'micromessenger') {
            return true; // 是微信端
        } else {
            return false;
        }
    }
function isQQ(){
        if(navigator.userAgent.toLowerCase().toString().indexOf('qqbrowser') > -1){
            return true; // 是QQ端
        } else {
            return false;
        }
    }
</script>
</head>
<body>
<?php
if(array_keys($_GET)[0]!=""){
	$sql="select * from sl_short where S_id=".$s." and (TIMESTAMPDIFF(DAY,S_time,DATE_FORMAT(now(),'%Y-%m-%d'))<".$C_day." or S_vip=1)";
	$result = mysqli_query($conn, $sql);
	$row = mysqli_fetch_assoc($result);
	if(mysqli_num_rows($result) > 0) {

		mysqli_query($conn,"update sl_short set S_times=S_times+1 where S_id=".$s);
		$url=$row["S_url"];
		$url=urldecode($url);
		$S_vip=$row["S_vip"];
?>
<div class="pop none" id="divpop" style="display:none;" >
　　<img src="images/top.png" style='float: right;margin: 10px;max-width: calc(100% - 20px)'>
<div style="color: #ffffff;text-align: center;margin-top:300px">
<h3>
即将跳转到网址
</h3>
<p>
	<?php echo $url?>
</p>
<?php
if($C_adprice3>0 && $S_vip==0){
	$sql="select * from sl_ad where A_type=2 and TIMESTAMPDIFF(MONTH,A_time,DATE_FORMAT(now(),'%Y-%m-%d'))<A_long order by A_order,A_id desc";
	$result = mysqli_query($conn,  $sql);
	if (mysqli_num_rows($result) > 0) {
	while($row = mysqli_fetch_assoc($result)) {
		echo "<a href=\"".$row["A_url"]."\"><img src=\"../media/".$row["A_pic"]."\" style=\"width:100%;position:absolute;bottom:0px;left:0px;\"></a>";
	    }
	} 
}
?>
</div>
</div>
<?php
		echo "<script>
			if(isWeiXin() || isQQ()){
				$('#divpop').show();
			}else{
				window.location.href='".$url."';
			}
			</script>";
		//header("Location: ".$url);
		//die($url);
	}else{
		die("{\"code\":\"error\",\"msg\":\"该短网址已失效，请重新生成\",\"S_id\":\"".$s."\"}");
	}
}else{
$_SESSION["ym"]=time();
?>
<div class="main">
<img src="media/<?php echo $C_logo?>" style="height: 70px;">
<div style="float: right;font-size: 15px;margin-top: 20px;font-weight: bold;">生成短网址并绕过域名拦截</div>

</div>
<div class="main">
<form id="form" onsubmit="creat();return false;">
	<p><input type="text" class="form-control input-lg" name="url" placeholder="输入网址" id="url"></p>
	<p><iframe id="slide" src="conn/code_1.php?name=M_code" scrolling="no" frameborder="0" width="100%" height="40"></iframe></p>
	<button type="submit" class="btn btn-primary btn-block btn-lg" >生成短网址</button>
</form>
<span id="msg"></span>
</div>
<?php
if($C_adprice1>0 || $C_adprice2>0){
?>
<div class="main">
		<div class="row" style="font-size: 12px;text-align: center;margin-bottom: 10px;">
			<?php
			if($C_adprice1>0){
				$sql="select * from sl_ad where A_type=0 and TIMESTAMPDIFF(MONTH,A_time,DATE_FORMAT(now(),'%Y-%m-%d'))<A_long order by A_order,A_id desc";
				$result = mysqli_query($conn,  $sql);
				if (mysqli_num_rows($result) > 0) {
				while($row = mysqli_fetch_assoc($result)) {
					if($row["A_red"]==1){
						$red="color:#ff0000;";
					}else{
						$red="";
					}
					if($row["A_bold"]==1){
						$bold="font-weight:bold;";
					}else{
						$bold="";
					}
					echo "<div class=\"col-md-4\" style=\"white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    word-break: break-all;\"><a href=\"".$row["A_url"]."\" target=\"_blank\" style=\"".$red.$bold."\">".$row["A_text"]."</a></div>";
				    }
				} 
			}
			?>
			<div class="col-md-4">广告位招租：<?php echo $C_adprice1?>元/月 <a href="member/ad.php" class="btn btn-xs btn-info">申请</a></div>
		</div>
<hr>
		<div class="row">
			<?php
			if($C_adprice2>0){
				$sql="select * from sl_ad where A_type=1 and TIMESTAMPDIFF(MONTH,A_time,DATE_FORMAT(now(),'%Y-%m-%d'))<A_long order by A_order,A_id desc";
				$result = mysqli_query($conn,  $sql);
				if (mysqli_num_rows($result) > 0) {
				while($row = mysqli_fetch_assoc($result)) {
					echo "<div class=\"col-md-3 col-xs-6\"><a href=\"".$row["A_url"]."\" target=\"_blank\">
					<div style=\"background-image: url(media/".$row["A_pic"]."); background-repeat: no-repeat; background-position: center center; width: 150px; height: 82px; background-size: cover;margin-bottom:10px; \"></div>
					</a></div>";
				    }
				} 
			}
			?>
			<div class="col-md-3 col-xs-6" style="font-size: 12px;text-align: center;">广告位招租：<?php echo $C_adprice2?>元/月 <a href="member/ad.php" class="btn btn-xs btn-info btn-block">申请</a></div>
		</div>
</div>
<?php }?>
<div class="main">
<div style="border-bottom: solid 1px #DDDDDD;margin-bottom: 5px;padding-bottom: 5px;width: 100%;font-size: 12px">
友情链接：
<?php
$sql="select * from sl_link order by L_order,L_id desc";
				$result = mysqli_query($conn,  $sql);
				if (mysqli_num_rows($result) > 0) {
				while($row = mysqli_fetch_assoc($result)) {
					echo " <a href=\"".$row["L_url"]."\" target=\"_blank\">".$row["L_title"]."</a>";
				    }
				} 
?>
</div>

<img src="media/<?php echo $C_logo?>" style="height: 50px;">
<div style="display: inline-block;margin-top: 10px;vertical-align: top;border-left: solid 1px #DDDDDD;padding-left: 10px;font-size: 12px">
<?php echo "<a href=\"https://beian.miit.gov.cn/\" target=\"blank\">".$C_beian."</a> <a href=\"http://wpa.qq.com/msgrd?v=3&uin=".$C_qq."&site=qq&menu=yes\">客服QQ：".$C_qq."</a> ".$C_code?><br>
<?php echo $C_copyright?>
</div>
</div>

<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
	<div class="modal-dialog">
		<div class="modal-content">
			<div class="modal-header">
				<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
					&times;
				</button>
				<h4 class="modal-title" id="myModalLabel">
					短网址生成
				</h4>
			</div>
			<div class="modal-body" style="text-align: center;" id="modal_body">
				<div id="billImage" style="width: 200px;display: inline-block;margin-bottom: 10px"></div>
				<p>
					<div class="input-group">
						<span class="input-group-addon">短网址</span>
	                    <input type="text" class="form-control" id="short">
	                    <span class="input-group-btn">
	                        <button class="btn btn-info" type="button" onclick="copy()">复制</button>
	                    </span>
	                </div>
	                <div id="copymsg" style="font-size: 12px;margin-top: 10px;color: #009900"></div>
	            </p>
	            <p id="vip">当前短网址有效期为<?php echo $C_day?>天，<a href="" class="btn btn-xs btn-primary" id="urlup">支付<?php echo $C_urlprice?>元</a> 升级到永久有效并去除广告</p>

			</div>
		</div>
	</div>
</div>
<?php
}
?>
<script type="text/javascript">
var qrcode = new QRCode('billImage', {width: 200,height: 200,colorDark: '#000000',colorLight: '#ffffff',correctLevel: QRCode.CorrectLevel.H});
</script>
</body>
</html>