示例#1
0
 public function index()
 {
     //$callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'] . '/?O=QQ_oauth&A=callback';
     $request_token = OpenSDK_Tencent_Weibo::getRequestToken(TX_callback);
     $url = OpenSDK_Tencent_Weibo::getAuthorizeURL($request_token);
     header('Location: ' . $url);
 }
示例#2
0
 private function jump()
 {
     global $_FANWE;
     OpenSDK_Tencent_Weibo::init($this->config['app_key'], $this->config['app_secret']);
     $request_token = OpenSDK_Tencent_Weibo::getRequestToken($_FANWE['site_url'] . "callback/tqq.php");
     $url = OpenSDK_Tencent_Weibo::getAuthorizeURL($request_token);
     fSetCookie('login_oauth', authcode(serialize($request_token), 'ENCODE'));
     $url = FU('tgo', array('url' => $url));
     fHeader("location:" . $url);
 }
示例#3
0
        if (isset($_GET['oauth_token']) && isset($_GET['oauth_verifier'])) {
            //从Callback返回时
            if (OpenSDK_Tencent_Weibo::getAccessToken($_GET['oauth_verifier'])) {
                $uinfo = OpenSDK_Tencent_Weibo::call('user/info');
                echo '从Opent返回并获得授权。你的微博帐号信息为:<br />';
                echo 'Access token: ', OpenSDK_Tencent_Weibo::getParam(OpenSDK_Tencent_Weibo::ACCESS_TOKEN), '<br />';
                echo 'oauth_token_secret: ', OpenSDK_Tencent_Weibo::getParam(OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET), '<br />';
                echo 'OpenID: ', OpenSDK_Tencent_Weibo::getParam(OpenSDK_Tencent_Weibo::OAUTH_OPENID), '<br />';
                echo 'OpenKey: ', OpenSDK_Tencent_Weibo::getParam(OpenSDK_Tencent_Weibo::OAUTH_OPENKEY), '<br />';
                echo '你的微博帐号信息为:<br /><pre>';
                var_dump($uinfo);
            } else {
                echo '获得Access Tokn 失败';
            }
            $exit = true;
        } else {
            if (isset($_GET['go_oauth'])) {
                $callback = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
                $request_token = OpenSDK_Tencent_Weibo::getRequestToken($callback);
                !$request_token && exit('获取request_token失败,请检查网络或者appkey和appsecret是否正确');
                $url = OpenSDK_Tencent_Weibo::getAuthorizeURL($request_token);
                header('Location: ' . $url);
            } else {
                echo '腾讯微博OAuth1.0接口演示<a href="?go_oauth">点击去授权</a>';
            }
        }
    }
}
if ($exit) {
    echo '<a href="?exit">退出再来一次</a>';
}
示例#4
0
 /**
  * 腾讯微博登录
  */
 public function public_tencent_login()
 {
     define('APP_KEY', Core::load_config('open_platform', 'Tencent_Weibo_App_Key'));
     define('APP_SECRET', Core::load_config('open_platform', 'Tencent_Weibo_App_Secret'));
     Core::load_core_class('weibo', CORE_PATH . 'class' . DS . 'opensdk' . DS . 'tencent', 0);
     OpenSDK_Tencent_Weibo::init(APP_KEY, APP_SECRET);
     Core::session_start();
     if (isset($_GET['callback']) && trim($_GET['callback'])) {
         OpenSDK_Tencent_Weibo::getAccessToken($_GET['oauth_verifier']);
         $uinfo = OpenSDK_Tencent_Weibo::call('user/info');
         $uinfo['data']['openid'] = $_GET['openid'];
         if ($uinfo) {
             // 检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
             $member_bind = Loader::model('member_bind_model')->get_one(array('connectid' => $uinfo['data']['openid'], 'form' => 'tencent'));
             if (!empty($member_bind)) {
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET]);
                 $r = $this->db->get_one(array('userid' => $member_bind['userid']));
                 // 读取本站用户信息,执行登录操作
                 $password = $r['password'];
                 if (C('config', 'ucenter')) {
                     $synloginstr = $this->client->uc_user_synlogin($r['ucenterid']);
                 }
                 $userid = $r['userid'];
                 $groupid = $r['groupid'];
                 $username = $r['username'];
                 $nickname = empty($r['nickname']) ? $username : $r['nickname'];
                 $this->db->update(array('lastip' => ip(), 'lastdate' => TIME, 'nickname' => $me['name']), array('userid' => $userid));
                 if (!$cookietime) {
                     $get_cookietime = cookie_get('cookietime');
                 }
                 $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);
                 $cookietime = $_cookietime ? TIME + $_cookietime : 0;
                 $yuncms_auth_key = md5(C('config', 'auth_key') . $this->http_user_agent);
                 $yuncms_auth = String::authcode($userid . "\t" . $password, 'ENCODE', $yuncms_auth_key);
                 cookie_set('auth', $yuncms_auth, $cookietime);
                 cookie_set('_userid', $userid, $cookietime);
                 cookie_set('_username', $username, $cookietime);
                 cookie_set('_groupid', $groupid, $cookietime);
                 cookie_set('cookietime', $_cookietime, $cookietime);
                 cookie_set('_nickname', $nickname, $cookietime);
                 $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?app=member&controller=index';
                 showmessage(L('login_success') . $synloginstr, $forward);
             } else {
                 OpenSDK_Tencent_Weibo::call('friends/add', array('name' => 'newsteng'), 'POST');
                 // 弹出绑定注册页面
                 $_SESSION['connectid'] = $uinfo['data']['openid'];
                 $_SESSION['token'] = $_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN];
                 $_SESSION['token_secret'] = $_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET];
                 $connect_username = $uinfo['data']['name'];
                 $connect_nick = $uinfo['data']['nick'];
                 $connect_email = $uinfo['data']['email'];
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]);
                 unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET]);
                 cookie_set('open_name', $uinfo['data']['name']);
                 cookie_set('open_from', 'tencent');
                 if (isset($_GET['bind'])) {
                     showmessage(L('bind_success'), 'index.php?app=member&controller=account&action=bind&t=1');
                 }
                 include template('member', 'connect');
             }
         } else {
             unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN]);
             unset($_SESSION[OpenSDK_Tencent_Weibo::ACCESS_TOKEN]);
             unset($_SESSION[OpenSDK_Tencent_Weibo::OAUTH_TOKEN_SECRET]);
             showmessage(L('login_failure'), 'index.php?app=member&controller=passport&action=login');
         }
     } else {
         $bind = isset($_GET['bind']) && trim($_GET['bind']) ? '&bind=' . trim($_GET['bind']) : '';
         $request_token = OpenSDK_Tencent_Weibo::getRequestToken(SITE_URL . 'index.php?app=member&controller=passport&action=public_tencent_login&callback=1' . $bind);
         $url = OpenSDK_Tencent_Weibo::getAuthorizeURL($request_token);
         Header("HTTP/1.1 301 Moved Permanently");
         Header("Location: {$url}");
     }
 }