<?php if(!defined('ONGPHP'))exit('Error ONGSOFT');
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'] );
$D = db('');


  /*获取游戏域名*/


$shezhisql = $D -> setbiao('shezhi') -> order(  )->where( $tiaojian )-> select();
//var_dump($shezhisql);exit;
if (is_array($shezhisql)) {
  $she = array();
  foreach($shezhisql as  $k => $v){

    $she[$v['id']] = $v;

  }

$youxi = $she[4]['data'];
$appid = $she[5]['data'];
$appsecret = $she[6]['data'];

}

$wangzhi = WZHOST;
$redirect_uri = urlencode ( $wangzhi.'weixin.php' );
//$redirect_uri = urlencode ( $shezhi['tiaozhuan'].'weixin.php' );
//var_dump($shezhi['tiaozhuan']);exit;
$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();

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

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

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

}


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




    $key = md5('wuwei'.$_SESSION['uid']);
    header("Location:".$youxi.'?uidw='.$_SESSION['uid'].'&key='.$key );
    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'] = $youxi;

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

}

