Field('id,card_id')->where($where)->find(); return $cardinfo; } Public function _initialize() { $title = 'http'; if ($_SERVER['HTTPS'] == 'on') { $title .= 's'; } $this->REQUEST_URL = $title . '://' . $_SERVER['HTTP_HOST']; //定义全局门店id $merchantid = I('get.merchantid'); $merchantid_1 = session('merchantid'); //存储商户id if (!empty($merchantid)) { if (!empty($_SESSION['sqmode']) && session('wxuser')['merchantid'] != $merchantid) { session('sqmode', null); } session('merchantid', $merchantid); } else if (empty($merchantid_1)) { $this->tipsMsg(0, '未知的门店信息'); exit; } self::$SET = $_SESSION['SET'] = $this->checkSet(); $appset = self::$SET; // print_r($appset); $url = 'http'; if ($_SERVER["HTTPS"] == "on") { $url = $url . 's'; } $_url = $url . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']; // echo !$_SESSION['sqmode'];exit; if ($appset['type'] == 1) { //用户自定义配置微信公众号 self::$_wxappid = self::$SET['appid']; self::$_wxappsecret = self::$SET['appsecret']; if (!$_SESSION['sqmode']) { if (strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")) { //判断code是否存在 if ($_GET['code']) { if ($_GET['code'] != 'authdeny') { //用户授权 $options['appid'] = self::$_wxappid; $options['appsecret'] = self::$_wxappsecret; $wx = new \Util\Wx\Wechat($options); $re = $wx->getOauthAccessToken($_GET['code']);//获取access_token和openid // var_dump($re); $access_token = $re['access_token']; $openid = $re['openid']; if ($re) { $_SESSION['sqmode'] = 'wecha'; $_SESSION['openid'] = $openid; } } else { $this->tipsMsg(0, '本应用需要您的授权才可以使用!'); } } else { $options['appid'] = self::$_wxappid; $options['appsecret'] = self::$_wxappsecret; $wx = new \Util\Wx\Wechat($options); $squrl = $wx->getOauthRedirect($_url, '1', 'snsapi_base'); header("Location:" . $squrl); exit; } } else { $this->tipsMsg(0, '请使用微信浏览器访问本应用!'); } } } else if ($appset['type'] == 2) { //第三方授权微信公众号 $appinfo = M('appweixin')->where('id = 1')->find(); $options['appid'] = self::$SET['authorizer_appid']; if (!$_SESSION['sqmode']) { if (strpos($_SERVER["HTTP_USER_AGENT"], "MicroMessenger")) { //判断code是否存在 if ($_GET['code']) { if ($_GET['code'] != 'authdeny') { $wx = new \Util\Wx\Wechat($options); $token = get_acc_token(); $re = $wx->getOauthAccessTokens($_GET['code'], $appinfo['appid'], $token);//获取access_token和openid $access_token = $re['access_token']; $openid = $re['openid']; if ($re) { $_SESSION['sqmode'] = 'wecha'; $_SESSION['openid'] = $openid; } } else { $this->tipsMsg(0, '本应用需要您的授权才可以使用!'); } } else { $wx = new \Util\Wx\Wechat($options); $squrl = $wx->getOauthRedirects($_url, '1', 'snsapi_base', $appinfo['appid']); header("Location:" . $squrl); exit; } } else { $this->tipsMsg(0, '请使用微信浏览器访问本应用!'); } } } else { $this->tipsMsg(0, '商户未配置微信公众号'); } //查找用户是否激活会员卡 $map['openid'] = $_SESSION['openid']; $map['merchantid'] = session('merchantid'); $map['status'] = array('neq', 2); $userinfo = D('Vip')->getFind($map); $config = M('vip_config')->where(array('merchantid' => $map['merchantid']))->find(); if ($config['viptemplatesign']) { $hasfile = file_exists('./VipTemplate/' . $config['viptemplatesign'] . '/Index/index.html'); if ($hasfile) { C('VIEW_PATH', './VipTemplate/' . $config['viptemplatesign'] . '/'); $config['style_model'] = 1; } } $userinfo['style_model'] = $config['style_model'] ? $config['style_model'] : 1; if (empty($userinfo) || $userinfo['is_register'] == 0) { //未激活会员卡去激活会员卡 session('sqmode', null); session('sq_sqmode', null); session('userinfo', null); session('openid', null); session('vid', null); $this->redirect('Register/index'); } else { session('userinfo', $userinfo); session('vid', $userinfo['id']); } } //第三方授权功能 //设置全局变量 全局缓存SET public function checkSet() { $merchantid = session('merchantid'); $set = M('wxconfig')->where(array('merchantid' => $merchantid))->find(); return $set ? $set : $this->error('系统全局设置未定义!'); } //禁止不动的失败提示的信息 public function diemsg($status, $msg) { //成功为1,失败为0 $this->error($msg); $this->display('Base_diemsg'); die(); } public function tipsMsg($status, $msg) { $this->assign('status', $status); $this->assign('msg', $msg); $this->display('Index/tipsMsg'); exit; } }