Exemple #1
0
 protected function _initialize()
 {
     parent::_initialize();
     $this->_appid = C("appid");
     $this->_secret = C("secret");
     $this->time = 0;
     $this->token = $this->_get('token');
     if (strlen($this->token)) {
         $_SESSION['token'] = $this->token;
     }
     if (!$this->token) {
         $this->token = $_SESSION['token'];
     }
     if (!$this->token && !(strpos(MODULE_NAME, 'Drp') === FALSE)) {
         $id = $this->_get('id');
         if ($id) {
             $did = M('Distributor_store')->where(array('id' => $id))->getField('did');
             $this->token = M('Distributor')->where(array('id' => $did))->getField('token');
         }
     }
     $this->assign('token', $this->token);
     if (!$this->token) {
         exit('no token');
     }
     if ($this->token && !preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit('error token');
     }
     $this->wxuser = S('wxuser_' . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
         S('wxuser_' . $this->token, $this->wxuser);
     }
     $this->assign('wxuser', $this->wxuser);
     $fake = 0;
     if ($this->wxuser['winxintype'] != 3 && $this->_appid && $this->_secret) {
         if (!$this->isAgent) {
             $this->wxuser['appid'] = trim($this->_appid);
             $this->wxuser['appsecret'] = trim($this->_secret);
         } else {
             $this->wxuser['appid'] = $this->thisAgent['appid'];
             $this->wxuser['appsecret'] = $this->thisAgent['appsecret'];
         }
         $fake = 1;
     }
     $toAuth = 0;
     $toAuth = $this->wxuser['oauth'];
     $this->wxuser['appid'] = $this->_appid;
     $this->wxuser['appsecret'] = $this->_secret;
     $fake = 1;
     $session_openid_name = 'token_openid_' . $this->token;
     $session_fakeopenid_name = 'token_fakeopenid_' . $this->token;
     $session_reopenid_name = 'token_reopenid_' . $this->token;
     $session_oauthed_name = 'token_oauthed_' . $this->token;
     $getUserInfoModules = getUserInfoModule::index();
     $getUserinfo = 0;
     if (isset($_GET['rget']) || intval($_GET['ali'])) {
         $_SESSION['otherSource'] = 1;
         $toAuth = 0;
         $this->wxuser['oauthinfo'] = 0;
     }
     if (isset($_SESSION['otherSource'])) {
         $toAuth = 0;
     }
     if ($this->wxuser['oauthinfo'] && !$_SESSION[$session_oauthed_name]) {
         if ($_SESSION[$session_openid_name]) {
             $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $_SESSION[$session_openid_name]))->find();
             if ($toAuth) {
                 if (!$fansInfo || !$fansInfo['wechaname'] || !$fansInfo['portrait']) {
                     unset($_SESSION[$session_openid_name]);
                     $getUserinfo = 1;
                 }
             }
         } else {
             if (isset($_SESSION[$session_reopenid_name]) && $_SESSION[$session_reopenid_name]) {
                 $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $_SESSION[$session_reopenid_name]))->find();
                 if (!$fansInfo || !$fansInfo['wechaname'] || !$fansInfo['portrait']) {
                     unset($_SESSION[$session_openid_name]);
                     unset($_SESSION[$session_reopenid_name]);
                     $getUserinfo = 1;
                 }
             } else {
                 $getUserinfo = 1;
             }
         }
     }
     if (!isset($_SESSION[$session_openid_name]) || !$_SESSION[$session_openid_name]) {
         $scope = 'snsapi_userinfo';
         if (!$this->wxuser['oauthinfo'] || !$getUserinfo) {
             $scope = 'snsapi_base';
         }
         if ((!$_GET['wecha_id'] || urldecode($_GET['wecha_id']) == '{wechat_id}') && $_GET['wecha_id'] != 'no' && !isset($_GET['code']) && $this->wxuser['appid'] && $this->wxuser['appsecret'] && $toAuth == 1) {
             $customeUrl = $this->siteUrl . $_SERVER['REQUEST_URI'];
             $oauthUrl = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid=' . $this->wxuser['appid'] . '&redirect_uri=' . urlencode($customeUrl) . '&response_type=code&scope=' . $scope . '&state=oauth#wechat_redirect';
             header('Location:' . $oauthUrl);
             exit;
         }
         if (isset($_GET['code']) && isset($_GET['state']) && $_GET['state'] == 'oauth') {
             $rt = $this->curlGet('https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $this->wxuser['appid'] . '&secret=' . $this->wxuser['appsecret'] . '&code=' . $_GET['code'] . '&grant_type=authorization_code');
             $jsonrt = json_decode($rt, 1);
             $openid = isset($jsonrt['openid']) ? $jsonrt['openid'] : "";
             $access_token = isset($jsonrt['access_token']) ? $jsonrt['access_token'] : "";
             $this->wecha_id = $openid;
             if ($fake) {
                 if (isset($_SESSION[$session_fakeopenid_name])) {
                     $this->wecha_id = $_SESSION[$session_fakeopenid_name];
                 } else {
                     $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'fakeopenid' => $openid))->find();
                     if ($fansInfo) {
                         $this->wecha_id = $fansInfo['wecha_id'];
                     }
                 }
             }
             if (!$openid) {
                 $this->error('授权不对<br>' . $this->wxuser['appid'] . '<br>' . $this->wxuser['appsecret'] . '<br>' . $jsonrt['errcode'], '#');
                 exit;
             } else {
                 if ($scope == 'snsapi_userinfo') {
                     $uinfo = $this->curlGet('https://api.weixin.qq.com/sns/userinfo?access_token=' . $access_token . '&openid=' . $openid . '&lang=zh_CN');
                     $jsonui = json_decode($uinfo, 1);
                     if (isset($jsonui['openid']) && $jsonui['openid']) {
                         if ($fansInfo) {
                             $exist = $fansInfo;
                         } else {
                             $exist = M('Userinfo')->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->getField("id");
                         }
                         $datainfo['wechaname'] = str_replace(array("'", "\\"), array(''), $jsonui['nickname']);
                         $datainfo['sex'] = $jsonui['sex'];
                         $datainfo['portrait'] = $jsonui['headimgurl'];
                         $datainfo['token'] = $this->token;
                         $datainfo['wecha_id'] = $jsonui['openid'];
                         $datainfo['city'] = $jsonui['city'];
                         $datainfo['province'] = $jsonui['province'];
                         if ($fake) {
                             $datainfo['wecha_id'] = $this->wecha_id;
                             $datainfo['fakeopenid'] = $jsonui['openid'];
                         }
                         if ($exist) {
                             $datainfo['truename'] = $datainfo['wechaname'];
                             M('Userinfo')->where(array("id" => $exist))->save($datainfo);
                         } else {
                             $datainfo['truename'] = $datainfo['wechaname'];
                             M('Userinfo')->add($datainfo);
                         }
                     } else {
                         $this->error('授权不对哦<br>' . $this->wxuser['appid'] . '<br>' . $this->wxuser['appsecret'] . '<br>' . $jsonui['errcode'], '#');
                         exit;
                     }
                 }
             }
             $_SESSION[$session_openid_name] = $this->wecha_id;
             $_SESSION[$session_oauthed_name] = 1;
         } else {
             $this->wecha_id = $this->_get('wecha_id');
             if ($fake && $toAuth && !isset($_GET['isappinstalled'])) {
                 $_SESSION[$session_fakeopenid_name] = $this->wecha_id;
             }
             if (!$toAuth) {
                 $_SESSION[$session_openid_name] = $this->wecha_id;
             }
             if (isset($_GET['wecha_id']) && strlen($_GET['wecha_id']) && $toAuth) {
                 $get_parms = $_GET;
                 unset($get_parms['wecha_id']);
                 $get_parm_str = '';
                 if ($get_parms) {
                     $comma = '';
                     foreach ($get_parms as $gpk => $gpv) {
                         $get_parm_str .= $comma . $gpk . '=' . $gpv;
                         $comma = '&';
                     }
                 }
                 $get_parm_str .= '&g=' . GROUP_NAME . '&m=' . MODULE_NAME . '&a=' . ACTION_NAME;
                 $_SESSION[$session_reopenid_name] = $this->wecha_id;
                 header('Location:' . $this->siteUrl . '/index.php?' . $get_parm_str);
                 exit;
             }
         }
     } else {
         $this->wecha_id = $_SESSION[$session_openid_name];
     }
     if ($this->wecha_id && !preg_match("/^[0-9a-zA-Z_\\-\\s]{3,82}\$/", $this->wecha_id)) {
         exit('error openid:' . $this->wecha_id);
     }
     if (!$this->wecha_id) {
         $this->wecha_id = $this->_get('wecha_id');
     }
     $this->assign('wecha_id', $this->wecha_id);
     $fansInfo = S('fans_' . $this->token . '_' . $this->wecha_id);
     if (!$fansInfo) {
         $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
     }
     $advanceInfo = M('Wechat_group_list')->where(array('token' => $this->token, 'openid' => $this->wecha_id))->find();
     if ($advanceInfo) {
         $fansInfo['nickname'] = $advanceInfo['nickname'];
         if (!$fansInfo['wechaname']) {
             $fansInfo['wechaname'] = $advanceInfo['nickname'];
         }
         $fansInfo['sex'] = $advanceInfo['sex'];
         $fansInfo['province'] = $advanceInfo['province'];
         $fansInfo['city'] = $advanceInfo['city'];
     }
     S('fans_' . $this->token . '_' . $this->wecha_id, $fansInfo);
     $this->fans = $fansInfo;
     $this->assign('fans', $fansInfo);
     $homeInfo = S('homeinfo_' . $this->token);
     if (!$homeInfo || 1) {
         $homeInfo = M('home')->where(array('token' => $this->token))->find();
         S('homeinfo_' . $this->token, $homeInfo);
     }
     $this->homeInfo = $homeInfo;
     $this->assign('homeInfo', $this->homeInfo);
     $catemenu = S('bottomMenus_' . $this->token);
     if (!$catemenu || 1) {
         $catemenu_db = M('catemenu');
         $catemenu = $catemenu_db->where(array('token' => $this->token, 'status' => 1))->order('orderss desc')->select();
         S('bottomMenus_' . $this->token, $catemenu);
     }
     $menures = array();
     if ($catemenu) {
         $res = array();
         $rescount = 0;
         foreach ($catemenu as $val) {
             $val['url'] = $this->getLink($val['url']);
             $res[$val['id']] = $val;
             if ($val['fid'] == 0) {
                 $val['vo'] = array();
                 $menures[$val['id']] = $val;
                 $menures[$val['id']]['k'] = $rescount;
                 $rescount++;
             }
         }
         foreach ($catemenu as $val) {
             $val['url'] = $this->getLink($val['url']);
             if ($val['fid'] > 0) {
                 array_push($menures[$val['fid']]['vo'], $val);
             }
         }
     }
     $catemenu = $menures;
     $this->bottomeMenus = $catemenu;
     $this->assign('catemenu', $this->bottomeMenus);
     $radiogroup = $homeInfo['radiogroup'];
     if ($radiogroup == false) {
         $radiogroup = 0;
     }
     $cateMenuFileName = 'tpl/Wap/default/Index_menuStyle' . $radiogroup . '.html';
     $this->assign('cateMenuFileName', $cateMenuFileName);
     $this->assign('radiogroup', $radiogroup);
     $this->user = S('user_' . $this->wxuser['uid']);
     if (!$this->user || 1) {
         $this->user = D('Users')->find(intval($this->wxuser['uid']));
         S('user_' . $this->wxuser['uid'], $this->user);
     }
     $this->assign('user', $this->user);
     $this->group = S('group_' . $this->user['gid']);
     if (!$this->group || 1) {
         $this->group = M('User_group')->where(array('id' => intval($this->user['gid'])))->find();
         S('group_' . $this->user['gid'], $this->group);
     }
     $this->assign('group', $this->group);
     $this->company = S('company_' . $this->token);
     if (!$this->company || 1) {
         $company_db = M('company');
         $this->company = $company_db->where(array('token' => $this->token, 'isbranch' => 0))->find();
         S('company_' . $this->token, $this->company);
     }
     $this->assign('company', $this->company);
     $this->copyright = $this->group['iscopyright'];
     $this->assign('iscopyright', $this->copyright);
     $this->assign('siteCopyright', C('copyright'));
     $this->assign('copyright', $this->copyright);
     $share = new WechatShare($this->wxuser['appid'], $this->wxuser['appsecret'], $this->token, $this->wecha_id);
     $this->shareScript = $share->getSgin();
     $this->assign('shareScript', $this->shareScript);
 }
Exemple #2
0
 protected function _initialize()
 {
     parent::_initialize();
     $this->_appid = C('appid');
     $this->_secret = C('secret');
     $this->time = 0;
     $this->token = $this->_get('token');
     if (ALI_FUWU_GROUP && date('Y') == 2015) {
         $fuwuuserlist = M('fuwuuser')->where(array('token' => $this->token))->select();
         foreach ($fuwuuserlist as $fuwuvo) {
             $fuwuuserinfo = M('userinfo')->where(array('token' => $this->token, 'wecha_id' => $fuwuvo['wecha_id']))->find();
             if ($fuwuuserinfo == '') {
                 if ($fuwuvo['gender'] == 'M') {
                     $fuwuvo['gender'] = 1;
                 } else {
                     if ($fuwuvo['gender'] == 'F') {
                         $fuwuvo['gender'] = 2;
                     } else {
                         $fuwuvo['gender'] = 0;
                     }
                 }
                 $add_userinfo_hb = array('token' => $this->token, 'wecha_id' => $fuwuvo['wecha_id'], 'issub' => 1, 'portrait' => $fuwuvo['avatar'], 'truename' => $fuwuvo['real_name'], 'nickname' => $fuwuvo['real_name'], 'wechaname' => $fuwuvo['real_name'], 'sex' => $fuwuvo['gender']);
                 $add_userinfo_hb = array_map('nulltoblank', $add_userinfo_hb);
                 $id_userinfo = M('userinfo')->add($add_userinfo_hb);
             } else {
                 if ($fuwuuserinfo['portrait'] == '' || $fuwuuserinfo['wechaname'] == '') {
                     if ($fuwuvo['gender'] == 'M') {
                         $fuwuvo['gender'] = 1;
                     } else {
                         if ($fuwuvo['gender'] == 'F') {
                             $fuwuvo['gender'] = 2;
                         } else {
                             $fuwuvo['gender'] = 0;
                         }
                     }
                     $save_userinfo_hb = array('token' => $this->token, 'wecha_id' => $fuwuvo['wecha_id'], 'issub' => 1, 'portrait' => $fuwuvo['avatar'], 'truename' => $fuwuvo['real_name'], 'nickname' => $fuwuvo['real_name'], 'wechaname' => $fuwuvo['real_name'], 'sex' => $fuwuvo['gender']);
                     $save_userinfo_hb = array_map('nulltoblank', $save_userinfo_hb);
                     $up_userinfo = M('userinfo')->where(array('token' => $this->token, 'wecha_id' => $fuwuvo['wecha_id']))->save($save_userinfo_hb);
                 }
             }
         }
     }
     if (strlen($this->token)) {
         $_SESSION['wap_token'] = $this->token;
     }
     if (!$this->token) {
         $this->token = $_SESSION['wap_token'];
     }
     if (!empty($_SESSION['wap_token'])) {
         $this->token = $_SESSION['wap_token'];
     }
     if (!$this->token && !(strpos(MODULE_NAME, 'Drp') === false)) {
         $id = $this->_get('id');
         if ($id) {
             $did = M('Distributor_store')->where(array('id' => $id))->getField('did');
             $this->token = M('Distributor')->where(array('id' => $did))->getField('token');
         }
     }
     $this->assign('token', $this->token);
     if (!$this->token) {
         exit('no token');
     }
     if ($this->token && !preg_match('/^[0-9a-zA-Z]{3,42}$/', $this->token)) {
         exit('error token');
     }
     $this->wxuser = S('wxuser_' . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D('Wxuser')->where(array('token' => $this->token))->find();
         S('wxuser_' . $this->token, $this->wxuser);
     }
     $this->owxuser = $this->wxuser;
     $this->assign('wxuser', $this->wxuser);
     $fake = 0;
     if ($this->wxuser['winxintype'] != 3 && $this->_appid && $this->_secret) {
         if ($this->wxuser['oauth'] == 1) {
             if (!$this->isAgent) {
                 $this->wxuser['appid'] = trim($this->_appid);
                 $this->wxuser['appsecret'] = trim($this->_secret);
             } else {
                 $this->wxuser['appid'] = $this->thisAgent['appid'];
                 $this->wxuser['appsecret'] = $this->thisAgent['appsecret'];
             }
         }
         $fake = 1;
     }
     $toAuth = 0;
     if (C('server_topdomain') == 'pigcms.cn' && C('site_url') != 'http://demo2.pigcms.cn') {
         $toAuth = 1;
     } else {
         $toAuth = $this->wxuser['oauth'];
     }
     if (C('server_topdomain') == 'pigcms.cn' && $this->wxuser['winxintype'] < 3) {
         $this->wxuser['appid'] = $this->_appid;
         $this->wxuser['appsecret'] = $this->_secret;
         $this->wxuser['oauth'] = 0;
         $this->wxuser['is_domain'] = 1;
         $fake = 1;
     }
     $wexintype = $this->wxuser['winxintype'];
     $session_openid_name = 'token_openid_' . $this->token;
     $session_fakeopenid_name = 'token_fakeopenid_' . $this->token;
     $session_reopenid_name = 'token_reopenid_' . $this->token;
     $session_oauthed_name = 'token_oauthed_' . $this->token;
     $getUserInfoModules = getUserInfoModule::index();
     $getUserinfo = 0;
     if (isset($_GET['rget']) || intval($_GET['ali'])) {
         $_SESSION['otherSource'] = 1;
         $toAuth = 0;
         $this->wxuser['oauthinfo'] = 0;
     }
     if (isset($_SESSION['otherSource'])) {
         $toAuth = 0;
     }
     if ($this->wxuser['oauthinfo'] && !$_SESSION[$session_oauthed_name]) {
         if ($_SESSION[$session_openid_name]) {
             $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $_SESSION[$session_openid_name]))->find();
             if ($toAuth) {
                 if (!$fansInfo || !$fansInfo['wechaname'] || !$fansInfo['portrait']) {
                     unset($_SESSION[$session_openid_name]);
                     $getUserinfo = 1;
                 }
             }
         } else {
             if (isset($_SESSION[$session_reopenid_name]) && $_SESSION[$session_reopenid_name]) {
                 $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $_SESSION[$session_reopenid_name]))->find();
                 if (!$fansInfo || !$fansInfo['wechaname'] || !$fansInfo['portrait']) {
                     unset($_SESSION[$session_openid_name]);
                     unset($_SESSION[$session_reopenid_name]);
                     $getUserinfo = 1;
                 }
             } else {
                 $getUserinfo = 1;
             }
         }
     }
     $this->isFuwu = 0;
     $this->isWechat = 0;
     $userAgent = strtolower($_SERVER['HTTP_USER_AGENT']);
     if (strpos($userAgent, 'alipayclient')) {
         $this->isFuwu = 1;
     } else {
         if (strpos($userAgent, 'micromessenger')) {
             $this->isWechat = 1;
         }
     }
     if (!M('Weixin_account')->where(array('type' => 1))->find()) {
         M('Wxuser')->where('1')->save(array('type' => 0));
     }
     if ($_GET['wecha_id'] && $_GET['wecha_id'] != $_SESSION[$session_openid_name] && 3 != $wexintype) {
         unset($_SESSION[$session_openid_name]);
         unset($_SESSION[$session_oauthed_name]);
     }
     if ($this->isFuwu) {
         if ($_GET['wecha_id'] != '') {
             $this->wecha_id = $_GET['wecha_id'];
         } else {
             $this->wecha_id = session('wecha_id');
         }
         session('wecha_id', $this->wecha_id);
         $thisfuwuuser = M('fuwuuser')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
         $isFuwuoauth = session('isFuwuoauth');
     }
     if ($this->isFuwu && ($isFuwuoauth != 'yes' || $thisfuwuuser == '')) {
         $FuwuNullFans = session('FuwuNullFans');
         if ($FuwuNullFans != 'yes') {
             $fw_wecha_id = FuwuOAuth::index($this->token);
             if ($fw_wecha_id != '') {
                 $this->wecha_id = $fw_wecha_id;
                 session('wecha_id', $this->wecha_id);
             } else {
                 session('FuwuNullFans', 'yes');
             }
         }
         $_SESSION[$session_openid_name] = $this->wecha_id;
         $_SESSION[$session_oauthed_name] = 1;
         session('isFuwuoauth', 'yes');
     }
     if (!isset($_SESSION[$session_openid_name]) || !$_SESSION[$session_openid_name]) {
         if ($this->isFuwu) {
         } else {
             $apiOauth = new apiOauth();
             if ((!$_GET['wecha_id'] || urldecode($_GET['wecha_id']) == '{wechat_id}') && $_GET['wecha_id'] != 'no' && $this->wxuser['appid'] && ($this->wxuser['type'] == 0 && $this->wxuser['appsecret'] != '' || $this->wxuser['type'] == 1) && $toAuth == 1) {
                 $token_info = $apiOauth->webOauth($this->wxuser, '', $fansInfo);
             }
             if (!empty($token_info)) {
                 $this->wecha_id = $token_info['openid'];
                 if (3 == $wexintype) {
                     $fake = 0;
                 }
                 if ($fake) {
                     if (isset($_SESSION[$session_fakeopenid_name])) {
                         $datainfo['issub'] = 1;
                         $this->wecha_id = $_SESSION[$session_fakeopenid_name];
                         $userinfoModel = M('Userinfo');
                         $userinfoData = $userinfoModel->where(array('token' => $this->token, 'wecha_id' => $_SESSION[$session_fakeopenid_name]))->find();
                         if ($userinfoData) {
                             $fakeUserinfoData = $userinfoModel->where(array('token' => $this->token, 'wecha_id' => $token_info['openid'], 'fakeopenid' => $token_info['openid']))->find();
                             if ($fakeUserinfoData) {
                                 if ($userinfoModel->where(array('id' => $fakeUserinfoData['id']))->save($this->_mergeUserinfo($userinfoData, $fakeUserinfoData))) {
                                     $userinfoModel->where(array('id' => $userinfoData['id']))->delete();
                                 }
                             } else {
                                 $userinfoModel->where(array('id' => $userinfoData['id']))->setField('fakeopenid', $token_info['openid']);
                             }
                         } else {
                             $fakeUserinfoData = $userinfoModel->where(array('token' => $this->token, 'wecha_id' => $token_info['openid'], 'fakeopenid' => $token_info['openid']))->find();
                             if ($fakeUserinfoData) {
                                 $userinfoModel->where(array('id' => $fakeUserinfoData['id']))->setField('wecha_id', $_SESSION[$session_fakeopenid_name]);
                             }
                         }
                         $this->wecha_id = $_SESSION[$session_fakeopenid_name];
                     } else {
                         $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'fakeopenid' => $token_info['openid']))->find();
                         if ($fansInfo) {
                             $this->wecha_id = $fansInfo['wecha_id'];
                         }
                     }
                 }
                 if ($this->wxuser['oauthinfo'] && MODULE_NAME != 'Index') {
                     $jsonui = $apiOauth->get_fans_info($token_info['access_token'], $token_info['openid']);
                     if (isset($jsonui['openid']) && $jsonui['openid']) {
                         if ($fansInfo) {
                             $exist = $fansInfo['id'];
                             $issub = $fansInfo['issub'];
                         } else {
                             $existInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
                             $issub = $existInfo['issub'];
                             $exist = $existInfo['id'];
                         }
                         $datainfo['wechaname'] = str_replace(array('\'', '\\'), array(''), $jsonui['nickname']);
                         $datainfo['sex'] = $jsonui['sex'];
                         $datainfo['portrait'] = $jsonui['headimgurl'];
                         $datainfo['token'] = $this->token;
                         $datainfo['wecha_id'] = $jsonui['openid'];
                         $datainfo['city'] = $jsonui['city'];
                         $datainfo['province'] = $jsonui['province'];
                         $datainfo['truename'] = $datainfo['wechaname'];
                         $datainfo['wecha_id'] = $this->wecha_id;
                         if ($fake) {
                             $datainfo['fakeopenid'] = $jsonui['openid'];
                         }
                         if (3 == $wexintype) {
                             $datainfo['fakeopenid'] = '';
                             $datainfo['issub'] = $this->_issubService($datainfo['wecha_id']);
                         }
                         if ($exist) {
                             D('Userinfo')->where(array('id' => $exist))->save($datainfo);
                         } else {
                             D('Userinfo')->add($datainfo);
                         }
                     } else {
                         $this->error('授权不对哦,请重置您的appsecret!<br>' . $this->wxuser['appid'] . '<br>' . $this->wxuser['appsecret'] . '<br>' . $jsonui['errcode'], '#');
                         exit;
                     }
                 }
                 if (empty($this->wxuser['oauthinfo']) && MODULE_NAME != 'Index') {
                     if ($fansInfo) {
                         $exist = $fansInfo['id'];
                     } else {
                         $existInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
                         $exist = $existInfo['id'];
                     }
                     $datainfo['token'] = $this->token;
                     $datainfo['wecha_id'] = $this->wecha_id;
                     if ($fake) {
                         $datainfo['fakeopenid'] = $token_info['openid'];
                     }
                     if (3 == $wexintype) {
                         $datainfo['fakeopenid'] = '';
                         $datainfo['issub'] = $this->_issubService($datainfo['wecha_id']);
                     }
                     if ($exist) {
                         D('Userinfo')->where(array('id' => $exist))->save($datainfo);
                     } else {
                         D('Userinfo')->add($datainfo);
                     }
                 }
                 $_SESSION[$session_openid_name] = $this->wecha_id;
                 $_SESSION[$session_oauthed_name] = 1;
             } else {
                 $this->wecha_id = $this->_get('wecha_id');
                 if ($fake && $toAuth && !isset($_GET['isappinstalled'])) {
                     $_SESSION[$session_fakeopenid_name] = $this->wecha_id;
                 }
                 if (!$toAuth) {
                     $_SESSION[$session_openid_name] = $this->wecha_id;
                 }
                 if (isset($_GET['wecha_id']) && strlen($_GET['wecha_id']) && $toAuth) {
                     $get_parms = $_GET;
                     unset($get_parms['wecha_id']);
                     $get_parm_str = '';
                     if ($get_parms) {
                         $comma = '';
                         foreach ($get_parms as $gpk => $gpv) {
                             $get_parm_str .= $comma . $gpk . '=' . $gpv;
                             $comma = '&';
                         }
                     }
                     $get_parm_str .= '&g=' . GROUP_NAME . '&m=' . MODULE_NAME . '&a=' . ACTION_NAME;
                     $_SESSION[$session_reopenid_name] = $this->wecha_id;
                     header('Location:' . $this->siteUrl . '/index.php?' . $get_parm_str);
                     exit;
                 }
             }
         }
     } else {
         $this->wecha_id = $_SESSION[$session_openid_name];
     }
     if ($_GET['yundabao'] == 1) {
         cookie('yundabao', '1', 31536000);
     }
     $yundabao = cookie('yundabao');
     if ($yundabao != '1') {
         if ($this->wecha_id && !preg_match('/^[0-9a-zA-Z_\\-\\s]{3,82}$/', $this->wecha_id)) {
             exit('error openid:' . $this->wecha_id);
         }
     }
     if (!$this->wecha_id) {
         $this->wecha_id = $this->_get('wecha_id');
     }
     $this->assign('wecha_id', $this->wecha_id);
     $fansInfo = S('fans_' . $this->token . '_' . $this->wecha_id);
     if (!$fansInfo) {
         $fansInfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
     }
     $advanceInfo = M('Wechat_group_list')->where(array('token' => $this->token, 'openid' => $this->wecha_id))->find();
     if ($advanceInfo) {
         $fansInfo['nickname'] = $advanceInfo['nickname'];
         if (!$fansInfo['wechaname']) {
             $fansInfo['wechaname'] = $advanceInfo['nickname'];
         }
         $fansInfo['sex'] = $advanceInfo['sex'];
         $fansInfo['province'] = $advanceInfo['province'];
         $fansInfo['city'] = $advanceInfo['city'];
     }
     if ($this->isFuwu) {
         $ali_userinfo_list = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => array('like', '%z_%')))->select();
         $ali_wecha_id_array = array();
         foreach ($ali_userinfo_list as $alivo) {
             if (in_array($alivo['wecha_id'], $ali_wecha_id_array)) {
                 $del_ali_userinfo = M('Userinfo')->where(array('token' => $this->token, 'id' => $alivo['id'], 'wecha_id' => $alivo['wecha_id']))->delete();
             } else {
                 $ali_wecha_id_array[] = $alivo['wecha_id'];
             }
         }
         $FuwuUserInfo = M('fuwuuser')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
         if ($FuwuUserInfo['gender'] == 'M') {
             $FuwuUserInfo['gender'] = 1;
         } else {
             if ($FuwuUserInfo['gender'] == 'F') {
                 $FuwuUserInfo['gender'] = 2;
             } else {
                 $FuwuUserInfo['gender'] = 0;
             }
         }
         if ($FuwuUserInfo['real_name'] != '') {
             $is_userinfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->find();
             if ($is_userinfo == '') {
                 $add_userinfo = array('token' => $this->token, 'wecha_id' => $this->wecha_id, 'issub' => 1, 'portrait' => $FuwuUserInfo['avatar'], 'truename' => $FuwuUserInfo['real_name'], 'nickname' => $FuwuUserInfo['real_name'], 'wechaname' => $FuwuUserInfo['real_name'], 'sex' => $FuwuUserInfo['gender']);
                 $add_userinfo = array_map('nulltoblank', $add_userinfo);
                 $id_Userinfo = M('Userinfo')->add($add_userinfo);
             } else {
                 if ($fansInfo['issub'] == 0) {
                     $up_Userinfo = M('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->save(array('issub' => 1));
                 }
             }
             if ($fansInfo['wechaname'] == '') {
                 $fansInfo['wechaname'] = $FuwuUserInfo['real_name'];
             }
             if ($fansInfo['portrait'] == '') {
                 $fansInfo['portrait'] = $FuwuUserInfo['avatar'];
             }
             if ($fansInfo['nickname'] == '') {
                 $fansInfo['nickname'] = $FuwuUserInfo['real_name'];
             }
             if ($fansInfo['truename'] == '') {
                 $fansInfo['truename'] = $FuwuUserInfo['real_name'];
             }
             if ($fansInfo['tel'] == '') {
                 $fansInfo['tel'] = $FuwuUserInfo['mobile'];
             }
         }
     }
     S('fans_' . $this->token . '_' . $this->wecha_id, $fansInfo);
     $this->fans = $fansInfo;
     $this->assign('fans', $fansInfo);
     $homeInfo = S('homeinfo_' . $this->token);
     if (!$homeInfo || 1) {
         $homeInfo = M('home')->where(array('token' => $this->token))->find();
         S('homeinfo_' . $this->token, $homeInfo);
     }
     $this->homeInfo = $homeInfo;
     $this->assign('homeInfo', $this->homeInfo);
     $catemenu = S('bottomMenus_' . $this->token);
     if (!$catemenu || 1) {
         $catemenu_db = M('catemenu');
         $catemenu = $catemenu_db->where(array('token' => $this->token, 'status' => 1))->order('orderss desc')->select();
         S('bottomMenus_' . $this->token, $catemenu);
     }
     $menures = array();
     if ($catemenu) {
         $res = array();
         $rescount = 0;
         foreach ($catemenu as $val) {
             $val['url'] = $this->getLink($val['url']);
             $res[$val['id']] = $val;
             if ($val['fid'] == 0) {
                 $val['vo'] = array();
                 $menures[$val['id']] = $val;
                 $menures[$val['id']]['k'] = $rescount;
                 $rescount++;
             }
         }
         foreach ($catemenu as $val) {
             $val['url'] = $this->getLink($val['url']);
             if (0 < $val['fid']) {
                 array_push($menures[$val['fid']]['vo'], $val);
             }
         }
     }
     $catemenu = $menures;
     $this->bottomeMenus = $catemenu;
     $this->assign('catemenu', $this->bottomeMenus);
     $radiogroup = $homeInfo['radiogroup'];
     if ($radiogroup == false) {
         $radiogroup = 0;
     }
     $cateMenuFileName = 'tpl/Wap/default/Index_menuStyle' . $radiogroup . '.html';
     $this->assign('cateMenuFileName', $cateMenuFileName);
     $this->assign('radiogroup', $radiogroup);
     $this->user = S('user_' . $this->wxuser['uid']);
     if (!$this->user || 1) {
         $this->user = D('Users')->find(intval($this->wxuser['uid']));
         S('user_' . $this->wxuser['uid'], $this->user);
     }
     $this->assign('user', $this->user);
     $this->group = S('group_' . $this->user['gid']);
     if (!$this->group || 1) {
         $this->group = M('User_group')->where(array('id' => intval($this->user['gid'])))->find();
         S('group_' . $this->user['gid'], $this->group);
     }
     $this->assign('group', $this->group);
     $this->company = S('company_' . $this->token);
     if (!$this->company || 1) {
         $company_db = M('company');
         $this->company = $company_db->where(array('token' => $this->token, 'isbranch' => 0))->find();
         S('company_' . $this->token, $this->company);
     }
     $this->assign('company', $this->company);
     $this->copyright = $this->group['iscopyright'];
     $this->assign('iscopyright', $this->copyright);
     $this->assign('siteCopyright', C('copyright'));
     $this->assign('copyright', $this->copyright);
     $share = new WechatShare($this->wxuser, $this->wecha_id);
     $this->shareScript = $share->getSgin();
     $this->assign('shareScript', $this->shareScript);
     $this->fakeopenid = D('Userinfo')->where(array('token' => $this->token, 'wecha_id' => $this->wecha_id))->getField('fakeopenid');
 }
Exemple #3
0
 protected function _initialize()
 {
     parent::_initialize();
     $this->_appid = C("appid");
     $this->_secret = C("secret");
     $this->time = 0;
     $this->token = $this->_get("token");
     if (ALI_FUWU_GROUP && date("Y") == 2015) {
         $fuwuuserlist = M("fuwuuser")->where(array("token" => $this->token))->select();
         foreach ($fuwuuserlist as $fuwuvo) {
             $fuwuuserinfo = M("userinfo")->where(array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"]))->find();
             if ($fuwuuserinfo == "") {
                 if ($fuwuvo["gender"] == "M") {
                     $fuwuvo["gender"] = 1;
                 } else {
                     if ($fuwuvo["gender"] == "F") {
                         $fuwuvo["gender"] = 2;
                     } else {
                         $fuwuvo["gender"] = 0;
                     }
                 }
                 $add_userinfo_hb = array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"], "issub" => 1, "portrait" => $fuwuvo["avatar"], "truename" => $fuwuvo["real_name"], "nickname" => $fuwuvo["real_name"], "wechaname" => $fuwuvo["real_name"], "sex" => $fuwuvo["gender"]);
                 $add_userinfo_hb = array_map("nulltoblank", $add_userinfo_hb);
                 $id_userinfo = M("userinfo")->add($add_userinfo_hb);
             } else {
                 if ($fuwuuserinfo["portrait"] == "" || $fuwuuserinfo["wechaname"] == "") {
                     if ($fuwuvo["gender"] == "M") {
                         $fuwuvo["gender"] = 1;
                     } else {
                         if ($fuwuvo["gender"] == "F") {
                             $fuwuvo["gender"] = 2;
                         } else {
                             $fuwuvo["gender"] = 0;
                         }
                     }
                     $save_userinfo_hb = array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"], "issub" => 1, "portrait" => $fuwuvo["avatar"], "truename" => $fuwuvo["real_name"], "nickname" => $fuwuvo["real_name"], "wechaname" => $fuwuvo["real_name"], "sex" => $fuwuvo["gender"]);
                     $save_userinfo_hb = array_map("nulltoblank", $save_userinfo_hb);
                     $up_userinfo = M("userinfo")->where(array("token" => $this->token, "wecha_id" => $fuwuvo["wecha_id"]))->save($save_userinfo_hb);
                 }
             }
         }
     }
     if (strlen($this->token)) {
         $_SESSION["wap_token"] = $this->token;
     }
     if (!$this->token) {
         $this->token = $_SESSION["wap_token"];
     }
     if (!empty($_SESSION["wap_token"])) {
         $this->token = $_SESSION["wap_token"];
     }
     if (!$this->token && !strpos(MODULE_NAME, "Drp") === false) {
         $id = $this->_get("id");
         if ($id) {
             $did = M("Distributor_store")->where(array("id" => $id))->getField("did");
             $this->token = M("Distributor")->where(array("id" => $did))->getField("token");
         }
     }
     $this->assign("token", $this->token);
     if (!$this->token) {
         exit("no token");
     }
     if ($this->token && !preg_match("/^[0-9a-zA-Z]{3,42}\$/", $this->token)) {
         exit("error token");
     }
     $this->wxuser = S("wxuser_" . $this->token);
     if (!$this->wxuser || 1) {
         $this->wxuser = D("Wxuser")->where(array("token" => $this->token))->find();
         S("wxuser_" . $this->token, $this->wxuser);
     }
     $this->owxuser = $this->wxuser;
     $this->assign("wxuser", $this->wxuser);
     $fake = 0;
     if ($this->wxuser["winxintype"] != 3 && $this->_appid && $this->_secret) {
         if ($this->wxuser["oauth"] == 1) {
             if (!$this->isAgent) {
                 $this->wxuser["appid"] = trim($this->_appid);
                 $this->wxuser["appsecret"] = trim($this->_secret);
             } else {
                 $this->wxuser["appid"] = $this->thisAgent["appid"];
                 $this->wxuser["appsecret"] = $this->thisAgent["appsecret"];
             }
         }
         $fake = 1;
     }
     $toAuth = 0;
     $toAuth = $this->wxuser["oauth"];
     $wexintype = $this->wxuser["winxintype"];
     $session_openid_name = "token_openid_" . $this->token;
     $session_fakeopenid_name = "token_fakeopenid_" . $this->token;
     $session_reopenid_name = "token_reopenid_" . $this->token;
     $session_oauthed_name = "token_oauthed_" . $this->token;
     $getUserInfoModules = getUserInfoModule::index();
     $getUserinfo = 0;
     if (isset($_GET["rget"]) || intval($_GET["ali"])) {
         $_SESSION["otherSource"] = 1;
         $toAuth = 0;
         $this->wxuser["oauthinfo"] = 0;
     }
     if (isset($_SESSION["otherSource"])) {
         $toAuth = 0;
     }
     if ($this->wxuser["oauthinfo"] && !$_SESSION[$session_oauthed_name]) {
         if ($_SESSION[$session_openid_name]) {
             $fansInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_openid_name]))->find();
             if ($toAuth) {
                 if (!$fansInfo || !$fansInfo["wechaname"] || !$fansInfo["portrait"]) {
                     unset($_SESSION[$session_openid_name]);
                     $getUserinfo = 1;
                 }
             }
         } else {
             if (isset($_SESSION[$session_reopenid_name]) && $_SESSION[$session_reopenid_name]) {
                 $fansInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_reopenid_name]))->find();
                 if (!$fansInfo || !$fansInfo["wechaname"] || !$fansInfo["portrait"]) {
                     unset($_SESSION[$session_openid_name]);
                     unset($_SESSION[$session_reopenid_name]);
                     $getUserinfo = 1;
                 }
             } else {
                 $getUserinfo = 1;
             }
         }
     }
     $this->isFuwu = 0;
     $this->isWechat = 0;
     $userAgent = strtolower($_SERVER["HTTP_USER_AGENT"]);
     if (strpos($userAgent, "alipayclient")) {
         $this->isFuwu = 1;
     } else {
         if (strpos($userAgent, "micromessenger")) {
             $this->isWechat = 1;
         }
     }
     if (!M("Weixin_account")->where(array("type" => 1))->find()) {
         M("Wxuser")->where("1")->save(array("type" => 0));
     }
     if ($_GET["wecha_id"] && $_GET["wecha_id"] != $_SESSION[$session_openid_name] && 3 != $wexintype) {
         unset($_SESSION[$session_openid_name]);
         unset($_SESSION[$session_oauthed_name]);
     }
     if ($this->isFuwu) {
         if ($_GET["wecha_id"] != "") {
             $this->wecha_id = $_GET["wecha_id"];
         } else {
             $this->wecha_id = session("wecha_id");
         }
         session("wecha_id", $this->wecha_id);
         $thisfuwuuser = M("fuwuuser")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
         $isFuwuoauth = session("isFuwuoauth");
     }
     if ($this->isFuwu && ($isFuwuoauth != "yes" || $thisfuwuuser == "")) {
         $FuwuNullFans = session("FuwuNullFans");
         if ($FuwuNullFans != "yes") {
             $fw_wecha_id = FuwuOAuth::index($this->token);
             if ($fw_wecha_id != "") {
                 $this->wecha_id = $fw_wecha_id;
                 session("wecha_id", $this->wecha_id);
             } else {
                 session("FuwuNullFans", "yes");
             }
         }
         $_SESSION[$session_openid_name] = $this->wecha_id;
         $_SESSION[$session_oauthed_name] = 1;
         session("isFuwuoauth", "yes");
     }
     if (!isset($_SESSION[$session_openid_name]) || !$_SESSION[$session_openid_name]) {
         if ($this->isFuwu) {
         } else {
             $apiOauth = new apiOauth();
             if ((!$_GET["wecha_id"] || urldecode($_GET["wecha_id"]) == "{wechat_id}") && $_GET["wecha_id"] != "no" && $this->wxuser["appid"] && ($this->wxuser["type"] == 0 && $this->wxuser["appsecret"] != "" || $this->wxuser["type"] == 1) && $toAuth == 1) {
                 $token_info = $apiOauth->webOauth($this->wxuser, "", $fansInfo);
             }
             if (!empty($token_info)) {
                 $this->wecha_id = $token_info["openid"];
                 if (3 == $wexintype) {
                     $fake = 0;
                 }
                 if ($fake) {
                     if (isset($_SESSION[$session_fakeopenid_name])) {
                         $datainfo["issub"] = 1;
                         $this->wecha_id = $_SESSION[$session_fakeopenid_name];
                         $userinfoModel = M("Userinfo");
                         $userinfoData = $userinfoModel->where(array("token" => $this->token, "wecha_id" => $_SESSION[$session_fakeopenid_name]))->find();
                         if ($userinfoData) {
                             $fakeUserinfoData = $userinfoModel->where(array("token" => $this->token, "wecha_id" => $token_info["openid"], "fakeopenid" => $token_info["openid"]))->find();
                             if ($fakeUserinfoData) {
                                 if ($userinfoModel->where(array("id" => $fakeUserinfoData["id"]))->save($this->_mergeUserinfo($userinfoData, $fakeUserinfoData))) {
                                     $userinfoModel->where(array("id" => $userinfoData["id"]))->delete();
                                 }
                             } else {
                                 $userinfoModel->where(array("id" => $userinfoData["id"]))->setField("fakeopenid", $token_info["openid"]);
                             }
                         } else {
                             $fakeUserinfoData = $userinfoModel->where(array("token" => $this->token, "wecha_id" => $token_info["openid"], "fakeopenid" => $token_info["openid"]))->find();
                             if ($fakeUserinfoData) {
                                 $userinfoModel->where(array("id" => $fakeUserinfoData["id"]))->setField("wecha_id", $_SESSION[$session_fakeopenid_name]);
                             }
                         }
                         $this->wecha_id = $_SESSION[$session_fakeopenid_name];
                     } else {
                         $fansInfo = M("Userinfo")->where(array("token" => $this->token, "fakeopenid" => $token_info["openid"]))->find();
                         if ($fansInfo) {
                             $this->wecha_id = $fansInfo["wecha_id"];
                         }
                     }
                 }
                 if ($this->wxuser["oauthinfo"] && MODULE_NAME != "Index") {
                     $jsonui = $apiOauth->get_fans_info($token_info["access_token"], $token_info["openid"]);
                     if (isset($jsonui["openid"]) && $jsonui["openid"]) {
                         if ($fansInfo) {
                             $exist = $fansInfo["id"];
                             $issub = $fansInfo["issub"];
                         } else {
                             $existInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
                             $issub = $existInfo["issub"];
                             $exist = $existInfo["id"];
                         }
                         $datainfo["wechaname"] = str_replace(array("'", "\\"), array(""), $jsonui["nickname"]);
                         $datainfo["sex"] = $jsonui["sex"];
                         $datainfo["portrait"] = $jsonui["headimgurl"];
                         $datainfo["token"] = $this->token;
                         $datainfo["wecha_id"] = $jsonui["openid"];
                         $datainfo["city"] = $jsonui["city"];
                         $datainfo["province"] = $jsonui["province"];
                         $datainfo["truename"] = $datainfo["wechaname"];
                         $datainfo["wecha_id"] = $this->wecha_id;
                         if ($fake) {
                             $datainfo["fakeopenid"] = $jsonui["openid"];
                         }
                         if (3 == $wexintype) {
                             $datainfo["fakeopenid"] = "";
                             $datainfo["issub"] = $this->_issubService($datainfo["wecha_id"]);
                         }
                         if ($exist) {
                             D("Userinfo")->where(array("id" => $exist))->save($datainfo);
                         } else {
                             D("Userinfo")->add($datainfo);
                         }
                     } else {
                         $this->error("授权不对哦,请重置您的appsecret!<br>" . $this->wxuser["appid"] . "<br>" . $this->wxuser["appsecret"] . "<br>" . $jsonui["errcode"], "#");
                         exit;
                     }
                 }
                 if (empty($this->wxuser["oauthinfo"]) && MODULE_NAME != "Index") {
                     if ($fansInfo) {
                         $exist = $fansInfo["id"];
                     } else {
                         $existInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
                         $exist = $existInfo["id"];
                     }
                     $datainfo["token"] = $this->token;
                     $datainfo["wecha_id"] = $this->wecha_id;
                     if ($fake) {
                         $datainfo["fakeopenid"] = $token_info["openid"];
                     }
                     if (3 == $wexintype) {
                         $datainfo["fakeopenid"] = "";
                         $datainfo["issub"] = $this->_issubService($datainfo["wecha_id"]);
                     }
                     if ($exist) {
                         D("Userinfo")->where(array("id" => $exist))->save($datainfo);
                     } else {
                         D("Userinfo")->add($datainfo);
                     }
                 }
                 $_SESSION[$session_openid_name] = $this->wecha_id;
                 $_SESSION[$session_oauthed_name] = 1;
             } else {
                 $this->wecha_id = $this->_get("wecha_id");
                 if ($fake && $toAuth && !isset($_GET["isappinstalled"])) {
                     $_SESSION[$session_fakeopenid_name] = $this->wecha_id;
                 }
                 if (!$toAuth) {
                     $_SESSION[$session_openid_name] = $this->wecha_id;
                 }
                 if (isset($_GET["wecha_id"]) && strlen($_GET["wecha_id"]) && $toAuth) {
                     $get_parms = $_GET;
                     unset($get_parms["wecha_id"]);
                     $get_parm_str = "";
                     if ($get_parms) {
                         $comma = "";
                         foreach ($get_parms as $gpk => $gpv) {
                             $get_parm_str .= $comma . $gpk . "=" . $gpv;
                             $comma = "&";
                         }
                     }
                     $get_parm_str .= "&g=" . GROUP_NAME . "&m=" . MODULE_NAME . "&a=" . ACTION_NAME;
                     $_SESSION[$session_reopenid_name] = $this->wecha_id;
                     header("Location:" . $this->siteUrl . "/index.php?" . $get_parm_str);
                     exit;
                 }
             }
         }
     } else {
         $this->wecha_id = $_SESSION[$session_openid_name];
     }
     if ($_GET["yundabao"] == 1) {
         cookie("yundabao", "1", 31536000);
     }
     $yundabao = cookie("yundabao");
     if ($yundabao != "1") {
         if ($this->wecha_id && !preg_match("/^[0-9a-zA-Z_\\-\\s]{3,82}\$/", $this->wecha_id)) {
             exit("error openid:" . $this->wecha_id);
         }
     }
     if (!$this->wecha_id) {
         $this->wecha_id = $this->_get("wecha_id");
     }
     $this->assign("wecha_id", $this->wecha_id);
     $fansInfo = S("fans_" . $this->token . "_" . $this->wecha_id);
     if (!$fansInfo) {
         $fansInfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
     }
     $advanceInfo = M("Wechat_group_list")->where(array("token" => $this->token, "openid" => $this->wecha_id))->find();
     if ($advanceInfo) {
         $fansInfo["nickname"] = $advanceInfo["nickname"];
         if (!$fansInfo["wechaname"]) {
             $fansInfo["wechaname"] = $advanceInfo["nickname"];
         }
         $fansInfo["sex"] = $advanceInfo["sex"];
         $fansInfo["province"] = $advanceInfo["province"];
         $fansInfo["city"] = $advanceInfo["city"];
     }
     if ($this->isFuwu) {
         $ali_userinfo_list = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => array("like", "%z_%")))->select();
         $ali_wecha_id_array = array();
         foreach ($ali_userinfo_list as $alivo) {
             if (in_array($alivo["wecha_id"], $ali_wecha_id_array)) {
                 $del_ali_userinfo = M("Userinfo")->where(array("token" => $this->token, "id" => $alivo["id"], "wecha_id" => $alivo["wecha_id"]))->delete();
             } else {
                 $ali_wecha_id_array[] = $alivo["wecha_id"];
             }
         }
         $FuwuUserInfo = M("fuwuuser")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
         if ($FuwuUserInfo["gender"] == "M") {
             $FuwuUserInfo["gender"] = 1;
         } else {
             if ($FuwuUserInfo["gender"] == "F") {
                 $FuwuUserInfo["gender"] = 2;
             } else {
                 $FuwuUserInfo["gender"] = 0;
             }
         }
         if ($FuwuUserInfo["real_name"] != "") {
             $is_userinfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->find();
             if ($is_userinfo == "") {
                 $add_userinfo = array("token" => $this->token, "wecha_id" => $this->wecha_id, "issub" => 1, "portrait" => $FuwuUserInfo["avatar"], "truename" => $FuwuUserInfo["real_name"], "nickname" => $FuwuUserInfo["real_name"], "wechaname" => $FuwuUserInfo["real_name"], "sex" => $FuwuUserInfo["gender"]);
                 $add_userinfo = array_map("nulltoblank", $add_userinfo);
                 $id_Userinfo = M("Userinfo")->add($add_userinfo);
             } else {
                 if ($fansInfo["issub"] == 0) {
                     $up_Userinfo = M("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->save(array("issub" => 1));
                 }
             }
             if ($fansInfo["wechaname"] == "") {
                 $fansInfo["wechaname"] = $FuwuUserInfo["real_name"];
             }
             if ($fansInfo["portrait"] == "") {
                 $fansInfo["portrait"] = $FuwuUserInfo["avatar"];
             }
             if ($fansInfo["nickname"] == "") {
                 $fansInfo["nickname"] = $FuwuUserInfo["real_name"];
             }
             if ($fansInfo["truename"] == "") {
                 $fansInfo["truename"] = $FuwuUserInfo["real_name"];
             }
             if ($fansInfo["tel"] == "") {
                 $fansInfo["tel"] = $FuwuUserInfo["mobile"];
             }
         }
     }
     S("fans_" . $this->token . "_" . $this->wecha_id, $fansInfo);
     $this->fans = $fansInfo;
     $this->assign("fans", $fansInfo);
     $homeInfo = S("homeinfo_" . $this->token);
     if (!$homeInfo || 1) {
         $homeInfo = M("home")->where(array("token" => $this->token))->find();
         S("homeinfo_" . $this->token, $homeInfo);
     }
     $this->homeInfo = $homeInfo;
     $this->assign("homeInfo", $this->homeInfo);
     $catemenu = S("bottomMenus_" . $this->token);
     if (!$catemenu || 1) {
         $catemenu_db = M("catemenu");
         $catemenu = $catemenu_db->where(array("token" => $this->token, "status" => 1))->order("orderss desc")->select();
         S("bottomMenus_" . $this->token, $catemenu);
     }
     $menures = array();
     if ($catemenu) {
         $res = array();
         $rescount = 0;
         foreach ($catemenu as $val) {
             $val["url"] = $this->getLink($val["url"]);
             $res[$val["id"]] = $val;
             if ($val["fid"] == 0) {
                 $val["vo"] = array();
                 $menures[$val["id"]] = $val;
                 $menures[$val["id"]]["k"] = $rescount;
                 $rescount++;
             }
         }
         foreach ($catemenu as $val) {
             $val["url"] = $this->getLink($val["url"]);
             if (0 < $val["fid"]) {
                 array_push($menures[$val["fid"]]["vo"], $val);
             }
         }
     }
     $catemenu = $menures;
     $this->bottomeMenus = $catemenu;
     $this->assign("catemenu", $this->bottomeMenus);
     $radiogroup = $homeInfo["radiogroup"];
     if ($radiogroup == false) {
         $radiogroup = 0;
     }
     $cateMenuFileName = "tpl/Wap/default/Index_menuStyle" . $radiogroup . ".html";
     $this->assign("cateMenuFileName", $cateMenuFileName);
     $this->assign("radiogroup", $radiogroup);
     $this->user = S("user_" . $this->wxuser["uid"]);
     if (!$this->user || 1) {
         $this->user = D("Users")->find(intval($this->wxuser["uid"]));
         S("user_" . $this->wxuser["uid"], $this->user);
     }
     $this->assign("user", $this->user);
     $this->group = S("group_" . $this->user["gid"]);
     if (!$this->group || 1) {
         $this->group = M("User_group")->where(array("id" => intval($this->user["gid"])))->find();
         S("group_" . $this->user["gid"], $this->group);
     }
     $this->assign("group", $this->group);
     $this->company = S("company_" . $this->token);
     if (!$this->company || 1) {
         $company_db = M("company");
         $this->company = $company_db->where(array("token" => $this->token, "isbranch" => 0))->find();
         S("company_" . $this->token, $this->company);
     }
     $this->assign("company", $this->company);
     $this->copyright = $this->group["iscopyright"];
     $this->assign("iscopyright", $this->copyright);
     $this->assign("siteCopyright", C("copyright"));
     $this->assign("copyright", $this->copyright);
     $share = new WechatShare($this->wxuser, $this->wecha_id);
     $this->shareScript = $share->getSgin();
     $this->assign("shareScript", $this->shareScript);
     $this->fakeopenid = D("Userinfo")->where(array("token" => $this->token, "wecha_id" => $this->wecha_id))->getField("fakeopenid");
 }