/** * * 网站的首页 */ 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'))); }
function callback() { //var_dump($_REQUEST); $renren = new RenrenConnect(); //这个key就是这个用户的令牌,很NB,要好好保存 $callback = site_url() . '/binding/renren/callback'; $sns_oauth_token = $renren->get_access_token(RENREN_APPKEY, RENREN_APPSECRET, $callback, $_REQUEST['code']); //var_dump($sns_oauth_token); $result = $renren->get_session_key($sns_oauth_token); //var_dump($result); $reren_session_key = $result->renren_token->session_key; $reren_session_secret = $result->renren_token->session_secret; $reren_token_expires_in = $result->renren_token->expires_in; $sns_uid = $result->user->id; if (empty($sns_uid)) { throw new Exception('oauth fail, havnt got get_access_token()'); } //获取用户信息 $me = $renren->get_user_info(RENREN_APPKEY, RENREN_APPSECRET, $reren_session_key, $sns_uid); //var_dump($me); //把资料准备好之后,剩下的就交给父类里的模版方法了! parent::post_login(UserManager::sns_website_renren, $sns_uid, $reren_session_key, $reren_session_secret, $me[0]->name, $reren_token_expires_in); /* $binding = $this->usermanager->get_binding_by_sns_uid(UserManager::sns_website_renren, $sns_uid); if(empty($binding)) { //初次登录用户 //创建用户(同时创建sns_binding) $user = $this->usermanager->create_user(UserManager::sns_website_renren, $sns_uid, $reren_session_key, $reren_session_secret, $me[0]->name, $reren_token_expires_in); //把新创建的用户放到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 { //老用户 $user = $this->usermanager->get_by_id($binding->user_id); //更新session_key,$reren_token_expires_in和display_name if ($reren_session_key!=$binding->sns_oauth_token || $me[0]->name!=$binding->sns_display_name) { $binding = $this->usermanager->update_sns_binding($binding->user_id, UserManager::sns_website_renren, $sns_uid, $reren_session_key, $reren_session_secret, $me[0]->name, $reren_token_expires_in); } //把刚登录的的用户放到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); } */ }