<?php
session_start();
if(isset($_POST['text']) && $_POST['text'] == '520'){
    $_SESSION['ok'] = 1;
    header('location:?');
}
?>
<?php
$is_defend=true;
include("./includes/common.php");
@header('Content-Type: text/html; charset=UTF-8');

$qq=isset($_GET['qq'])?strip_tags($_GET['qq']):null;

$addsalt=md5(mt_rand(0,999).time());
$_SESSION['addsalt']=$addsalt;
include_once(SYSTEM_ROOT."hieroglyphy.class.php");
$x = new hieroglyphy();
$addsalt_js = $x->hieroglyphyString($addsalt);

$rs=$DB->query("SELECT * FROM shua_class WHERE active=1 order by sort asc");
$select='<option value="0">请选择分类</option>';
$shua_class[0]='默认分类';
while($res = $DB->fetch($rs)){
	$shua_class[$res['cid']]=$res['name'];
	$select.='<option value="'.$res['cid'].'">'.$res['name'].'</option>';
}

$select2='<option value="0">请选择商品</option>';

if($is_fenzhan==true && file_exists(ROOT.'assets/img/logo_'.$conf['zid'].'.png')){
	$logo = 'assets/img/logo_'.$conf['zid'].'.png';
}else{
	$logo = 'assets/img/logo.png';
}
if($conf['cdnserver']==1){
	$cdnserver = '//cdn.qqzzz.net/';
}else{
	$cdnserver = null;
}

if(!empty($conf['gg_announce']))$conf['anounce']=$conf['gg_announce'].$conf['anounce'];

if($is_fenzhan == true && $siterow['power']==1 && $siterow['ktfz_price']>0){
	$conf['fenzhan_price']=$siterow['ktfz_price'];
	if($conf['fenzhan_cost2']<=0)$conf['fenzhan_cost2']=$conf['fenzhan_price2'];
	if($siterow['ktfz_price2']>0 && $siterow['ktfz_price2']>=$conf['fenzhan_cost2'])$conf['fenzhan_price2']=$siterow['ktfz_price2'];
}

if($conf['ui_bing']==1){
	$background_image='//img-cdnw.b0.upaiyun.com/cdn/zip-img/'.rand(1,19).'.jpg!gzipimgw';
	$conf['ui_background']=3;
}elseif($conf['ui_bing']==2){
	if(date("Ymd")==$conf['ui_bing_date']){
		$background_image=$conf['ui_backgroundurl'];
		if(checkmobile()==true)$background_image=str_replace('1920x1080','768x1366',$background_image);
	}else{
		$url = 'http://cn.bing.com/HPImageArchive.aspx?format=js&idx=0&n=1';
		$bing_data = get_curl($url);
		$bing_arr=json_decode($bing_data,true);
		if (!empty($bing_arr['images'][0]['url'])) {
			$background_image='//cn.bing.com'.$bing_arr['images'][0]['url'];
			saveSetting('ui_backgroundurl', $background_image);
			saveSetting('ui_bing_date', date("Ymd"));
			$CACHE->clear();
			if(checkmobile()==true)$background_image=str_replace('1920x1080','768x1366',$background_image);
		}
	}
	$conf['ui_background']=3;
}else{
	$background_image='assets/img/bj.png';
}
if($conf['ui_background']==0)
$repeat='background-repeat:repeat;';
elseif($conf['ui_background']==1)
$repeat='background-repeat:repeat-x;
background-size:auto 100%;';
elseif($conf['ui_background']==2)
$repeat='background-repeat:repeat-y;
background-size:100% auto;';
elseif($conf['ui_background']==3)
$repeat='background-repeat:no-repeat;
background-size:100% 100%;';

if ($key = daddslashes($_GET['tgkey']))
if(!isset($_SESSION['ok'])){
    exit('
        <title>代刷网-防刷验证</title>
    <meta name="viewport" content="width=device-width, initial-scale=1"/>
    <link href="//lib.baomitu.com/twitter-bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet"/>
    <link href="//lib.baomitu.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
    <link rel="stylesheet" href="assets/simple/css/plugins.css">
    <link rel="stylesheet" href="assets/simple/css/main.css">
    <script src="//lib.baomitu.com/modernizr/2.8.3/modernizr.min.js"></script>
    <!--[if lt IE 9]>
      <script src="//lib.baomitu.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="//lib.baomitu.com/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<br/>
<img src="http://ww1.sinaimg.cn/large/006NhCa0gy1fq25goc4g8j30i20badgp.jpg" alt="Full Background" class="full-bg full-bg-bottom animated pulse " ondragstart="return false;" oncontextmenu="return false;">
<div class="col-xs-12 col-sm-10 col-md-8 col-lg-5 center-block" style="float: none;">
    <div class="block">
        <div class="block-title">
            <h2><i class="fa fa-share-alt"></i>&nbsp;&nbsp;<b>防 刷 验 证</b></h2>
        </div>
			<div class="form-group">
				<div class="alert alert-info alert-dismissable">
					<span id="loginmsg">注：为防止流量宝恶意刷单请输入密码 520 即可！</span><span id="loginload" style="padding-left: 10px;color: #790909;">.</span>
				</div>
			<div class="form-group">
				<div class="input-group"><div class="input-group-addon">请输入访问密码</div>
				<form method="post">
				<input type="text" name="text" class="form-control" placeholder="密码为520"required="required"/>
			</div></div>
			  <input type="submit" value="我确认我不是机器" class="btn btn-primary btn-block"/>
			  </form>
			<div id="resulturl" style="display:none;">
			</div>
			</div>
			<hr>
			<div class="form-group">
			<a href="../" class="btn btn-primary btn-rounded"><i class="fa fa-home"></i>&nbsp;返回主页</a>
			<a href="user/reg.php" class="btn btn-danger btn-rounded" style="float:right;"><i class="fa fa-user-plus"></i>&nbsp;开通分站</a>
			</div>
        </div>
      </div>
    </div>
  </div>
<script src="//lib.baomitu.com/jquery/1.12.4/jquery.min.js"></script>
<script src="//lib.baomitu.com/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script src="//lib.baomitu.com/layer/2.3/layer.js"></script>

    ');
}
{
	$day = 1;//天数领取
	$tg_row = $DB->get_row("SELECT * FROM `shua_tg` WHERE (`key`='{$key}') LIMIT 1");
	if ($tg_row)
	{
		$tglog_row = $DB->get_row("SELECT *,DATE_ADD(date,INTERVAL {$day} DAY) as date FROM `shua_tglog` WHERE (`ip` = '{$clientip}' AND `date` < '{$date}' )LIMIT 1");
		if ($tglog_row == '')
		{
			echo '<script>alert(\'欢迎来到' . $conf['sitename'] . '\');window.location.href=\''.($_SERVER['SERVER'] == 443 ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].'/?buyok=1\'</script>'; 
			$tool_id = 1;//赠送商品tid , 注意：1、该商品前提必须要对接社区，否则订单不会处理 2、建议商品为下架状态，留作送奖励用的 tid 格式如下：daishua_sxaxs/shopedit.php?my=edit&tid=1 &tid=1的1就是商品id
			$tool = $DB->get_row("SELECT * FROM `shua_tools` WHERE (`tid` = '{$tool_id}' AND `is_curl`=2) LIMIT 1");
			$tid = $tool['tid'];
			$money = $tool['price']; //商品金额
			$status = 1; //订单状态
			$trade_no=date("YmdHis").rand(111,999); 
			$DB->query("INSERT INTO `shua_pay`(`trade_no`,`type`,`zid`,`tid`,`input`,`num`,`addtime`,`endtime`,`name`,`money`,`ip`,`userid`,`status`) VALUES
			('{$trade_no}','qqpay','" . ($siterow['zid']?$siterow['zid']:1) . "',{$tid},'{$tg_row['userqq']}',1,'{$date}','{$date}','推广商品','{$money}','{$clientip}','{$cookiesid}',1)");
			$id = $DB->insert("INSERT INTO `shua_orders`(`tid`,`zid`,`input`,`value`,`status`,`djzt`,`userid`,`tradeno`,`money`,`addtime`,`endtime`) VALUES
			({$tid},'" . ($siterow['zid']?$siterow['zid']:1) . "','{$tg_row['userqq']}',1,0,2,'{$cookiesid}','{$trade_no}',{$money},'{$date}','{$date}')");
			do_goods($id);
			$DB->query("INSERT INTO `shua_tglog` (`userqq`,`zid`,`date`,`ip`,`trade_no`) VALUES
			('{$tg_row['userqq']}','" . ($siterow['zid']?$siterow['zid']:1) . "','{$date}','{$clientip}','{$trade_no}')");
		} else {
			echo '<script>alert(\'您今天已经帮助过好友，请隔'.$day.'天在来领取\');window.location.href=\''.($_SERVER['SERVER'] == 443 ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'].'/?buyok=1\';</script>';
		}
		//header('Location:?buyok=1');
	}
}
$mod = isset($_GET['mod'])?$_GET['mod']:'index';
$loadfile = Template::load($mod);
include $loadfile;
