/** * QQ号码登录 * 该函数为QQ登录回调地址 */ public function public_qq_loginnew() { $appid = pc_base::load_config('system', 'qq_appid'); $appkey = pc_base::load_config('system', 'qq_appkey'); $callback = pc_base::load_config('system', 'qq_callback'); pc_base::load_app_class('qqapi', '', 0); $info = new qqapi($appid, $appkey, $callback); $this->_session_start(); if (!isset($_GET['code'])) { $info->redirect_to_login(); } else { $code = $_GET['code']; $openid = $_SESSION['openid'] = $info->get_openid($code); if (!empty($openid)) { $r = $this->db->get_one(array('connectid' => $openid, 'from' => 'qq')); if (!empty($r)) { //QQ已存在于数据库,则直接转向登陆操作 $password = $r['password']; $this->_init_phpsso(); $synloginstr = $this->client->ps_member_synlogin($r['phpssouid']); $userid = $r['userid']; $groupid = $r['groupid']; $username = $r['username']; $nickname = empty($r['nickname']) ? $username : $r['nickname']; $this->db->update(array('lastip' => ip(), 'lastdate' => SYS_TIME, 'nickname' => $me['name']), array('userid' => $userid)); if (!$cookietime) { $get_cookietime = param::get_cookie('cookietime'); } $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0); $cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth = sys_auth($userid . "\t" . $password, 'ENCODE', get_auth_key('login')); param::set_cookie('auth', $phpcms_auth, $cookietime); param::set_cookie('_userid', $userid, $cookietime); param::set_cookie('_username', $username, $cookietime); param::set_cookie('_groupid', $groupid, $cookietime); param::set_cookie('cookietime', $_cookietime, $cookietime); param::set_cookie('_nickname', $nickname, $cookietime); $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index'; showmessage(L('login_success') . $synloginstr, $forward); } else { //未存在于数据库中,跳去完善资料页面。页面预置用户名(QQ返回是UTF8编码,如有需要进行转码) $user = $info->get_user_info(); $_SESSION['connectid'] = $openid; $_SESSION['from'] = 'qq'; if (CHARSET != 'utf-8') { //转编码 $connect_username = iconv('utf-8', CHARSET, $user); } else { $connect_username = $user; } include template('member', 'connect'); } } } }
public function public_qq_login2() { $appid = pc_base::load_config('system', 'qq_appid'); $appkey = pc_base::load_config('system', 'qq_appkey'); $callback = pc_base::load_config('system', 'qq_callback'); pc_base::load_app_class('qqapi', '', 0); $info = new qqapi($appid, $appkey, $callback); $this->_session_start(); if (!isset($_GET['oauth_token'])) { $info->redirect_to_login(); } else { $info->get_openid(); if (!empty($_SESSION['openid'])) { $r = $this->db->get_one(array('connectid' => $_SESSION['openid'], 'from' => 'qq')); if (!empty($r)) { //登陆 $password = $r['password']; $this->_init_phpsso(); $synloginstr = $this->client->ps_member_synlogin($r['phpssouid']); $userid = $r['userid']; $groupid = $r['groupid']; $username = $r['username']; $nickname = empty($r['nickname']) ? $username : $r['nickname']; $this->db->update(array('lastip' => ip(), 'lastdate' => SYS_TIME, 'nickname' => $me['name']), array('userid' => $userid)); if (!$cookietime) { $get_cookietime = param::get_cookie('cookietime'); } $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0); $cookietime = $_cookietime ? TIME + $_cookietime : 0; $phpcms_auth_key = md5(pc_base::load_config('system', 'auth_key') . $this->http_user_agent); $phpcms_auth = sys_auth($userid . "\t" . $password, 'ENCODE', $phpcms_auth_key); param::set_cookie('auth', $phpcms_auth, $cookietime); param::set_cookie('_userid', $userid, $cookietime); param::set_cookie('_username', $username, $cookietime); param::set_cookie('_groupid', $groupid, $cookietime); param::set_cookie('cookietime', $_cookietime, $cookietime); param::set_cookie('_nickname', $nickname, $cookietime); $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index'; showmessage(L('login_success') . $synloginstr, $forward); } else { $user = $info->get_user_info(); $_SESSION['connectid'] = $_SESSION['openid']; $_SESSION['from'] = 'qq'; $connect_username = $user['nickname']; include template('member', 'connect'); } } } }