function callback() { //var_dump($_REQUEST); //这个key就是这个用户的令牌,很NB,要好好保存 $callback = site_url() . '/binding/tqq/callback'; //var_dump($this->session); $o = new MBOpenTOAuth(MB_AKEY, MB_SKEY, $this->session->userdata('oauth_token'), $this->session->userdata('oauth_token_secret')); $result = $o->getAccessToken($_REQUEST['oauth_verifier']); //获取ACCESSTOKEN //var_dump($result); $sns_oauth_token = $result['oauth_token']; $sns_oauth_token_secret = $result['oauth_token_secret']; $sns_uid = $result['name']; //让人吃金啊 if (empty($sns_uid)) { throw new Exception('oauth fail, havnt got getAccessToken()'); } //获取用户信息 //$c = new WeiboClient( WB_AKEY , WB_SKEY , $sns_oauth_token , $sns_oauth_token_secret); $c = new MBApiClient(MB_AKEY, MB_SKEY, $sns_oauth_token, $sns_oauth_token_secret); $me = $c->getUserInfo(); $me = $me['data']; //把资料准备好之后,剩下的就交给父类里的模版方法了! parent::post_login(UserManager::sns_website_tqq, $sns_uid, $sns_oauth_token, $sns_oauth_token_secret, $me['name']); /* $binding = $this->usermanager->get_binding_by_sns_uid(UserManager::sns_website_tqq, $sns_uid); if(empty($binding)) { //初次登录用户 //创建用户(同时创建sns_binding) $user = $this->usermanager->create_user(UserManager::sns_website_tqq, $sns_uid, $sns_oauth_token, $sns_oauth_token_secret, $me['name']); //把新创建的用户放到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); } */ }
/** * 此函数,供Callback处调用,如果返回false,认证失败,否则返回以下哈希表: * last_key -> callback得到的last_key * oauth_token -> 上述lastkey中的oauth_token * oauth_token_secret -> 上述lastkey中的oauth_token_secret * user_id -> 用户ID * user_name -> 用户昵称 * user_email -> 用户邮箱 */ function AuthCallback_tencent() { // 取得腾讯Auth对象 $o = new MBOpenTOAuth(MB_AKEY, MB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']); // 获取last_key $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']); if ($last_key) { $rtn = array(); $rtn['last_key'] = $last_key; $rtn['oauth_token'] = $last_key['oauth_token']; $rtn['oauth_token_secret'] = $last_key['oauth_token_secret']; $rtn['user_id'] = $last_key['name']; $client = new MBApiClient(MB_AKEY, MB_SKEY, $last_key['oauth_token'], $last_key['oauth_token_secret']); $user = $client->getUserInfo(); $rtn['user_name'] = $user['data']['nick']; $rtn['user_email'] = $user['data']['email']; return $rtn; } else { return $last_key; } }
function sendtalk() { $weibo = D('Weibobind'); $ctent = D('Content'); $user = Action::$login_user; $contentid = mysql_insert_id(); if ($contentid) { $content = $ctent->where("content_id='{$contentid}'")->find(); $text = $content['content_body']; $media = $content['media_body']; $text = str_replace('&', '&', $text); $text = ubbreplace($text); $media = ubbreplace($content['media_body']); $st = getsubstr($media, 0, 7, false); if ($st == 'http://' || $st == '/photo/') { if ($st == '/photo/') { $media = __PUBLIC__ . '/attachments' . $media; $media = str_replace('s_', '', $media); } $text = $text . $media; } $text = clean_html($text); } if ($text) { $bind = $weibo->where("uid='{$user['user_id']}'")->find(); if ($bind['sina_uid'] && $bind['sina_token'] && $bind['sina_tsecret'] && $bind['sendtosina'] == 1) { $sinawb = new WeiboClient(WB_AKEY, WB_SKEY, $bind['sina_token'], $bind['sina_tsecret']); $me = $sinawb->verify_credentials(); if ($me['id'] == $bind['sina_uid']) { $rssina = $sinawb->update($text); } } if ($bind['qq_uid'] && $bind['qq_token'] && $bind['qq_tsecret'] && $bind['sendtoqq'] == 1) { include_once "qqweibo/api_client.php"; $qqwb = new MBApiClient(MB_AKEY, MB_SKEY, $bind['qq_token'], $bind['qq_tsecret']); $me = $qqwb->getUserInfo(); if ($me['data']['name'] == $bind['qq_uid']) { $p = array('c' => $text, 'ip' => $_SERVER['REMOTE_ADDR'], 'j' => '', 'w' => ''); $rsqq = $qqwb->postOne($p); } } } }