<?php if(!defined('ONGPHP'))exit('Error ONGSOFT');

// $a[1] = 320;
// $a[2] = 328;
// $a[3] = 313;

// arsort($a);

// dump($a);exit;
if(strpos($_SERVER['HTTP_USER_AGENT'], 'iPhone')||strpos($_SERVER['HTTP_USER_AGENT'], 'iPad')){
    
}else if(strpos($_SERVER['HTTP_USER_AGENT'], 'Android')){
    
}else{
    //exit;
}

plus( array('p','jiami','jianli','mima','shanchu','qcurl','qfopen','x','memcc','txtcc','db','isutf8','setsession','pagec','pinyin','ip','post','funciton','sslget','sslpost','vcode','update','mysqlcc') );

if($CONN['HTTP'] != '' || $CONN['WAPHTTP'] != ''){

          if( $CONN['HTTP'] != $_SERVER ['HTTP_HOST'] && $CONN['WAPHTTP'] != $_SERVER ['HTTP_HOST']  ){

                header('HTTP/1.1 301 Moved Permanently');

                if( $CONN['HTTP'] == '') Header("Location: ".$HOSTQZ.$CONN['WAPHTTP']);
                else                     Header("Location: ".$HOSTQZ.$CONN['HTTP']);
                exit();
          }
}


$Memsession =  $Mem = new txtcc();
$Mem1 = new txtcc(ONGPHP.'/mode/');
$shezhi = $Mem1 -> g('shezhi');

setsession( $CONN['sessiontime'] );

if($shezhi['weihu']){
    
	if($_GET['chenxi']!="123456"){
		msgbox('系统正在维护中，请加QQ群'.$shezhi['weixinqq'].'即时获取最新资讯哦', "http://baidu.com");
    exit;
	}
    
}

$ip = ip();


$D = db('');

$uidw = isset($_GET['uidw']) ? $_GET['uidw'] :'';
$key = isset($_GET['key']) ? $_GET['key'] :'';
$bendikey = md5('wuwei'.$uidw);

if ($key!='' && $uidw!='' ) {

  if ($bendikey==$key) {
  /*查询是否有该会员*/
  $huiyuan = $D ->setbiao('user')-> where( array( "uid" => $uidw ) ) -> find();
  if ($huiyuan) {
    
    $_SESSION['uid'] = $uidw;

  }

  }
}

//$_SESSION['uid'] = '4';

$appid = $shezhi['appid'];
$appsecret = $shezhi['appsecret'];

$tuid = isset($_GET['tuid']) ? $_GET['tuid'] :'';
$fenxiao = isset($_GET['fenxiao']) ? $_GET['fenxiao'] :'';
//dump($fenxiao);exit;
if ($fenxiao!='') {

  $_SESSION['adminid'] = $fenxiao;

}


if ($tuid!='') {

  $_SESSION['tuid'] = (float)$tuid;

}

//$_SESSION['uid'] = '';

if ( $_SESSION['uid'] ) {
    /*查询会员*/


    $huiyuans = $D ->setbiao('user')-> where( array( "uid" => $_SESSION['uid'] ) ) -> find();
    // var_dump($huiyuans);
}







if (isset($huiyuans)  && is_array($huiyuans) ) {
    
    

}else{

    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    if (strpos($user_agent, 'MicroMessenger') === false) {
    // 非微信浏览器禁止浏览
       //$_GET['action'] = "fenxiang";
        $_SESSION['uid'] = -1;
        $_GET['action'] = "fenxiang";
        
        
    }else{

       if ($shezhi['tiaozhuan']!='') {


		$redirect_uri = urlencode ( $shezhi['tiaozhuan'].'weixin.php' );
           $url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
           
           $_SESSION['backurl'] = $shezhi['youxiyuming'];
           
           header("Location:".$url);
           exit();

    }else{
    
		
	
      $wangzhi = WZHOST;
      $redirect_uri = urlencode ( $wangzhi.'weixin.php' );
      $url ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=$appid&redirect_uri=$redirect_uri&response_type=code&scope=snsapi_userinfo&state=1#wechat_redirect";
      
  
      $_SESSION['backurl'] = $wangzhi."index.php";

      header("Location:".$url);
      exit();

    }

  


  }



}
 





$LOCK = ONGPHP.'dsoft.lock';

if( !file_exists( $LOCK ) ){

    msgbox('','install.php');

}
if( ! (mb_detect_encoding($URI, 'UTF-8') === 'UTF-8')   ) $URI = iconv( "gb2312" , "UTF-8//IGNORE" ,$URI);

$HUOBI = huobi( $CONN,2 );

$HUOBIICO = array( '￥' , $CONN['jifen'] ,  $CONN['huobi'] , $CONN['hongbao'] );


if( strstr( $URI , $CONN['houzui'].'&')) $URI = str_replace( $CONN['houzui'].'&' , $CONN['houzui'].'?', $URI);

$URI  = ltrim( str_replace( array( '//' , trim( $_SERVER['SCRIPT_NAME'] , '/' ) ), array( '/' , '' ) , $URI ) , $CONN['dir'] );
$TURI = explode( '?' , ltrim( $URI ,'?'));
$URI  = trim( $TURI['0'] , '/');

if( strstr( $URI , '.' )) $URI = str_replace( $CONN['houzui'] , '', $URI);
else                      $URI = 'index';

/*再次强行容错*/
if( $URI == '' ) $URI = 'index';
$HTTP = explode( $CONN['fenge'] , $URI);

$LANG = include QTLANG;

if( count ( $HTTP ) > $CONN['fengenum'] ) error404( $LANG['ERfgum'] );
if( strstr( $URI , '.php' ))              error404( $LANG['ERffhz'] );

if( ( $CONN['huanchun'] > 0 || isset( $_GET['huan']) ) && $HTTP['0'] != $CONN['userword'] ){

    if(  $CONN['yunxing'] == 3)
        $WENJIAN = wlx( ONGPHP.'../'.$URI.'.html' , 2);
    else $WENJIAN = Txpath.'html/'.mima( $CONN['qtpl']. $URI).'.html';

    if( file_exists( $WENJIAN)){ 

        clearstatcache();
        $guoqitime = filemtime( $WENJIAN ) + $CONN['huanchun']; 
        $dangqtime = time();

        if( $dangqtime < $guoqitime){

            $fp = qfopen( $WENJIAN , 'utf-8');
            if( ! isset( $_GET['huan'])) echo $fp;
            die;
        }

        if( isset( $_GET['huan'])) @unlink($WENJIAN);
    }
}


$PAGE = (float)( isset($HTTP['1']) ? $HTTP['1'] : 1 );



$action = isset($_GET['action']) ? $_GET['action'] :'index';
if ($action=='index') {
	  if($_GET['openid']){

        $D = db('');
        $where = array(

            'uid'=>$_SESSION['uid']
            //'iskaijiang' =>1
        ) ;

        $update = array(

            'txopenid'=>$_GET['openid']
            //'iskaijiang' =>1
        ) ;

        //$result = $D->setbiao('user')->where($where)->find();

        $result = $D->setbiao('user')->where($where)->update($update);
         include QTPL.'index.php';
		exit;
    }
    $D = db('');
    $where = array(

        'uid'=>$_SESSION['uid']
    ) ;

    $result = $D->setbiao('user')->where($where)->find();

    if(empty($result['txopenid'])){
        $url = $shezhi['lingurl']."openid.php?mid=".$shezhi['linguid']."&url=".WZHOST."?action=index";
        header("Location:".$url);
    }

    include QTPL.'index.php';
    exit;

}else if ($action=='zhuye') {
	include QTPL.'zhuye.php';
     exit;
    
    if($shezhi['weixintixian'] == 1){
    
        if($_GET['openid']){
    
            $openid = $_GET['openid'];
            $update = array(
                 
                'txopenid'=>$openid
                //'iskaijiang' =>1
            ) ;
    
            //$result = $D->setbiao('user')->where($where)->find();
    
            $where = array(
                 
                'uid'=>$_SESSION['uid']
                //'iskaijiang' =>1
            ) ;
    
            $result = $D->setbiao('user')->where($where)->update($update);
    
        }
    
   
		 if(empty($huiyuans['txopenid'])){

        $_SESSION['dhurl'] = 2;//1表示游戏提现2表示佣金提现
        $url = $shezhi['lingurl']."openid.php?mid=".$shezhi['linguid']."&url=".WZHOST."?action=index";
        header("Location:".$url);

    }
    
        include QTPL.'zhuye.php';
        exit;
    }
    
}else if ($action=='jifenlog') {

	include QTPL.'jifenlog.php';
	

}else if ($action=='chanpin') {

	$result = chanpin();
	dump($result);exit;
    $result = json_encode($result);
    
    dump($result);exit;

}else if ($action=='login') {

	//include QTPL.'index.php';
	include QTPL.'login_id.php';

}elseif ($action=='myDetail') {

	include QTPL.'myDetail.php';

}elseif ($action=='duihuanlog') {

  include QTPL.'duihuanlog.php';

}elseif ($action=='duihuandetail_type') {

  include QTPL.'duihuandetail_type.php';

}elseif ($action=='paihang') {
  
  include QTPL.'paihang_y.php';

}elseif ($action=='ajax') {
   include QTPL.'ajax.php';
}elseif ($action=='tixian') {

  include QTPL.'tixian.php';

}elseif ($action=='chongzhi') {

   
    
    include QTPL.'chongzhi.php';
    exit;
  

}elseif ($action=='me') {
  
    include QTPL.'userindex.php';
    
    exit;
if($_GET['openid']){
	
	$D = db('');
	$where = array(
         
        'uid'=>$_SESSION['uid']
        //'iskaijiang' =>1
    ) ;
    
	$update = array(
         
        'txopenid'=>$_GET['openid']
        //'iskaijiang' =>1
    ) ;
	
    //$result = $D->setbiao('user')->where($where)->find();
	
	$result = $D->setbiao('user')->where($where)->update($update);
	//dump($result);
	
	if($_SESSION['dhurl']==1){
	    include QTPL.'duihuan.php';exit;
	}else{
	    include QTPL.'duihuan_y.php';exit;
	}
	
	
}
  //include QTPL.'me.php';
    include QTPL.'geren.php';
    
}elseif ($action=='fenxiang') {
  
   include QTPL.'fenxiang.php';
  
}elseif ($action=='jilu') {
  
  include QTPL.'jilu.php';

}elseif ($action=='kefu') {

   include QTPL.'kefu.php';
   
}elseif ($action=='daili') {//赚钱

   include QTPL.'daili.php';
   
}elseif ($action=='myChild') {//赚钱

   include QTPL.'myChild.php';
   
}elseif ($action=='paihangj') {//竞猜达人

   include QTPL.'paihang_j.php';
   
}elseif ($action=='paihangy') {//邀请达人

   include QTPL.'paihang_y.php';
   
}elseif ($action=='orderlog') {//交易明细

   include QTPL.'jiaoyi.php';
   
}elseif ($action=='xinshou') {//交易明细yongjiurukou

   include QTPL.'xinshou.php';
   
}elseif ($action=='tousu') {//交易明细yongjiurukou

   include QTPL.'tousu.php';
   
}elseif ($action=='yongjiurukou') {//交易明细yongjiurukou

   include QTPL.'yongjiurukou.php';
   
}elseif ($action=='duihuan') {//游戏兑换
	include QTPL.'duihuan.php';
    exit;

    if($_GET['openid']){
    
        $openid = $_GET['openid'];
        $update = array(
             
            'txopenid'=>$openid
            //'iskaijiang' =>1
        ) ;
    
        //$result = $D->setbiao('user')->where($where)->find();
    
        $where = array(
             
            'uid'=>$_SESSION['uid']
            //'iskaijiang' =>1
        ) ;
    
        $result = $D->setbiao('user')->where($where)->update($update);
    
    }
	 if(empty($huiyuans['txopenid'])){

        $_SESSION['dhurl'] = 2;//1表示游戏提现2表示佣金提现
        $url = $shezhi['lingurl']."openid.php?mid=".$shezhi['linguid']."&url=".WZHOST."?action=index";
        header("Location:".$url);

    }
    
    include QTPL.'duihuan.php';
    exit;
    
   
    
   
}elseif ($action=='kuandianshoukuantb') {
	
	
	$myappid="2017110173";//您的APPID
    $appkey="e9788b9c0568fc95c6191b047786b308";//您的APPKEY
//***********************
header("Content-Type: text/html; charset=utf-8");
if(!isset($_REQUEST['appid'])||!isset($_REQUEST['tno'])||!isset($_REQUEST['payno'])||!isset($_REQUEST['money'])||!isset($_REQUEST['typ'])||!isset($_REQUEST['paytime'])||!isset($_REQUEST['sign'])){
	exit('参数错误');
}
$appid=(int)$_REQUEST['appid'];
$tno=$_REQUEST['tno'];//交易号 支付宝 微信 财付通 的交易号
$payno=$_REQUEST['payno'];//网站充值的用户名
$money=$_REQUEST['money'];//付款金额 
$typ=(int)$_REQUEST['typ'];
$paytime=$_REQUEST['paytime'];
$sign=$_REQUEST['sign'];
if(!$appid||!$tno||!$payno||!$money||!$typ||!$paytime||!$sign){
	exit('参数错误');
}
if($myappid!=$appid)exit('appid error');
//sign 校验
if($sign!=md5($appid."|".$appkey."|".$tno."|".$payno."|".$money."|".$paytime."|".$typ)){
	exit('签名错误');
}
//处理用户充值
		if($typ==1){
			$typname='手工充值';
		}else if($typ==2){
			$typname='支付宝充值';
		}else if($typ==3){
			$typname='财付通充值';
		}else if($typ==4){
			$typname='手Q充值';
		}else if($typ==5){
			$typname='微信充值';
		}
		
		if(!$tno)exit('没有订单号');
		if(!$payno)exit('没有付款说明');
	//************以下代码自己写	
		//查询数据库 交易号tno是否存在  tno数据库充值表增加个字段 长度50 存放交易号
		
		//已经存在输出 存在 跳转到充值记录或其他页面 交易号唯一 
		
		//不存在 查询用户是否存在
		
		//用户存在 增加用户充值记录 写入交易号
		
		//给用户增加金额 
		
		//处理成功
	
	
}elseif ($action=='getip') {
  echo "<pre>";
  var_dump( $ipp );
  echo "</pre>";

}elseif ($action=='qianyinzhifu') {
    
    
    header("Content-type:text/html;charset=utf-8");
    $data=$_GET;       //post方式获得表单提交的数据
    $data['jine'] = (int)$data['jine'];
	
    $shop_id= 1560;         //商户ID，商户在千应官网申请到的商户ID
    $bank_Type=$data['type'];   //充值渠道，101表示支付宝快速到账通道102微信通道
    $bank_payMoney=$data['jine'];     //充值金额
    $orderid=time().time();   //商户的订单ID，【请根据实际情况修改】

    //加入数据库
    $token=$_SESSION['uid'];                                                 //自定义传过来的值 千应平台会返回原值
    
    
                
    $callbackurl=$shezhi['youxiyuming'].'qianyinyibu.php';        //商户的回掉地址，【请根据实际情况修改】
    
    $gofalse=$shezhi['youxiyuming'].'?action=chongzhi';                      //订单二维码失效，需要重新创建订单时，跳到该页
    
    $gotrue=$shezhi['youxiyuming'].'qianyintongbu.php';                          //支付成功后，跳到此页面
    
    $key = "393a1fc2efd944b8b872c6400d1784bf";                   //密钥
    $posturl='http://www.qianyingnet.com/pay/';                   //千应api的post提交接口服务器地址
    
    $charset="utf-8";                                              //字符集编码方式
    
    $parma='uid='.$shop_id.'&type='.$bank_Type.'&m='.$bank_payMoney.'&orderid='.$orderid.'&callbackurl='.$callbackurl;     //拼接$param字符串
    $parma_key=md5($parma . $key);                                 //md5加密
    $PostUrl=$posturl."?".$parma."&sign=".$parma_key."&gofalse=".$gofalse."&gotrue=".$gotrue."&charset=".$charset."&token=".$token;       //生成指定网址
    
    
    //跳转到指定网站
    if (isset($PostUrl))
    {
        header("Location: $PostUrl");
        exit;
    }else{
        echo "<script type='text/javascript'>";
        echo "window.location.href='$PostUrl'";
        echo "</script>";
    };
    
    
}elseif ($action=='bankzhifu') {
	
	header("Content-type:text/html;charset=utf-8");
	$data=$_GET; 
    
	$data['jine'] = (float)$data['jine'];
	
	if($data['jine']<=1){
		$data['jine'] = 1;
	}
	
	$orderid = date(Ymd).rand(1111,9999).time();
	//$result = $D->setbiao('user')->where($tiaojian)->find($insert);签名验证(attach+cburl+cid+orderid+total_fee+key的MD5值，大写)
	
	$insert['uid'] = $_SESSION['uid'];
    //$insert['name'] = $result['name'];
    $insert['type'] = 0;
	$insert['orderid'] = $orderid;
    $insert['jine'] = $data['jine'];
    
    $insert['ip'] = ip();
    $insert['atime'] = time();
    
    
    $result = $D->setbiao('bankdingdan')->insert($insert);
	
	if(!$result){
		
		exit('网络不好');
		
	}
	
	//$attach = $_SESSION['uid'];
	
	$jine   = (int)($data['jine']*100);
	
	$cburl  = urlencode(WZHOST);
	$parma  = WZHOST.'2143'.$orderid.$jine.'1e9103c96a451ee6dd8aec85b5e78226';
	
	$sign = md5($parma);
	$sign = strtoupper($sign);
	
	//dump($cburl);exit;
    $url = "http://pay.5iyx.com.cn/shownutspay/wxpay.jsp?cid=2143&orderid=".$orderid."&total_fee=".$jine."&cburl=".$cburl."&sign=".$sign;
	
	//echo  $url;exit;
	header("Location: $url");
    exit;

    
}elseif ($action=='qqzhifu') {
	
	header("Content-type:text/html;charset=utf-8");
	$data=$_GET; 
    
	$data['jine'] = (float)$data['jine'];
	
	if($data['jine']<=1){
		$data['jine'] = 1;
	}
	
	$orderid = date(Ymd).rand(1111,9999).time();
	//$result = $D->setbiao('user')->where($tiaojian)->find($insert);签名验证(attach+cburl+cid+orderid+total_fee+key的MD5值，大写)
	
	$insert['uid'] = $_SESSION['uid'];
    //$insert['name'] = $result['name'];
    $insert['type'] = 0;
	$insert['orderid'] = $orderid;
    $insert['jine'] = $data['jine'];
    
    $insert['ip'] = ip();
    $insert['atime'] = time();
    
    
    $result = $D->setbiao('bankdingdan')->insert($insert);
	
    
	if(!$result){
		
		exit('网络不好');
		
	}
	$jine   = (int)($data['jine']*100);
	$CANSHU = array(  'cid'  => "2161" ,
	    
	    'total_fee' => $jine,
	    'title' => "欢迎欢迎",
	    'platform' => "TEN_CR",
	    'attach'=>$_SESSION['uid'],
	    
	    'orderno' => $orderid,
	    
	);
	//$attach = $_SESSION['uid'];
	
	$parma  = $CANSHU['attach'].$CANSHU['cid'].$CANSHU['orderno'].$CANSHU['title'].$CANSHU['total_fee'].$CANSHU['platform'].'4bd7317a987909c9af8f5f4a0cc19ae4';
	
	$sign = md5($parma);
	$sign = strtoupper($sign);
	
	$CANSHU['sign'] = $sign;
	//dump($CANSHU);exit;
	$url="http://121.196.213.236/xjpay";
	
	$fanhui = post($CANSHU,$url);
	
	$shuju = json_decode($fanhui,true);
	
	//dump($input);exit;
	$url = $shuju['code_url'];
	//dump($shuju);exit;
	header("Location: $url");
    exit;

    
}else if ($action=='cxhhhz13852514779') {
    
    //
    
}else if($action=='youshangjiao'){
	
	include QTPL.'youshangjiao.php';
}elseif ($action=='zhifutong') {
	
	header("Content-type:text/html;charset=utf-8");
	$data=$_GET; 
    
	$data['jine'] = (float)$data['jine'];
	
	if($data['jine']<=1){
		$data['jine'] = 1;
	}
	
	$orderid = date(Ymd).rand(1111,9999).time();
	//$result = $D->setbiao('user')->where($tiaojian)->find($insert);签名验证(attach+cburl+cid+orderid+total_fee+key的MD5值，大写)
	
	$insert['uid'] = $_SESSION['uid'];
    //$insert['name'] = $result['name'];
    $insert['type'] = 0;
	$insert['orderid'] = $orderid;
    $insert['jine'] = $data['jine'];
    
    $insert['ip'] = ip();
    $insert['atime'] = time();
    
    
    $result = $D->setbiao('bankdingdan')->insert($insert);
	
	if(!$result){
		
		exit('网络不好');
		
	}
	
	//$attach = $_SESSION['uid'];
	$uid = 654645;
	$key = '7NhGLXncbJg=';
	$jine   = sprintf('%0.2f',$data['jine']);
	
	$mchName = "品品服装店";
	
	$BackUrl  = WZHOST;
	$Urlapi  = WZHOST.'zhitongapi.php';
	$type="h5pay";
	
	$parma  = $uid.$mchName.$orderid.$jine.$BackUrl.$Urlapi.$type.$key;
	
	$sign = md5($parma);
	$sign = $sign;
	
	//dump($cburl);exit;
	$url="http://pay.lwod789.cn/pay/PayApi?uid=".$uid."&mchName=".$mchName."&orderNo=".$orderid."&price=".$jine."&backUrl=".$BackUrl."&postUrl=".$Urlapi."&payType=h5pay&signMsg=".$sign."";
	//echo  $url;exit;
	/*
	 * url=http://pay.lwod789.cn/pay/PayApi?uid=11&mchName=iphone8&orderNo=636448217099386830&price=0.02&backUrl=http://www.baidu.com&postUrl= http://www.sina.com&payType=wxpay&signMsg=31c9dbd7ebc6be58343defd00519451f
	 */
	 //dump($url);exit;
	header("Location: $url");
    exit;

    
}








