Beispiel #1
0
 /**
  * 
  * 网站的首页
  */
 public function index()
 {
     if ($this->weixiao->is_login()) {
         $data = array('user' => $this->weixiao->get_cur_user());
         //获得所有绑定的数据
         $bindings = $this->usermanager->get_binding_by_uid($this->weixiao->get_cur_user()->id);
         foreach ($bindings as $binding) {
             switch ($binding->sns_website) {
                 case UserManager::sns_website_sina:
                     $data['binding_sina'] = $binding;
                     //读sina的数据
                     $c = new WeiboClient(WB_AKEY, WB_SKEY, $binding->sns_oauth_token, $binding->sns_oauth_token_secret);
                     $me = $c->verify_credentials();
                     $data['sina'] = $me;
                     $friends = $c->friends_ids(null, 5000, $binding->sns_uid);
                     $data['friends_sina'] = $friends['ids'];
                     break;
                 case UserManager::sns_website_qq:
                     $data['binding_qq'] = $binding;
                     //读qq的数据
                     $qq = new QqConnect();
                     $me = $qq->get_user_info(QQ_APPID, QQ_APPKEY, $binding->sns_oauth_token, $binding->sns_oauth_token_secret, $binding->sns_uid);
                     $data['qq'] = $me;
                     break;
                 case UserManager::sns_website_tqq:
                     $data['binding_tqq'] = $binding;
                     //读t.qq的数据
                     $c = $this->snsfactory->getMBApiClient(MB_AKEY, MB_SKEY, $binding->sns_oauth_token, $binding->sns_oauth_token_secret);
                     //						$c = new MBApiClient( MB_AKEY , MB_SKEY , $binding->sns_oauth_token , $binding->sns_oauth_token_secret);
                     $me = $c->getUserInfo();
                     $me = $me['data'];
                     $data['tqq'] = $me;
                     $friends = $c->getMyfans(array('num' => 30, 'start' => 0, 'type' => 1, 'n' => ''));
                     $data['friends_tqq'] = $friends['data']['info'];
                     break;
                 case UserManager::sns_website_renren:
                     $data['binding_renren'] = $binding;
                     //读renren的数据
                     $renren = new RenrenConnect();
                     $me = $renren->get_user_info(RENREN_APPKEY, RENREN_APPSECRET, $binding->sns_oauth_token, $binding->sns_uid);
                     $data['renren'] = $me[0];
                     $friends = $renren->get_friends(RENREN_APPKEY, RENREN_APPSECRET, $binding->sns_oauth_token);
                     $data['friends_renren'] = $friends;
                     break;
             }
         }
         $this->load->view('index_login', $data);
     } else {
         $this->load->view('index_not_login');
     }
     //$this->load->view('main_view',  array('users'=>$this->db->get('users')));
 }
Beispiel #2
0
 function callback()
 {
     //var_dump($_REQUEST);
     $qq = new QqConnect();
     //这个key就是这个用户的令牌,很NB,要好好保存
     $result = $qq->get_access_token(QQ_APPID, QQ_APPKEY, $this->session->userdata('oauth_request_token'), $this->session->userdata('oauth_request_token_secret'), $_REQUEST['oauth_vericode']);
     //var_dump($result);
     $sns_oauth_token = $result['oauth_access_token'];
     $sns_oauth_token_secret = $result['oauth_access_token_secret'];
     $sns_uid = $result['openid'];
     if (empty($sns_uid)) {
         throw new Exception('oauth fail, havnt got get_access_token()');
     }
     //获取用户信息
     $me = $qq->get_user_info(QQ_APPID, QQ_APPKEY, $sns_oauth_token, $sns_oauth_token_secret, $sns_uid);
     //把资料准备好之后,剩下的就交给父类里的模版方法了!
     parent::post_login(UserManager::sns_website_qq, $sns_uid, $sns_oauth_token, $sns_oauth_token_secret, $me['nickname']);
     /*
     $binding = $this->usermanager->get_binding_by_sns_uid(UserManager::sns_website_qq, $sns_uid);
     if(empty($binding))
     {
     	//初次登录用户
     	//创建用户(同时创建sns_binding)
     	$user = $this->usermanager->create_user(UserManager::sns_website_qq, $sns_uid, $sns_oauth_token, $sns_oauth_token_secret, $me['nickname']);
     	//把新创建的用户放到ci->weixiao里
     	$this->weixiao->set_user_token($user->user_token);
     	$cur_user = $this->weixiao->get_cur_user();
     	if(empty($cur_user)) throw new Exception("something strange happens, cant get user just login.");
     	$data = array('user'=>$cur_user);
     	$this->load->view('binding/first_binding', $data);
     }
     else {
     	//老用户
     	//TODO 初次登录进入binding/first_binding,否则关闭弹出窗口,刷新父页面
     	$user = $this->usermanager->get_by_id($binding->user_id);
     	//把新创建的用户放到ci->weixiao里
     	$this->weixiao->set_user_token($user->user_token);
     	$cur_user = $this->weixiao->get_cur_user();
     	if(empty($cur_user)) throw new Exception("something strange happens, cant get user just login.");
     	$data = array('user'=>$cur_user);
     	$this->load->view('binding/not_first_binding', $data);
     }
     */
 }
Beispiel #3
0
         return;
     }
     $qc = new QqConnect();
     $url = $qc->create_login_url();
     unset($qc);
     redirect($url);
 } elseif ($ref == "qqlogged") {
     if ($MAC['connect']['qq']['status'] == 0) {
         echo 'QQ一键登录已关闭';
         return;
     }
     $qc = new QqConnect();
     if ($qc->checkLogin()) {
         $qc->callback();
         $qqid = $qc->get_openid();
         $userinfo = $qc->get_user_info();
         $nickname = $userinfo["nickname"];
         $nickname = replaceStr($nickname, "'", "");
         $tmpname = $nickname;
         $i = 0;
         $rscount = $db->getOne("SELECT count(*) FROM {pre}user where u_qid='" . $qqid . "'");
         if ($rscount == 0) {
             $rscount = $db->getOne("SELECT count(*) FROM {pre}user where u_name='" . $tmpname . "'");
             while ($rscount > 0) {
                 $tmpname = $nickname . $i;
                 $rscount = $db->getOne("SELECT count(*) FROM {pre}user where u_name='" . $tmpname . "'");
                 $i++;
             }
             $nickname = $tmpname;
             $db->Add("{pre}user", array("u_name", "u_qid", "u_password", "u_qq", "u_email", "u_regtime", "u_status", "u_points", "u_group", "u_phone", "u_question", "u_answer"), array($nickname, $qqid, md5(""), "", "", time(), $MAC['user']['regstate'], $MAC['user']['regpoint'], $MAC['user']['reggroup'], "", "", ""));
         }