按用户UID或昵称返回用户资料,同时也将返回用户的最新发布的微博。
对应API:{@link http://open.weibo.com/wiki/2/users/show users/show}
对应API:{@link http://open.weibo.com/wiki/2/users/show users/show}
public show_user_by_id ( integer $uid ) : array | ||
$uid | integer | 用户UID。 |
return | array |
/** * 从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 userInfo() { $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['sina']['token']['access_token']); $uid = $this->get_openid(); return $user = $c->show_user_by_id($uid); //根据ID获取用户等基本信息 }
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); }
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; }
function callback() { $o = new SaeTOAuthV2(c('weibo_akey'), c('weibo_skey')); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = 'http://' . c('site_domain') . '/?c=weibo&a=callback'; try { $token = $o->getAccessToken('code', $keys); } catch (OAuthException $e) { } $_SESSION['weibo_token'] = $token; // get user info $c = new SaeTClientV2(c('weibo_akey'), c('weibo_skey'), atoken()); $info = $c->show_user_by_id(wbuid()); if (strlen($info['name']) < 1) { return info_page('登入失败,请去吃点零食后重试'); } $_SESSION['weibo_uid'] = $info['name']; $_SESSION['uname'] = $info['name']; $_SESSION['avatar'] = $info['profile_image_url']; //print_r( $_SESSION ); header("Location: /?a=index"); } }
function WB_callback() { $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; // $login_type = getvaluebykey('login_type'); // $userid = getvaluebykey('userid'); // print_r($userid);exit; // $headpic = getvaluebykey('headpic'); // $emailnum = getvaluebykey('emailnum'); $keys['redirect_uri'] = WB_CALLBACK_URL; //.'?login_type='.$login_type.'_'.$userid.'_'.$headpic.'_'.$emailnum; try { $token = $o->getAccessToken('code', $keys); //print_r($token); } catch (OAuthException $e) { } } if ($token) { $_SESSION['token'] = $token; $c1 = new SaeTClientV2(WB_AKEY, WB_SKEY, $token['access_token']); $userinfo = $c1->show_user_by_id($token[uid]); setcookie('weibojs_' . $o->client_id, http_build_query($token)); $cb_arr = array('access_token' => $token['access_token'], 'openid' => $token[uid], 'nick' => $userinfo['name']); return $cb_arr; } }
/** * 此函数,供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; } }
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"; } } }
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']); }
/** * 授权回调地址 */ public function callback() { if (empty($_GET['code'])) { throw new Typecho_Exception(_t('无效请求!')); } //跳转 if (!class_exists('SaeTOAuthV2')) { require_once './saetv2.ex.class.php'; } $saeto_client = new SaeTOAuthV2($this->config->client_id, $this->config->client_secret); //取access_token $access_token = $saeto_client->getAccessToken('code', array('code' => trim($_GET['code']), 'redirect_uri' => $this->config->callback_url)); if (empty($access_token) || !is_array($access_token) || empty($access_token['uid'])) { throw new Typecho_Exception(_t('获取access_token失败,请返回重新授权!')); } $table = $this->db->getPrefix() . self::$tableName; $query = $this->db->query("SELECT * FROM {$table} WHERE openid='{$access_token['uid']}' AND plateform='sina'"); $users_oauth = $this->db->fetchRow($query); if (!empty($users_oauth['uid'])) { //该新浪帐号已经绑定了用户 if (Typecho_Widget::widget('Widget_User')->hasLogin()) { /** 直接返回 */ $this->response->redirect(Typecho_Widget::widget('Widget_Options')->index); } else { //让其直接登陆 $this->setUserLogin($users_oauth['uid']); if (!Typecho_Widget::widget('Widget_User')->pass('contributor', true)) { /** 不允许普通用户直接跳转后台 */ $this->response->redirect(Typecho_Widget::widget('Widget_Options')->profileUrl); } else { $this->response->redirect(Typecho_Widget::widget('Widget_Options')->adminUrl); } } exit; } //该新浪帐号未绑定过 /** 如果已经登录 */ if (Typecho_Widget::widget('Widget_User')->hasLogin()) { /** 直接绑定 */ $cookieUid = Typecho_Cookie::get('__typecho_uid'); $this->bindOauthUser($cookieUid, $access_token['uid'], 'sina', $access_token['expires_in']); $this->response->redirect(Typecho_Widget::widget('Widget_Options')->index); } else { //取用户信息 $saetc_client = new SaeTClientV2($this->config->client_id, $this->config->client_secret, $access_token['access_token']); $weibo_user = $saetc_client->show_user_by_id($access_token['uid']); //创建用户 $uid = $this->registerFromWeiboUser($weibo_user); if (!$uid) { throw new Typecho_Exception(_t('创建帐号失败,请联系管理员!')); } $this->setUserLogin($uid); $this->bindOauthUser($uid, $access_token['uid'], 'sina', $access_token['expires_in']); $this->response->redirect(Typecho_Widget::widget('Widget_Options')->profileUrl); } //构造用户帐号 exit; }
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']; }
/** * 獲取用戶信息 * @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; }
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; }
public function getUserInfo($request_args) { is_null($request_args['code']) && exit; $oauth = new SaeTOAuthV2($this->setting['app_key'], $this->setting['app_secret']); $keys = array('code' => $request_args['code'], 'redirect_uri' => $this->redirect_uri); $token = $oauth->getAccessToken('code', $keys); $client = new SaeTClientV2($this->setting['app_key'], $this->setting['app_secret'], $token['access_token']); $user = $client->show_user_by_id($token['uid']); $result['keyid'] = $user['id']; $result['keyname'] = $user['name']; $result['keyavatar_small'] = $user['profile_image_url']; $result['keyavatar_big'] = $user['avatar_large']; $result['bind_info'] = $token; return $result; }
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 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'); } }
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'); }
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); }
/** * 新浪微博回调地址 * sinawb login */ public function actionSinawb_callback() { require_once Yii::getPathOfAlias('ext') . "/OAuth/sinawb/config.php"; require_once Yii::getPathOfAlias('ext') . "/OAuth/sinawb/saetv2.ex.class.php"; $sinawb = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if (isset($_REQUEST['code'])) { $keys = array(); $keys['code'] = $_REQUEST['code']; $keys['redirect_uri'] = WB_CALLBACK_URL; try { $token = $sinawb->getAccessToken('code', $keys); } catch (OAuthException $e) { throw new CHttpException(500, 'Error:' . $e->getMessage()); } } if ($token) { $access_token = Yii::app()->session['access_token'] = $token['access_token']; $openid = $token['uid']; //设置cookie $cookie_name = 'weibojs_' . $openid; $cookie = new CHttpCookie($cookie_name, http_build_query($token)); $cookie->expire = time() + 60 * 60 * 24 * 30; //有限期30天 Yii::app()->request->cookies[$cookie_name] = $cookie; //获取用户信息 $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $access_token); $user_info = $c->show_user_by_id($openid); //根据ID获取用户等基本信息 if ($user_info['error']) { throw new CHttpException('500', Yii::t('common', 'Login Failed') . '(' . $user_info['error_code'] . ')'); } //查看是否已绑定 $bind = OAuthSinawb::model()->findByPk($openid); //数据 $data = array('type' => 'sinawb', 'access_token' => $access_token, 'openid' => $openid, 'uid' => $bind ? $bind->uid : 0, 'username' => $user_info['screen_name'], 'avatar' => $user_info['avatar_large']); //绑定注册 $this->bind_register($bind, $data); } else { $this->message('error', Yii::t('common', 'Login Failed') . '(sinawb_x_0000)', $this->createUrl('user/login')); } }
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"; } }
/** * Sina Callback */ public function actionSinacallback() { set_time_limit(0); $o = new SaeTOAuthV2(WB_AKEY, WB_SKEY); if ($code = $this->request->getQuery('code')) { $keys = array(); $keys['code'] = $code; $keys['redirect_uri'] = WB_CALLBACK_URL; try { if (Yii::app()->session["weibo_access_token"]) { $access_token = Yii::app()->session["weibo_access_token"]; $sns_id = Yii::app()->session['user']['sns_uid']; } else { $token = $o->getAccessToken('code', $keys); $access_token = $token["access_token"]; $sns_id = $token["uid"]; } $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $access_token); $basic_account = $c->show_user_by_id($sns_id); if ($user = $this->getUser($basic_account['id'])) { $this->refreshSnsUser($user['uid'], $access_token, $basic_account); Yii::app()->session['is_login'] = "******"; Yii::app()->session['user'] = $user; } else { if ($user = $this->regUser($access_token, $basic_account)) { Yii::app()->session["is_login"] = "******"; Yii::app()->session["user"] = $user; $this->responseJSON($user, 'success'); } } echo "Success! Please close this window"; } catch (oAuthException $e) { echo 'error'; } } else { echo 'error'; } }
/** * * 功能:微博登陆 */ public static function weiboLogin($code) { import('Vendor.Weibo.saetv2'); $weibo = new \SaeTOAuthV2(WB_APPKEY, WB_SKEY); $params = array('client_id' => WB_APPKEY, 'client_secret' => WB_SKEY, 'grant_type' => 'authorization_code', 'code' => $code, 'redirect_uri' => WB_REDIRECT_URI); $accessToken = $weibo->getAccessToken('code', $params); if (!$accessToken || $accessToken['access_token'] == '' || !$accessToken['uid']) { return array('status' => false, 'msg' => '登陆失败,获取access_token失败'); } $clientModel = new \SaeTClientV2(WB_APPKEY, WB_SKEY, $accessToken['access_token']); $userInfo = $clientModel->show_user_by_id($accessToken['uid']); if ($userInfo['error_code']) { return array('status' => false, 'msg' => $userInfo['error']); } //判断本地是否有该用户 $rs = M('Users')->where('weiboid=' . $accessToken['uid'])->find(); if (!$rs) { $data['username'] = ''; $data['nickname'] = $userInfo['screen_name']; $data['avator'] = $userInfo['avatar_large']; $data['salt'] = ''; $data['passwd'] = ''; $data['weiboid'] = $accessToken['uid']; $data['address'] = $userInfo['location']; $data['ip'] = get_client_ip(); $data['posttime'] = time(); $userId = M('Users')->add($data); if (!$userId) { return array('status' => false, 'msg' => '登陆失败'); } } session(array("name" => SESSION_ID, 'path' => "/", "expire" => $accessToken['expires_in'])); session(SESSION_ID, $rs ? $rs['userid'] : $userId); session(array("name" => SESSION_TOKEN, 'path' => "/", "expire" => $accessToken['expires_in'])); session(SESSION_TOKEN, $rs ? $rs['userid'] : $userId); cookie("__info__", authcode(serialize(array('nickname' => $userInfo['screen_name'], 'userid' => $rs ? $rs['userid'] : $userId, 'avator' => $userInfo['avatar_large'])), "ENCODE", SESSION_AUTH, $accessToken['expires_in'])); return array('status' => true, 'msg' => '登陆成功'); }
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 } }
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())); //更新用户头像 if ($arrUserInfo['avatar_large']) {
/** * 分享绑定sinaweibo */ public function share_sinaweiboOp() { //判断系统是否开启站外分享功能 if (C('share_sinaweibo_isuse') != 1) { showMessage(Language::get('sharebind_unused'), 'index.php?act=member_sharemanage', 'html', 'error'); } include_once BASE_DATA_PATH . '/api/snsapi/sinaweibo/callback.php'; if (!$_SESSION['slast_key']) { echo "<script>alert('" . Language::get('sharebind_bind_fail') . "');</script>"; echo "<script>window.close();</script>"; exit; } $update_arr = array(); $update_arr['snsbind_memberid'] = $_SESSION['member_id']; $update_arr['snsbind_membername'] = $_SESSION['member_name']; $update_arr['snsbind_appsign'] = 'sinaweibo'; $update_arr['snsbind_updatetime'] = time(); $update_arr['snsbind_accesstoken'] = $_SESSION['slast_key']['access_token']; $update_arr['snsbind_expiresin'] = $_SESSION['slast_key']['expires_in']; $update_arr['snsbind_openid'] = $_SESSION['slast_key']['uid']; //获取新浪微博账号信息 require_once BASE_DATA_PATH . DS . 'api' . DS . 'snsapi' . DS . 'sinaweibo' . DS . 'saetv2.ex.class.php'; $c = new SaeTClientV2(C('sina_wb_akey'), C('sina_wb_skey'), $_SESSION['slast_key']['access_token']); $sinauser_info = $c->show_user_by_id($_SESSION['slast_key']['uid']); //根据ID获取用户等基本信息 $update_arr['snsbind_openinfo'] = $sinauser_info['name']; $model = Model(); $where_arr = array(); $where_arr['snsbind_memberid'] = $_SESSION['member_id']; $where_arr['snsbind_appsign'] = 'sinaweibo'; //查询该用户是否已经绑定sinaweibo $bind_info = $model->table('sns_binding')->where($where_arr)->find(); if (empty($bind_info)) { $result = $model->table('sns_binding')->insert($update_arr); } else { $result = $model->table('sns_binding')->where($where_arr)->update($update_arr); } if (!$result) { echo "<script>alert('" . Language::get('sharebind_bind_fail') . "');</script>"; } echo "<script>window.close();</script>"; exit; }
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")); } }
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; } }
/** * 新浪微博账号绑定新用户 */ public function registerOp() { //实例化模型 $model_member = Model('member'); //检查登录状态 $model_member->checkloginMember(); if ($_POST['form_submit'] == 'ok') { //注册验证 $obj_validate = new Validate(); $obj_validate->validateparam = array(array("input" => $_POST["user_name"], "require" => "true", "message" => Language::get('login_usersave_username_isnull')), array("input" => $_POST["password"], "require" => "true", "message" => Language::get('login_usersave_password_isnull')), array("input" => $_POST["password_confirm"], "require" => "true", "validator" => "Compare", "operator" => "==", "to" => $_POST["password"], "message" => Language::get('login_usersave_password_not_the_same')), array("input" => $_POST["email"], "require" => "true", "validator" => "email", "message" => Language::get('login_usersave_wrong_format_email')), array("input" => $_POST["agree"], "require" => "true", "message" => Language::get('login_usersave_you_must_agree'))); $error = $obj_validate->validate(); if ($error != '') { showMessage(Language::get('error') . $error, '', 'html', 'error'); } if (C('captcha_status_register') == '1') { $captcha = trim($_POST['captcha']); if (!$captcha) { showMessage(Language::get('login_usersave_code_isnull'), '', 'html', 'error'); } if (!checkSeccode($_POST['nchash'], $captcha)) { showMessage(Language::get('login_usersave_wrong_code'), '', 'html', 'error'); } } $check_member_name = $model_member->infoMember(array('member_name' => trim($_POST['user_name']))); if (is_array($check_member_name) and count($check_member_name) > 0) { showMessage(Language::get('login_usersave_your_username_exists'), '', 'html', 'error'); } $check_member_email = $model_member->infoMember(array('member_email' => trim($_POST['email']))); if (is_array($check_member_email) and count($check_member_email) > 0) { showMessage(Language::get('login_usersave_your_email_exists'), '', 'html', 'error'); } $user_array = array(); if ($GLOBALS['setting_config']['ucenter_status'] == '1') { /** * Ucenter处理 */ $model_ucenter = Model('ucenter'); $uid = $model_ucenter->addUser(trim($_POST['user_name']), trim($_POST['password']), trim($_POST['email'])); if ($uid > 0) { $user_array['member_id'] = $uid; } else { showMessage(Language::get('login_usersave_regist_fail'), SiteUrl . '/index.php?act=login&op=register', 'html', 'error'); } } /** * 会员添加 */ $user_array['member_name'] = $_POST['user_name']; $user_array['member_passwd'] = $_POST['password']; $user_array['member_email'] = $_POST['email']; $user_array['member_sinaopenid'] = $_SESSION['slast_key']['uid']; //sina openid //处理sina账号信息 $sina_arr = array(); if (trim($_POST['regsname'])) { $sina_arr['name'] = trim($_POST['regsname']); } $sina_str = ''; if (is_array($sina_arr) && count($sina_arr) > 0) { $sina_str = serialize($sina_arr); } $user_array['member_sinainfo'] = $sina_str; //sina 信息 $result = $model_member->addMember($user_array); if ($result) { $_SESSION['is_login'] = '******'; $_SESSION['member_id'] = $result; $_SESSION['member_name'] = trim($user_array['member_name']); $_SESSION['member_email'] = trim($user_array['member_email']); //添加会员积分 if ($GLOBALS['setting_config']['points_isuse'] == 1) { $points_model = Model('points'); $points_model->savePointsLog('regist', array('pl_memberid' => $_SESSION['member_id'], 'pl_membername' => $_SESSION['member_name']), false); } $success_message = Language::get('login_usersave_regist_success'); showMessage($success_message, SiteUrl); } else { showMessage(Language::get('login_usersave_regist_fail'), SiteUrl . '/index.php?act=login&op=register', 'html', 'error'); } } else { //获取新浪微博账号信息 require_once BasePath . DS . 'api' . DS . 'sina' . DS . 'saetv2.ex.class.php'; $c = new SaeTClientV2($GLOBALS['setting_config']['sina_wb_akey'], $GLOBALS['setting_config']['sina_wb_skey'], $_SESSION['slast_key']['access_token']); $sinauser_info = $c->show_user_by_id($_SESSION['slast_key']['uid']); //根据ID获取用户等基本信息 Tpl::output('sinauser_info', $sinauser_info); Tpl::output('nchash', substr(md5(SiteUrl . $_GET['act'] . $_GET['op']), 0, 8)); Tpl::showpage('sconnect_register'); } }
* 此文件暂不升级了 * 此文件欠缺多次升级 */ /* get_task_avatar.php */ include_once '../config.php'; include_once $webRoot . 'lib/saetv2.ex.class.php'; include_once $webRoot . 'lib/dbo.class.php'; include_once $dbConfFile; include_once $webRoot . 'foundation/debug.php'; $c = new SaeTClientV2(WB_AKEY, WB_SKEY, $_SESSION['stoken']); $dbo = new dbex($dbServs); /* 获取关注任务的图标url */ $sql = "select task_id, task_sina_uid from task where type='follow' and (task_icon_url IS NULL OR task_screen_name IS NULL OR task_location IS NULL) limit 2"; $sql_res = $dbo->getRs($sql); foreach ($sql_res as $user) { $user_info = $c->show_user_by_id($user['task_sina_uid']); if_weiboapi_fail($user_info); $icon_url = $user_info['avatar_large']; $screen_name = $user_info['screen_name']; $location = $user_info['location']; // echo '<p><img src="'.$icon_url.'" />'.$location.$screen_name.'</p>'; $sql = "update task set task_icon_url='{$icon_url}', task_screen_name='{$screen_name}', task_location='{$location}' where task_id = {$user['task_id']} limit 1"; echo '<p>' . $sql . '</p>'; $dbo->query($sql); } /* 获取转发任务的小图标,微博内容,微博图片大url和小url */ $sql = "select task_id, task_sina_wid from task where type='repost' and (task_icon_url IS NULL OR task_thumbnail_pic_url IS NULL OR task_bmiddle_pic_url IS NULL OR task_text IS NULL) limit 50"; $sql_res = $dbo->getRs($sql); foreach ($sql_res as $user) { $weibo = $c->show_status($user['task_sina_wid']); if_weiboapi_fail($weibo);