<?php
//外部调用第一个页面后,自动调转到该页面,由该页面实际完成调用应用的起始页面
include "wxid/wechat.class.php";
include 'wxid/errCode.php';
require_once("Wx.Config.php");
$httppath = WxMainConfig::ServerHttpPath;

header("Content-type:text/html;charset=utf-8");

$scope = 'snsapi_base';

$opt = array(
	'appsecret'=>WxMainConfig::APPSECRET,//填写高级调用功能的密钥
	'appid'=>WxMainConfig::APPID	//填写高级调用功能的appid
);

$we = new Wechat($opt);
$auth = $we->checkAuth();
$arr = $we->getOauthAccessToken();


//得到微信UDID
$strSelWXID=$arr["openid"];

$strTemp=$we->getUserInfo($strSelWXID);
//print_r($strTemp);
$gzflag=$strTemp["subscribe"];
/*
if($gzflag<>'1')
{
	//没有关注公众号则进入关注微信号界面
	//header('Location: http://hotel.yuanxusoft.cn/mp/profile_ext?action=home&__biz=MzA4MDk0NDcyOQ==&from=1#wechat_redirect');
	header('Location: https://hotel.yuanxusoft.cn/mp/profile_ext?action=home&__biz=MzA4MDk0NDcyOQ==&scene=124&from=singlemessage#wechat_redirect');
	exit;
}
*/

//根据当前的wxudid判断进入什么系统
require_once("db/db.php");	
require_once("common/common.php");

//1.商户号
$strDListID=trim($_REQUEST['dlistid']);	//部门流水号
$strTableNo=trim($_REQUEST['tableno']);	//桌台号

if($strDListID=='')
{
	$strDListID=0;
}

$strSelDListID=0;
$strSelTableNo='';
//$sql = sprintf("SELECT ListNo FROM TCP_Depart_Inform Where ListNo=%s",$strDListID);
$sql = sprintf("SELECT b.DListNo,a.TableNo FROM TCP_Table_Inform a,TCP_Table_Type b WHERE a.TypeListNo=b.ListNo And b.DListNo=%s And a.TableNo='%s'",$strDListID,$strTableNo);
$result = querySql($sql);
if($row = fetch_array($result))
{
	$strSelDListID=$row['DListNo'];
	$strSelTableNo=$row['TableNo'];
}			
freeResult($result);	//释放数据库
closeDb();

//echo $strSelDListID.'**'.$strSelVIPNo;
//exit;
//3.进入部门点单界面
$bqurl=$httppath.'wxpos/indexauto.php?wxudid='.$strSelWXID.'&dlistid='.$strSelDListID.'&tableno='.$strSelTableNo;
echo $bqurl;
exit;
header('Location: ' . $bqurl);

?>