get_uid() public method

对应API:{@link http://open.weibo.com/wiki/2/account/get_uid account/get_uid}
public get_uid ( ) : array
return array
Beispiel #1
0
 public function weibocallback($code)
 {
     $cfg = K::$system->config->get('connect');
     if (defined('IN_MOBILE')) {
         $mobile = K::$system->config->get('mobile');
         $callback = $mobile['url'] . '/' . K::M('helper/link')->mklink('passport:weibocallback');
     } else {
         $site = K::$system->config->get('site');
         $callback = $site['siteurl'] . '/' . K::M('helper/link')->mklink('passport:weibocallback');
     }
     if (empty($cfg['weibo_is_open'])) {
         $this->err->add('很抱歉网站管理员还未开启微博登录功能', 201);
         return false;
     }
     $keys = array();
     $keys['code'] = $code;
     $keys['redirect_uri'] = $callback;
     $o = new SaeTOAuthV2($cfg['weibo_app_id'], $cfg['weibo_app_key']);
     try {
         $token = $o->getAccessToken('code', $keys);
     } catch (OAuthException $e) {
         $this->err->add($e->getMessage(), 201);
         return false;
     }
     $c = new SaeTClientV2($cfg['weibo_app_id'], $cfg['weibo_app_key'], $token['access_token']);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $user_message = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     return $this->login($uid, $user_message);
 }
Beispiel #2
0
/**
 * 此函数,供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_sina()
{
    // 取得新浪Auth对象
    $sinaappkey = $_SESSION['sinaappkey'];
    $sinasecret = $_SESSION['sinasecret'];
    $o = new SaeTOAuthV2($sinaappkey, $sinasecret);
    if (isset($_REQUEST['code'])) {
        $keys = array();
        $keys['code'] = $_REQUEST['code'];
        $keys['redirect_uri'] = $_SESSION['wb_callback_url'];
        try {
            $last_key = $o->getAccessToken('code', $keys);
        } catch (OAuthException $e) {
        }
    }
    if ($last_key) {
        $rtn = array();
        $rtn['last_key'] = $last_key;
        $rtn['oauth_token'] = $keys['code'];
        $rtn['oauth_token_secret'] = $last_key['access_token'];
        $client = new SaeTClientV2($sinaappkey, $sinasecret, $last_key['access_token']);
        $uid_get = $client->get_uid();
        $rtn['user_id'] = $uid_get['uid'];
        $user_message = $client->show_user_by_id($rtn['user_id']);
        $rtn['user_name'] = $user_message['screen_name'];
        return $rtn;
    } else {
        return $last_key;
    }
}
Beispiel #3
0
 function actionReturn()
 {
     $o = new \SaeTOAuthV2($this->app_key, $this->app_secret);
     if ($_REQUEST['code']) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = $this->url;
         try {
             $token = $o->getAccessToken('code', $keys);
             $access_token = $token['access_token'];
             $c = new \SaeTClientV2($this->app_key, $this->app_secret, $access_token);
             $uid_get = $c->get_uid();
             $uid = $uid_get['uid'];
             $me = $c->show_user_by_id($uid);
             $me['name'] = $me['screen_name'];
             $me['options'] = array('url' => $me['profile_url']);
             $r = $this->member_get_third_set_user($me, $this->oauth_id, $access_token);
             flash('success', __('login success'));
             $this->redirect(return_url());
         } catch (OAuthException $e) {
             flash('error', __('login error'));
             $this->redirect(return_url());
         }
     }
     exit;
 }
Beispiel #4
0
 /**
  * 从Callback返回时
  */
 public function callback()
 {
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = WB_CALLBACK_URL;
         try {
             $token = $this->sina->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         $_SESSION['token'] = $token;
         setcookie('weibojs_' . $this->sina->client_id, http_build_query($token));
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']);
         $ms = $c->home_timeline();
         // done
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $user = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         $_SESSION['token']['name'] = $user['name'];
         echo "\n\t\t\t\t\t<script type=\"text/javascript\">\n\t\t\t\t\t\twindow.opener.callback_exec('Sina' , {$uid} , '{$user['name']}',false);\n\t\t\t\t\t\twindow.close();\n\t\t\t\t\t</script>";
     } else {
         echo '授权失败';
     }
 }
 function callbackAction()
 {
     $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
     $token = $this->getToken($o);
     if ($token) {
         $tokenNamespace = new Zend_Session_Namespace('token');
         $tokenNamespace->token = $token;
         setcookie('weibojs_' . $o->client_id, http_build_query($token));
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']);
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $db = Zend_Registry::get('db');
         $adapter = new WeiboLoginAuthAdapter($uid);
         $auth = Zend_Auth::getInstance();
         $result = $auth->authenticate($adapter);
         $consumerModel = new Consumer();
         $consumer_id = $db->fetchOne("SELECT id FROM consumer WHERE weiboid = :temp and state='ACTIVE'", array('temp' => $uid));
         $consumer = $consumerModel->find($consumer_id)->current();
         if ($result->isValid()) {
             $authNamespace = new Zend_Session_Namespace('Zend_Auth');
             $authNamespace->user = $consumer;
             $authNamespace->role = 'consumer';
             $logModel = new Log();
             $logId = $logModel->insert(array('consumer_id' => $consumer->id, 'date' => date("Y-m-d H:i:s"), 'event' => 'LOGIN'));
             //				$this->_helper->redirector('index', 'home');
             $this->_helper->redirector('index', 'tag');
         } else {
             $this->first();
         }
     }
 }
Beispiel #6
0
 function get_info()
 {
     if ($this->dx_auth->is_logged_in()) {
         echo "你已经登陆了";
     } else {
         $this->load->model('m_open');
         session_start();
         require_once APPPATH . 'libraries/weibo/config.php';
         require_once APPPATH . 'libraries/weibo/saetv2.ex.class.php';
         $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
         $o->set_debug(DEBUG_MODE);
         if (isset($_REQUEST['code'])) {
             $keys = array();
             // 验证state
             $state = $_REQUEST['state'];
             if (empty($state) || $state !== $_SESSION['weibo_state']) {
                 echo '非法请求!';
                 exit;
             }
             unset($_SESSION['weibo_state']);
             $keys['code'] = $_REQUEST['code'];
             $keys['redirect_uri'] = WB_CALLBACK_URL;
             try {
                 $token = $o->getAccessToken('code', $keys);
             } catch (OAuthException $e) {
             }
         }
         if ($token) {
             $_SESSION['token'] = $token;
             setcookie('weibojs_' . $o->client_id, http_build_query($token));
             //echo "success";
             $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
             $c->set_debug(DEBUG_MODE);
             $uid_get = $c->get_uid();
             $uid = $uid_get['uid'];
             if (!$uid) {
                 echo "error";
             }
             $user = $c->show_user_by_id($uid);
             //根据ID获取用户等基本信息
             //echo $user['screen_name'];
             if ($this->m_open->is_id($uid)) {
                 $this->m_open->login($uid);
                 //echo "登陆";
                 //echo $uid;
                 //$c->update( "坑爹的api终于调好了");
                 redirect('line');
             } else {
                 $this->m_open->register($user);
                 $this->m_open->create($user);
                 //echo $uid;
                 //echo "注册";
                 redirect('line');
             }
         } else {
             echo "fail";
         }
     }
 }
Beispiel #7
0
function get_user_info($config, $oauth_data)
{
    $c = new SaeTClientV2($config['appid'], $config['appkey'], $oauth_data['oauth_openid']);
    $get = $c->get_uid();
    $m = $c->show_user_by_id($get['uid']);
    //根据ID获取用户等基本信息
    return array('name' => $m['name'], 'avatar' => $m['profile_image_url']);
}
 private function getUserName()
 {
     $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
     $ms = $c->home_timeline();
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $user_message = $c->show_user_by_id($uid);
     return $user_message['screen_name'];
 }
Beispiel #9
0
 function get_openid()
 {
     if (!isset($_SESSION['sina']["openid"]) || !$_SESSION['sina']["openid"]) {
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['sina']['token']['access_token']);
         $uid_get = $c->get_uid();
         $_SESSION['sina']["openid"] = $uid_get['uid'];
     }
     return $_SESSION['sina']["openid"];
 }
Beispiel #10
0
 /**
  * 獲取用戶信息
  * @param type $access_token
  * @return type
  * Array ( [id] => 3767777785 [idstr] => 3767777785 [class] => 1 
  * [screen_name] => soqugame [name] => soqugame 
  * [province] => 11 [city] => 1 [location] => 北京 东城区 [description] => [url] => 
  * [profile_image_url] => http://tp2.sinaimg.cn/3767777785/50/0/1 
  * [profile_url] => u/3767777785 [domain] => [weihao] => [gender] => m [followers_count] => 3 [friends_count] => 18 [statuses_count] => 0 [favourites_count] => 0 [created_at] => Tue Sep 03 16:48:05 +0800 2013 [following] => [allow_all_act_msg] => [geo_enabled] => 1 [verified] => 1 [verified_type] => 2 [remark] => [ptype] => 0 [allow_all_comment] => 1 [avatar_large] => http://tp2.sinaimg.cn/3767777785/180/0/1 [avatar_hd] => http://tp2.sinaimg.cn/3767777785/180/0/1 [verified_reason] => 上海搜趣广告有限公司 [follow_me] => [online_status] => 0 [bi_followers_count] => 0 [lang] => zh-cn [star] => 0 [mbtype] => 0 [mbrank] => 0 [block_word] => 0 )
  */
 public function getUser($access_token)
 {
     $c = new SaeTClientV2($this->_params['WB_AKEY'], $this->_params['WB_SKEY'], $access_token);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $user_message = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     return $user_message;
 }
Beispiel #11
0
 function getUserInfo()
 {
     require_once dirname(__FILE__) . "/API/saetv2.ex.class.php";
     $token = ISession::get('token');
     $c = new SaeTClientV2(ISession::get('apiKey'), ISession::get('apiSecret'), $token['access_token']);
     $ms = $c->home_timeline();
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $user_message = $c->show_user_by_id($uid);
     $userInfo = array();
     $userInfo['id'] = $uid;
     $userInfo['name'] = isset($user_message['screen_name']) ? $user_message['screen_name'] : '';
     return $userInfo;
 }
Beispiel #12
0
 public function callback()
 {
     $appkey = $this->config->get('weibo_login_appkey');
     $appsecret = $this->config->get('weibo_login_appsecret');
     $callback_url = $this->url->link('extension/module/weibo_login/callback', '', true);
     $this->load->language('extension/module/weibo_login');
     $data['text_weibo_login'] = $this->language->get('text_weibo_login');
     include_once DIR_SYSTEM . 'library/weibo/saetv2.ex.class.php';
     $o = new SaeTOAuthV2($appkey, $appsecret);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = $callback_url;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         //setcookie( 'weibojs_'.$o->client_id, http_build_query($token) );
         $c = new SaeTClientV2($appkey, $appsecret, $token['access_token']);
         $ms = $c->home_timeline();
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $user_message = $c->show_user_by_id($uid);
         $this->session->data['weibo_login_access_token'] = $token['access_token'];
         $this->session->data['weibo_login_uid'] = $uid;
         if ($this->customer->login_weibo($this->session->data['weibo_login_access_token'], $this->session->data['weibo_login_uid'])) {
             unset($this->session->data['guest']);
             // Default Shipping Address
             $this->load->model('account/address');
             if ($this->config->get('config_tax_customer') == 'payment') {
                 $this->session->data['payment_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
             }
             if ($this->config->get('config_tax_customer') == 'shipping') {
                 $this->session->data['shipping_address'] = $this->model_account_address->getAddress($this->customer->getAddressId());
             }
             $this->response->redirect($this->url->link('account/account', '', 'SSL'));
         } else {
             $this->session->data['weibo_login_warning'] = sprintf($this->language->get('text_weibo_login_warning'), $this->config->get('config_name'));
             $this->response->redirect($this->url->link('account/login', '', 'SSL'));
         }
     } else {
         echo $this->language->get('text_weibo_fail');
     }
 }
Beispiel #13
0
 public function wbcallback()
 {
     Vendor('Weibo.saetv2#ex#class');
     $o = new \SaeTOAuthV2(C('weibo.wb_akey'), C('weibo.wb_skey'));
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $this->_request('code');
         $keys['redirect_uri'] = C('weibo.wb_callback_url');
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         // 获取用户信息
         $c = new SaeTClientV2(C('weibo.wb_akey'), C('weibo.wb_skey'), $token['access_token']);
         // $ms  = $c->home_timeline(); // done
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $uinfo = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         // 查询是否已经绑定
         $this->user_model = D('user');
         $user = $this->user_model->field('id,email,password')->where(array('wb_token' => $token['access_token'], 'wb_openid' => $uid))->find();
         // echo $this->user_model->getLastSql();
         if ($user['id'] > 0) {
             // 登录用户
             if ($this->user_model->login($user['id'], $user['email'], $user['password'])) {
                 //TODO:跳转到登录前页面
                 $this->success('登录成功!', session('rebackurl'));
             } else {
                 $this->error($model->getError());
             }
         } else {
             session('avatar', $uinfo['avatar_hd']);
             session('openid', $uinfo['id']);
             session('token', $token['access_token']);
             session('uname', $uinfo['screen_name']);
             session('oatype', 'wb_');
             //print_r($uinfo);
             $this->redirect('join');
         }
     } else {
         $this->error('授权失败。');
     }
 }
 public function index()
 {
     if ($this->config->get('weibo_login_status') !== '1') {
         $this->redirect($this->url->link('account/login', '', 'SSL'));
     }
     $this->load->model('account/weibo_login');
     $weibo_uid = '';
     if ($this->request->server['REQUEST_METHOD'] == 'GET') {
         if (isset($_REQUEST['code'])) {
             require_once DIR_SYSTEM . 'weiboSDK/oauth2.class.php';
             $appkey = $this->config->get('weibo_login_appkey');
             $appsecret = $this->config->get('weibo_login_secret');
             $o = new SaeTOAuthV2($appkey, $appsecret);
             $keys = array();
             $keys['code'] = $_REQUEST['code'];
             $keys['redirect_uri'] = $this->url->link('account/weibo_login');
             try {
                 $token = $o->getAccessToken('code', $keys);
                 $c = new SaeTClientV2($appkey, $appsecret, $token['access_token']);
                 $uid_get = $c->get_uid();
                 $weibo_uid = $uid_get['uid'];
             } catch (OAuthException $e) {
             }
         } else {
             $this->response->redirect($this->url->link('account/login', '', 'SSL'));
         }
     } else {
         // POST
         $weibo_uid = $this->request->post['weibo_uid'];
     }
     if (empty($weibo_uid)) {
         $this->response->redirect($this->url->link('account/login', '', 'SSL'));
     }
     if (!$this->model_account_weibo_login->getUidRecord($weibo_uid)) {
         // New customer
         $this->model_account_weibo_login->addCustomer($weibo_uid);
     }
     if ($this->model_account_weibo_login->getUidRecord($weibo_uid)) {
         unset($this->session->data['guest']);
         $customerInfo = $this->model_account_weibo_login->getCustomerInfoByUid($weibo_uid);
         $this->session->data['customer_id'] = $customerInfo['customer_id'];
         $this->customer->loginThridPart($customerInfo);
         $this->response->redirect($this->url->link('account/account'));
     }
 }
Beispiel #15
0
 function sina_oauth_back()
 {
     require_once APPPATH . 'libraries/sina/saetv2.ex.class.php';
     $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
     $back_url = base_url() . 'index.php?c=oauth&m=sina_oauth_back';
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = $back_url;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $user_message = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     if ($user_message['gender'] == 'm') {
         $user_data['tu_gender'] = 0;
     } else {
         $user_data['tu_gender'] = 1;
     }
     $user_data['tu_weibo_nickname'] = $user_message['screen_name'];
     $user_data['tu_source'] = 0;
     $weibo_user_check = $this->tickets->select('users', $user_data);
     if ($weibo_user_check) {
         $final_user = $weibo_user_check[0];
     } else {
         $save_dir = 'api_images';
         $image = $user_message['avatar_large'];
         $image_new_name = $this->generate_code(10) . '.jpg';
         $image = $this->getImage($image, $save_dir, $image_new_name, 1);
         $user_data['tu_portrait'] = $image['save_path'];
         $user_data['tu_created'] = date('Y-m-d H:i:s');
         $result = $this->tickets->insert('users', $user_data);
         $temp_user = $this->tickets->select('users', array('tu_id' => $result));
         $final_user = $temp_user[0];
     }
     setcookie('user_cookie', serialize($final_user), time() + 3600 * 24, '/');
     redirect('/main/index');
 }
Beispiel #16
0
 function userInfo($token)
 {
     $c = new SaeTClientV2($this->sina_akey, $this->sina_skey, $token);
     $home = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $me = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     $user['id'] = $me['id'];
     $user['type'] = $this->type;
     $user['uname'] = $me['name'];
     $user['province'] = $me['province'];
     $user['city'] = $me['city'];
     $user['location'] = $me['location'];
     $user['email'] = $me['data']['email'];
     $user['userface'] = str_replace($user['id'] . '/50/', $user['id'] . '/180/', $me['profile_image_url']);
     $user['sex'] = $me['gender'] == 'm' ? 1 : 0;
     return $user;
 }
 /**
  * 新浪注册
  */
 function registerSina()
 {
     $c = null;
     try {
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $this->token);
     } catch (Exception $ex) {
         $this->clientError(_('invalid_access_token'));
         return;
     }
     $uid_get = $c->get_uid();
     $error = $uid_get['error'];
     if (!empty($error)) {
         $this->clientError(_('invalid_access_token'));
         return;
     }
     $uid = $uid_get['uid'];
     $this->user_message = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     $this->regist_common($uid, User::PLATFORM_TYPE_SINA, $this->user_message['screen_name'], $this->user_message['profile_image_url'], $this->user_message['description'], $this->user_message['gender'], null);
 }
Beispiel #18
0
 function open()
 {
     session_start();
     require_once APPPATH . 'libraries/weibo/config.php';
     require_once APPPATH . 'libraries/weibo/saetv2.ex.class.php';
     $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
     $o->set_debug(DEBUG_MODE);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         // 验证state
         $state = $_REQUEST['state'];
         if (empty($state) || $state !== $_SESSION['weibo_state']) {
             echo '非法请求!';
             exit;
         }
         unset($_SESSION['weibo_state']);
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = WB_CALLBACK_URL;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         $_SESSION['token'] = $token;
         setcookie('weibojs_' . $o->client_id, http_build_query($token));
         echo "success";
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
         $c->set_debug(DEBUG_MODE);
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $user = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         echo $user['screen_name'];
         //利用一个方法将weibo_id存入users
         //利用一个方法将weibo个人信息存入info中
     } else {
         echo "fail";
     }
 }
    function callback()
    {
        import("Org.Util.saetv2");
        $o = new \SaeTOAuthV2(WB_AKEY, WB_SKEY);
        if (isset($_REQUEST['code'])) {
            $keys = array();
            $keys['code'] = $_REQUEST['code'];
            $keys['redirect_uri'] = WB_CALLBACK_URL;
            try {
                $token = $o->getAccessToken('code', $keys);
            } catch (OAuthException $e) {
            }
        }
        if ($token) {
            session("token", $token);
            //$_SESSION['token'] = $token
            setcookie('weibojs_' . $o->client_id, http_build_query($token));
            $c = new \SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
            $ms = $c->home_timeline();
            // done
            $uid_get = $c->get_uid();
            $uid = $uid_get['uid'];
            $user_message = $c->show_user_by_id($uid);
            //根据ID获取用户等基本信息
            //var_dump($user_message);die;
            session("username", $user_message["screen_name"]);
            session("c_img", $user_message["profile_image_url"]);
            echo session('username');
            ?>
			success ,<a href="http://www.sutuijian.com">come on</a> 
			<?php 
        } else {
            ?>
			default。
			<?php 
        }
    }
Beispiel #20
0
 $strOpen = $new['pubs']->find('user_open', array('sitename' => 'weibo', 'openid' => $openid));
 //10天更换一次access_token
 if (time() - 10 * 86400 > $strOpen['uptime']) {
     $new['pubs']->update('user_open', array('sitename' => 'weibo', 'openid' => $openid), array('access_token' => $access_token, 'uptime' => time()));
 }
 if ($strOpen['userid']) {
     $userData = $new['pubs']->find('user_info', array('userid' => $strOpen['userid']), 'userid,username,path,face,isadmin,signin,uptime');
     //更新登录时间
     $new['pubs']->update('user_info', array('userid' => $strOpen['userid']), array('ip' => getIp(), 'uptime' => time()));
     $_SESSION['tsuser'] = $userData;
     header("Location: " . SITE_URL);
     exit;
 } else {
     //获取用户基本资料
     $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $access_token);
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $arrUserInfo = $c->show_user_by_id($uid);
     /*	
     Array ( [id] => 2741015883 [idstr] => 2741015883 [class] => 1 [screen_name] => 哥哥很伤心啦 [name] => 哥哥很伤心啦 [province] => 11 [city] => 5 [location] => 北京 朝阳区 [description] => [url] => [profile_image_url] => http://tp4.sinaimg.cn/2741015883/50/5633423902/1 [profile_url] => u/2741015883 [domain] => [weihao] => [gender] => m [followers_count] => 3 [friends_count] => 30 [statuses_count] => 0 [favourites_count] => 0 [created_at] => Thu May 31 17:22:49 +0800 2012 [following] => [allow_all_act_msg] => [geo_enabled] => 1 [verified] => [verified_type] => -1 [remark] => [ptype] => 0 [allow_all_comment] => 1 [avatar_large] => http://tp4.sinaimg.cn/2741015883/180/5633423902/1 [avatar_hd] => http://tp4.sinaimg.cn/2741015883/180/5633423902/1 [verified_reason] => [follow_me] => [online_status] => 0 [bi_followers_count] => 0 [lang] => zh-cn [star] => 0 [mbtype] => 0 [mbrank] => 0 [block_word] => 0 )
     */
     if ($arrUserInfo['screen_name'] == '') {
         tsNotice('登陆失败!请使用Email登陆');
     }
     $salt = md5(rand());
     $pwd = random(5, 0);
     $userid = $new['pubs']->create('user', array('pwd' => md5($salt . $pwd), 'salt' => $salt, 'email' => $openid));
     //插入ts_user_info
     $new['pubs']->create('user_info', array('userid' => $userid, 'username' => $arrUserInfo['screen_name'], 'email' => $openid, 'ip' => getIp(), 'addtime' => time(), 'uptime' => time()));
     //插入ts_user_open
     $new['pubs']->create('user_open', array('userid' => $userid, 'sitename' => 'weibo', 'openid' => $openid, 'access_token' => $access_token, 'uptime' => time()));
Beispiel #21
0
 public function callback()
 {
     global_run();
     require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php';
     //$sina_keys = es_session::get("sina_keys");
     $o = new SaeTOAuthV2($this->api['config']['app_key'], $this->api['config']['app_secret']);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         if ($this->api['config']['app_url'] == "") {
             $app_url = SITE_DOMAIN . APP_ROOT . "/api_callback.php?c=Sina";
         } else {
             $app_url = $this->api['config']['app_url'];
         }
         $keys['redirect_uri'] = $app_url;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
             //print_r($e);exit;
             showErr("授权失败,错误信息:" . $e->getMessage());
             die;
         }
     }
     $c = new SaeTClientV2($this->api['config']['app_key'], $this->api['config']['app_secret'], $token['access_token']);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $msg = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     if (intval($msg['error_code']) != 0) {
         showErr("授权失败,错误代码:" . $msg['error_code']);
         die;
     }
     $msg['field'] = 'sina_id';
     $msg['sina_token'] = $token['access_token'];
     es_session::set("api_user_info", $msg);
     if (!$msg['name']) {
         app_redirect(url("index"));
         exit;
     }
     //print_r($msg);die();
     $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where sina_id = '" . $msg['id'] . "' and sina_id <> ''  and is_effect=1 and is_delete=0");
     $is_bind = intval(es_session::get("is_bind"));
     if ($user_data) {
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_token = '" . $token['access_token'] . "',login_ip = '" . CLIENT_IP . "',login_time= " . NOW_TIME . " where id =" . $user_data['id']);
         es_session::delete("api_user_info");
         if ($is_bind) {
             if (intval($user_data['id']) != intval($GLOBALS['user_info']['id'])) {
                 showErr("该帐号已经被别的会员绑定过,请直接用帐号登录", 0, url("index", "uc_account"));
             } else {
                 require_once APP_ROOT_PATH . "system/model/user.php";
                 load_user($user_data['id'], true);
                 es_session::set("user_info", $user_data);
                 app_redirect(url("index", "uc_account"));
             }
         } else {
             require_once APP_ROOT_PATH . "system/model/user.php";
             auto_do_login_user($user_data['user_name'], $user_data['user_pwd'], $from_cookie = false);
             app_redirect(url("index", "index"));
         }
     } elseif ($is_bind == 1 && $GLOBALS['user_info']) {
         //当有用户身份且要求绑定时
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_id= '" . $msg['id'] . "', sina_token ='" . $token['access_token'] . "' where id =" . $GLOBALS['user_info']['id']);
         require_once APP_ROOT_PATH . "system/model/user.php";
         load_user($GLOBALS['user_info']['id'], true);
         app_redirect(url("index", "uc_account"));
     } else {
         $user_info = $this->create_user();
         require_once APP_ROOT_PATH . "system/model/user.php";
         auto_do_login_user($user_info['user_name'], $user_info['user_pwd'], $from_cookie = false);
         app_redirect(url("index", "index"));
     }
 }
Beispiel #22
0
    public function sendwb()
    {
        // 获取消息正文 发晒单 bask 写心情 mood
        /*
         * if(isset($this->request->post['bask']) && ($this->request->post['bask'])) { $message_text = $this->request->post['bask']; $message_flag = 1; } else if(isset($this->request->post['mood']) && ($this->request->post['mood'])) { $message_text = $this->request->post['mood']; $message_flag = 2; } else { $message_text = ''; $message_flag = 0; } //获取图片url地址 $this->session->data['token'] if(isset($this->request->post['image']) && ($this->request->post['image'])) { $imgurl = $this->request->post['image']; } else { $imgurl = ''; } //获取视频url地址 if(isset($this->reuqest->post['video']) && ($this->request->post['video'])) { $videourl = $this->request->post['video']; } else { $videourl = ''; } //之前已经登录微博并授权 if (isset($_SESSION['token'])) { } //未登录微博授权 else { include_once(DIR_SYSTEM . 'weibo/config.php'); include_once(DIR_SYSTEM . 'weibo/saetv2.ex.class.php'); if (isset($_GET['code'])) { $keys = array(); $keys['code'] = $_GET['code']; $keys['redirect_uri'] = WBS_CALLBACK_URL; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } } else { echo "<script language=\"javascript\">window.open ('https://api.weibo.com/oauth2/authorize?client_id=".WB_AKEY."&redirect_uri=".WBS_CALLBACK_URL."&response_type=code','newwindow','height=440,width=630,top=150,left=300,toolbar=no,menubar=no,scrollbars=no,resizable=no,location=no,status=no')</script>"; } }
         */
        include_once DIR_SYSTEM . 'weibo/config.php';
        include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php';
        $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
        // 之前未登录微博授权
        if (isset($_GET['code'])) {
            $keys = array();
            $keys['code'] = $_GET['code'];
            $keys['redirect_uri'] = WBS_CALLBACK_URL;
            try {
                $token = $o->getAccessToken('code', $keys);
                // $this->session->data['token'] = $token;
            } catch (OAuthException $e) {
            }
        }
        if (isset($token) && !empty($token)) {
            $this->session->data['token'] = $token;
            $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
            $ms = $c->home_timeline();
            // done
            $uid_get = $c->get_uid();
            /*
             * var_dump($token); var_dump($uid_get);
             */
            $uid = $uid_get['uid'];
            $user_message = $c->show_user_by_id($uid);
            // 根据ID获取用户等基本信息
            // 图片微博
            if (isset($this->session->data['wb']['imgurl'])) {
                $ret = $c->upload($this->session->data['wb']['message_text'] . ' @信恩世通CNstorm', $this->session->data['wb']['imgurl']);
            } else {
                // 文字微博
                $ret = $c->update($this->session->data['wb']['message_text'] . ' @信恩世通CNstorm');
            }
            // 返回信息
            $msg = '';
            if (isset($ret['error_code']) && $ret['error_code'] > 0) {
                $err = '微博同步失败,';
                if ($ret['error_code'] == 20003) {
                    $msg = $err . "用户不存在";
                } elseif ($ret['error_code'] == 20005) {
                    $msg = $err . "目前仅支持JPG、GIF、PNG的图片";
                } elseif ($ret['error_code'] == 20006) {
                    $msg = $err . "图片太大";
                } elseif ($ret['error_code'] == 20012) {
                    $msg = $err . "输入文字太长,请不要超过140字";
                } elseif ($ret['error_code'] == 20015) {
                    $msg = $err . "账号、IP或应用非法,暂时无法完成此操作";
                } elseif ($ret['error_code'] == 20016) {
                    $msg = $err . "发布内容过于频繁";
                } elseif ($ret['error_code'] == 20017) {
                    $msg = $err . "提交相似的信息";
                } elseif ($ret['error_code'] == 20018) {
                    $msg = $err . "包含非法网址";
                } elseif ($ret['error_code'] == 20019) {
                    $msg = $err . "提交相同的信息";
                } elseif ($ret['error_code'] == 20020) {
                    $msg = $err . "包含广告信息";
                } elseif ($ret['error_code'] == 20021) {
                    $msg = $err . "包含非法内容";
                } elseif ($ret['error_code'] == 20022) {
                    $msg = $err . "此IP地址上的行为异常";
                } elseif ($ret['error_code'] == 20032) {
                    $msg = "发布成功,目前服务器可能会有延迟,请耐心等待1-2分钟";
                } else {
                    $msg = "微博同步失败";
                }
            } else {
                unset($this->session->data['wb']['message_text']);
                if (isset($this->session->data['wb']['imgurl'])) {
                    unset($this->session->data['wb']['imgurl']);
                }
                $msg = "微博同步成功";
            }
            echo <<<Eof
<script type="text/javascript">  
  var i = 3;
  function check(){
       if(i>0){
            i = i - 1;
            document.getElementById("time").innerHTML = i;
            setTimeout("check()",1000);
         }else{
          window.opener = null;
          window.close();
         }
   }
     setTimeout("check()",1000);
  
  </script>
  
  <body>
     <div><p>{$msg}</p></div>

     <div>本页面<span id="time">3</span>秒后自动关闭</div>

     <div><p><a href="http://www.weibo.com/" target="_blank">查看微博</a></p></div>

     <a href="javascript:window.opener=null;window.close();">直接关闭本页面</a>
  </body>
Eof;
        }
    }
Beispiel #23
0
 public function public_sina_login()
 {
     define('WB_AKEY', pc_base::load_config('system', 'sina_akey'));
     define('WB_SKEY', pc_base::load_config('system', 'sina_skey'));
     define('WEB_CALLBACK', APP_PATH . 'index.php?m=member&c=index&a=public_sina_login&callback=1');
     pc_base::load_app_class('saetv2.ex', '', 0);
     $this->_session_start();
     if (isset($_GET['callback']) && trim($_GET['callback'])) {
         $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
         if (isset($_REQUEST['code'])) {
             $keys = array();
             $keys['code'] = $_REQUEST['code'];
             $keys['redirect_uri'] = WEB_CALLBACK;
             try {
                 $token = $o->getAccessToken('code', $keys);
             } catch (OAuthException $e) {
             }
         }
         if ($token) {
             $_SESSION['token'] = $token;
         }
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
         $ms = $c->home_timeline();
         // done
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $me = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         if (CHARSET != 'utf-8') {
             $me['name'] = iconv('utf-8', CHARSET, $me['name']);
             $me['location'] = iconv('utf-8', CHARSET, $me['location']);
             $me['description'] = iconv('utf-8', CHARSET, $me['description']);
             $me['screen_name'] = iconv('utf-8', CHARSET, $me['screen_name']);
         }
         if (!empty($me['id'])) {
             //检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
             $where = array('connectid' => $me['id'], 'from' => 'sina');
             $r = $this->db->get_one($where);
             //connect用户已经绑定本站用户
             if (!empty($r)) {
                 //读取本站用户信息,执行登录操作
                 $password = $r['password'];
                 $this->_init_phpsso();
                 $synloginstr = $this->client->ps_member_synlogin($r['phpssouid']);
                 $userid = $r['userid'];
                 $groupid = $r['groupid'];
                 $username = $r['username'];
                 $nickname = empty($r['nickname']) ? $username : $r['nickname'];
                 $this->db->update(array('lastip' => ip(), 'lastdate' => SYS_TIME, 'nickname' => $me['name']), array('userid' => $userid));
                 if (!$cookietime) {
                     $get_cookietime = param::get_cookie('cookietime');
                 }
                 $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);
                 $cookietime = $_cookietime ? TIME + $_cookietime : 0;
                 $phpcms_auth = sys_auth($userid . "\t" . $password, 'ENCODE', get_auth_key('login'));
                 param::set_cookie('auth', $phpcms_auth, $cookietime);
                 param::set_cookie('_userid', $userid, $cookietime);
                 param::set_cookie('_username', $username, $cookietime);
                 param::set_cookie('_groupid', $groupid, $cookietime);
                 param::set_cookie('cookietime', $_cookietime, $cookietime);
                 param::set_cookie('_nickname', $nickname, $cookietime);
                 $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?m=member&c=index';
                 showmessage(L('login_success') . $synloginstr, $forward);
             } else {
                 //弹出绑定注册页面
                 $_SESSION = array();
                 $_SESSION['connectid'] = $me['id'];
                 $_SESSION['from'] = 'sina';
                 $connect_username = $me['name'];
                 //加载用户模块配置
                 $member_setting = getcache('member_setting');
                 if (!$member_setting['allowregister']) {
                     showmessage(L('deny_register'), 'index.php?m=member&c=index&a=login');
                 }
                 //获取用户siteid
                 $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1;
                 //过滤非当前站点会员模型
                 $modellist = getcache('member_model', 'commons');
                 foreach ($modellist as $k => $v) {
                     if ($v['siteid'] != $siteid || $v['disabled']) {
                         unset($modellist[$k]);
                     }
                 }
                 if (empty($modellist)) {
                     showmessage(L('site_have_no_model') . L('deny_register'), HTTP_REFERER);
                 }
                 $modelid = 10;
                 //设定默认值
                 if (array_key_exists($modelid, $modellist)) {
                     //获取会员模型表单
                     require CACHE_MODEL_PATH . 'member_form.class.php';
                     $member_form = new member_form($modelid);
                     $this->db->set_model($modelid);
                     $forminfos = $forminfos_arr = $member_form->get();
                     //万能字段过滤
                     foreach ($forminfos as $field => $info) {
                         if ($info['isomnipotent']) {
                             unset($forminfos[$field]);
                         } else {
                             if ($info['formtype'] == 'omnipotent') {
                                 foreach ($forminfos_arr as $_fm => $_fm_value) {
                                     if ($_fm_value['isomnipotent']) {
                                         $info['form'] = str_replace('{' . $_fm . '}', $_fm_value['form'], $info['form']);
                                     }
                                 }
                                 $forminfos[$field]['form'] = $info['form'];
                             }
                         }
                     }
                     $formValidator = $member_form->formValidator;
                 }
                 include template('member', 'connect');
             }
         } else {
             showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login');
         }
     } else {
         $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
         $aurl = $o->getAuthorizeURL(WEB_CALLBACK);
         include template('member', 'connect_sina');
     }
 }
Beispiel #24
0
function login_by_weibo()
{
    include 'saetv2.ex.class.php';
    global $_db, $_cache, $_user;
    session_start();
    $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
    if (isset($_REQUEST['code'])) {
        $keys = array();
        $keys['code'] = $_REQUEST['code'];
        $keys['redirect_uri'] = WB_CALLBACK_URL;
        try {
            $token = $o->getAccessToken('code', $keys);
        } catch (OAuthException $e) {
        }
    }
    if ($token) {
        $_SESSION['token'] = $token;
        setcookie('weibojs_' . $o->client_id, http_build_query($token));
        $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
        $uid_get = $c->get_uid();
        $uid = $uid_get['uid'];
        $_user = user::get_one(array('weibo_uid' => $uid));
        $user_id = $_user->user_id;
        $user_info = $c->show_user_by_id($uid);
        //根据ID获取用户等基本信息
        if (!$user_id) {
            $user_id = user::register(array('screen_name' => $user_info['screen_name'], 'weibo_uid' => $uid, 'avatar_url' => $user_info['profile_image_url']));
            $_user = user::get_one(array('user_id' => $user_id));
            $res = 'new_user';
        } else {
            $res = $_user;
        }
        $_SESSION['uid'] = $user_id;
        //set_cookie('uid',$user_id);
        return $res;
    } else {
        //授权失败
    }
    return false;
}
Beispiel #25
0
 public function sina_callback()
 {
     $dir = './Public/Library/sinaAuth/';
     include_once $dir . 'config.php';
     include_once $dir . 'saetv2.ex.class.php';
     $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         $keys['redirect_uri'] = WB_CALLBACK_URL;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
         }
     }
     if ($token) {
         $_SESSION['token'] = $token;
         setcookie('weibojs_' . $o->client_id, http_build_query($token));
         $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
         //$ms  = $c->home_timeline(); // done
         $uid_get = $c->get_uid();
         $uid = $uid_get['uid'];
         $user_message = $c->show_user_by_id($uid);
         //根据ID获取用户等基本信息
         $openid = $user_message['idstr'];
         $nickname = $user_message['name'];
         //TODO 注册登录
     } else {
         echo '授权失败。';
     }
 }
 public function callback()
 {
     require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php';
     es_session::start();
     //$sina_keys = es_session::get("sina_keys");
     $o = new SaeTOAuthV2($this->api['config']['app_key'], $this->api['config']['app_secret']);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         if ($this->api['config']['app_url'] == "") {
             $app_url = get_domain() . APP_ROOT . "/api_callback.php?c=Sina";
         } else {
             $app_url = $this->api['config']['app_url'];
         }
         $keys['redirect_uri'] = $app_url;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
             print_r($e);
             exit;
         }
     }
     $c = new SaeTClientV2($this->api['config']['app_key'], $this->api['config']['app_secret'], $token['access_token']);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $msg = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     //name,url,province,city,avatar,token,field,token_field(授权的字段),sex,secret_field(授权密码的字段),scret,url_field(微博地址的字段)
     $api_data['name'] = $msg['name'];
     $api_data['url'] = "http://weibo.com/" . $msg['profile_url'];
     $location = $msg['location'];
     $location = explode(" ", $location);
     $api_data['province'] = $location[0];
     $api_data['city'] = $location[1];
     $api_data['avatar'] = $msg['http://tp2.sinaimg.cn/3048107865/180/0/1'];
     $api_data['field'] = 'sina_id';
     $api_data['token'] = $token['access_token'];
     $api_data['token_field'] = "sina_token";
     $api_data['secret'] = "";
     $api_data['secret_field'] = "sina_secret";
     $api_data['url_field'] = "sina_url";
     if ($msg['gender'] == 'm') {
         $api_data['sex'] = 1;
     } else {
         if ($msg['gender'] == 'f') {
             $api_data['sex'] = 0;
         } else {
             $api_data['sex'] = -1;
         }
     }
     if ($msg['name'] != "") {
         es_session::set("api_user_info", $api_data);
     }
     $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where sina_id = '" . $api_data['name'] . "' and sina_id <> ''");
     if ($user_data) {
         es_session::delete("api_user_info");
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_token = '" . $api_data['token'] . "',login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",sina_url = '" . $api_data['url'] . "' where id =" . $user_data['id']);
         update_user_weibo($user_data['id'], $api_data['url']);
         //更新微博
         es_session::set("user_info", $user_data);
         app_redirect_preview();
     } else {
         if ($GLOBALS['user_info']) {
             update_user_weibo($GLOBALS['user_info']['id'], $api_data['url']);
             //更新微博
             $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_id = '" . $api_data['name'] . "',sina_token = '" . $api_data['token'] . "',sina_url = '" . $api_data['url'] . "' where id =" . intval($GLOBALS['user_info']['id']));
             app_redirect(url("settings#bind"));
         } else {
             app_redirect(url("user#api_register"));
         }
     }
 }
 /**
  * 检查用户登陆
  * @param $userInfo
  * @return array
  */
 public function checkLogin()
 {
     //获取微博用户信息(根据ID获取用户等基本信息)
     $Client = new \SaeTClientV2($this->weibo_akey, $this->weibo_skey, $_SESSION['token']['access_token']);
     $uid_get = $Client->get_uid();
     $weiboUser = $Client->show_user_by_id($uid_get['uid']);
     $model = D('Common/Users');
     $userInfo = $model->login($weiboUser['name']);
     //如果没有用户信息的,则新增用户
     if ($userInfo === false) {
         $this->createUser($weiboUser);
     }
     cookie('ticket', json_encode($userInfo['ticket']));
     $cookie = array('avatar' => $userInfo['weibo_avatar'], 'username' => $userInfo['username']);
     notPreCookie('user', $cookie);
     $this->Redis->set($userInfo['ticket'], serialize($userInfo), C('COOKIE_EXPIRE'));
     //写日志
     D('Common/LoginLog')->writeLog($userInfo['username']);
     $callback = $this->Redis->get('callback');
     if ($callback != false) {
         header("Location:" . base64_decode(urldecode($callback)));
     } else {
         header("Location:/");
     }
 }
Beispiel #28
0
 public function getUserDataFromAPI($uid = 0, $token = '')
 {
     if (!$token) {
         $token = getWeiboToken();
     }
     if (!$token) {
         throw new InvalidArgumentException('no token');
     }
     $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $token);
     if (!$uid) {
         $userID = $c->get_uid();
         $uid = $userID['uid'];
     }
     return $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
 }
Beispiel #29
0
<?php

session_start();
include_once 'config.php';
include_once 'saetv2.ex.class.php';
// if not access the auth
if (!isset($_SESSION['token']) || empty($_SESSION['token']) || empty($_SESSION['token']['access_token'])) {
    header('Location:http://xweibo.mapp.cc/');
    die;
}
$c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['token']['access_token']);
$uid = $c->get_uid();
$uid = $uid['uid'];
$user_message = $c->show_user_by_id($uid);
//根据ID获取用户等基本信息
$tip = '';
if (isset($user_message['error']) && !empty($user_message['error'])) {
    $tip = <<<HTML
          <div id="tip_error" class="row">
            <div class="span7">
              <div class="error">
  由于新浪微博 API 的请求限制,服务暂时无法使用,请稍后重试,谢谢 :)
              </div>
            </div>
            <div class="span1">
            </div>
          </div>
HTML;
}
// Delete weibo by ids
if (isset($_POST['del_ids']) && !empty($_POST['del_ids']) && empty($tip)) {
 public function callback()
 {
     require_once APP_ROOT_PATH . 'system/api_login/sina/saetv2.ex.class.php';
     es_session::start();
     //$sina_keys = es_session::get("sina_keys");
     $o = new SaeTOAuthV2($this->api['config']['app_key'], $this->api['config']['app_secret']);
     if (isset($_REQUEST['code'])) {
         $keys = array();
         $keys['code'] = $_REQUEST['code'];
         if ($this->api['config']['app_url'] == "") {
             $app_url = SITE_DOMAIN . APP_ROOT . "/api_callback.php?c=Sina";
         } else {
             $app_url = $this->api['config']['app_url'];
         }
         $keys['redirect_uri'] = $app_url;
         try {
             $token = $o->getAccessToken('code', $keys);
         } catch (OAuthException $e) {
             //print_r($e);exit;
             showErr("授权失败,错误信息:" . $e->getMessage());
             die;
         }
     }
     $c = new SaeTClientV2($this->api['config']['app_key'], $this->api['config']['app_secret'], $token['access_token']);
     $ms = $c->home_timeline();
     // done
     $uid_get = $c->get_uid();
     $uid = $uid_get['uid'];
     $msg = $c->show_user_by_id($uid);
     //根据ID获取用户等基本信息
     if (intval($msg['error_code']) != 0) {
         showErr("授权失败,错误代码:" . $msg['error_code']);
         die;
     }
     $msg['field'] = 'sina_id';
     $msg['sina_token'] = $token['access_token'];
     es_session::set("api_user_info", $msg);
     if (!$msg['name']) {
         app_redirect(url("index"));
         exit;
     }
     $user_data = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user where sina_id = '" . $msg['id'] . "' and sina_id <> 0");
     //print_r($user_data);die();
     if ($user_data) {
         $user_current_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where id = " . intval($user_data['group_id']));
         $user_group = $GLOBALS['db']->getRow("select * from " . DB_PREFIX . "user_group where score <=" . intval($user_data['score']) . " order by score desc");
         if ($user_current_group['score'] < $user_group['score']) {
             $user_data['group_id'] = intval($user_group['id']);
         }
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_token = '" . $token['access_token'] . "',login_ip = '" . get_client_ip() . "',login_time= " . get_gmtime() . ",group_id=" . intval($user_data['group_id']) . " where id =" . $user_data['id']);
         es_session::delete("api_user_info");
         $is_bind = intval(es_session::get("is_bind"));
         if ($is_bind) {
             if (intval($user_data['id']) != intval($GLOBALS['user_info']['id'])) {
                 showErr("该帐号已经被别的会员绑定过,请直接用帐号登录", 0, url("shop", "uc_center#setweibo"));
             } else {
                 es_session::set("user_info", $user_data);
                 app_redirect(url("index", "uc_center#setweibo"));
             }
         } else {
             require_once APP_ROOT_PATH . "system/libs/user.php";
             auto_do_login_user($user_data['user_name'], md5($user_data['user_pwd'] . "_EASE_COOKIE"), $from_cookie = false);
             app_recirect_preview();
         }
     } elseif ($is_bind == 1 && $GLOBALS['user_info']) {
         //当有用户身份且要求绑定时
         $GLOBALS['db']->query("update " . DB_PREFIX . "user set sina_id= '" . intval($msg['id']) . "', sina_token ='" . $token['access_token'] . "' where id =" . $GLOBALS['user_info']['id']);
         app_redirect(url("index", "uc_center#setweibo"));
     } else {
         $this->create_user();
         app_redirect(get_gopreview());
     }
 }