示例#1
0
 public function qqCallBackAction()
 {
     try {
         $config = $this->di->get('sdkconfig');
         $appid = $config['QQ']['appid'];
         //获取accesstoken
         $qc = new QcApi($this->di);
         $accessToken = $qc->getAccessToken();
         //获取openid
         $openId = $qc->getOpenid();
         $keysArr = ['oauth_consumer_key' => $appid, 'access_token' => $accessToken, 'openid' => $openId, 'format' => 'json'];
         if ($this->session->has('uid') && !empty($openId)) {
             $user = new Users();
             if ($user->getUinfo($openId, 'qq')) {
                 echo '<script>alert("绑定失败,该账号已绑定其他用户");window.location.href="/user/accountbind";</script>';
                 return;
             } else {
                 if ($user->bingQq($this->session->get('uid'), $openId)) {
                     $this->response->redirect('user/accountbind');
                 } else {
                     throw new E('QQ bing failed');
                 }
             }
         } else {
             $user = new Users();
             if ($uinfo = $user->getUinfo($openId, 'qq')) {
                 $cas = new \Ucenter\Utils\cas\CAServer();
                 $this->session->set('uid', $uinfo['u_id']);
                 $this->session->set('uinfo', array('name' => $uinfo['u_name'], 'mobile' => $uinfo['u_mobi']));
                 $cas->casSave(0, 0);
                 $this->response->redirect('user/index');
             } else {
                 $url = 'https://graph.qq.com/user/get_user_info';
                 $userInfo = $qc->get($url, $keysArr);
                 $userInfo = json_decode($userInfo);
                 $info = array('type' => 'qq', 'name' => $userInfo->nickname, 'uids' => $openId, 'pic' => $userInfo->figureurl_qq_2);
                 setcookie(substr(md5('tmpQqWb'), 8, 20), base64_encode(json_encode($info)), $_SERVER['REQUEST_TIME'] + 1800, '/');
                 $this->response->redirect('index/addUserInfo');
             }
         }
     } catch (E $e) {
         $this->response->redirect('login');
     }
 }
示例#2
0
 /**
  * [qqOauthAction QQ认证登陆]
  */
 public function qqOauthAction()
 {
     $qc = new QcApi($this->di);
     $qc->loginUrl();
 }