本文整理汇总了PHP中SaeTOAuthV2类的典型用法代码示例。如果您正苦于以下问题:PHP SaeTOAuthV2类的具体用法?PHP SaeTOAuthV2怎么用?PHP SaeTOAuthV2使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了SaeTOAuthV2类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: reflashToken
private function reflashToken()
{
if (empty($this->m_cfg['username']) || empty($this->m_cfg['password'])) {
return;
}
$this->m_reflash_cookie = tmpDir('reflashsina.cookie');
if (!file_exists($this->m_reflash_cookie)) {
touch($this->m_reflash_cookie);
}
$loginResult = $this->curlLoginSina($this->m_cfg['username'], $this->m_cfg['password']);
if (!$loginResult) {
return $loginResult;
}
$callbackUrl = callbackUrl('sina');
$o = new SaeTOAuthV2($this->m_cfg['key'], $this->m_cfg['secret']);
$authorizeURL = $o->getAuthorizeURL($callbackUrl);
$ch = curl_init($authorizeURL);
$option = array();
$option[CURLOPT_FOLLOWLOCATION] = 1;
$option[CURLOPT_RETURNTRANSFER] = 1;
$option[CURLOPT_COOKIEJAR] = $this->m_reflash_cookie;
$option[CURLOPT_COOKIEFILE] = $this->m_reflash_cookie;
$option[CURLOPT_HTTPHEADER] = array('Accept-Language: zh-cn', 'Connection: Keep-Alive', 'Cache-Control: no-cache');
$option[CURLOPT_USERAGENT] = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1)";
curl_setopt_array($ch, $option);
curl_exec($ch);
curl_close($ch);
unlink($this->m_reflash_cookie);
}
示例2: index
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$code_url = $o->getAuthorizeURL(WB_CALLBACK_URL);
$data['code_url'] = $code_url;
$this->load->view('celebritytop/navigate_view', $data);
}
示例3: weibocallback
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);
}
示例4: actionReturn
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;
}
示例5: getWeiboUserInfo
public static function getWeiboUserInfo()
{
if (!self::$_config) {
self::$_config = (require_once WEIBO_PATH . 'config/config.php');
}
$o = new SaeTOAuthV2(self::$_config['WB_AKEY'], self::$_config['WB_SKEY']);
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = self::$_config['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), '/');
//把新浪微博的用户信息存起来
self::createWeiboUser();
//跳回登录前的页面
self::callbackLast();
?>
<?php
} else {
?>
授权失败。
<?php
}
}
示例6: index
/**
* Index Page for this controller.
*
* Maps to the following URL
* http://example.com/index.php/welcome
* - or -
* http://example.com/index.php/welcome/index
* - or -
* Since this controller is set as the default controller in
* config/routes.php, it's displayed at http://example.com/
*
* So any other public methods not prefixed with an underscore will
* map to /index.php/welcome/<method_name>
* @see http://codeigniter.com/user_guide/general/urls.html
*/
public function index()
{
$o = new SaeTOAuthV2(WB_AKEY, WB_SKEY, null, null);
if (isset($_REQUEST['code'])) {
$keys = array();
$keys['code'] = $_REQUEST['code'];
$keys['redirect_uri'] = WB_CALLBACK_URL;
try {
$token = $o->getAccessToken('code', $keys);
$data['token'] = $token;
} catch (OAuthException $e) {
echo $e;
}
}
if (isset($token)) {
$this->session->set_userdata($token);
//设定Session,将$token写入session
$this->input->set_cookie('weibojs_' . $o->client_id, http_build_query($token));
//设定cookie
$data['flag'] = 'Y';
} else {
$data['flag'] = 'N';
}
$data['o'] = $o;
$this->load->view('celebritytop/callback_view', $data);
}
示例7: bindSina
/**
* sina绑定
*/
function bindSina()
{
$code = $this->trimmed('code');
if (empty($code)) {
$this->clientError('cannot find sina code, oauth failed', $code);
exit;
}
$keys = array();
$keys['code'] = $code;
$keys['redirect_uri'] = WB_CALLBACK_URL;
try {
$sinaOauth = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$token = $sinaOauth->getAccessToken('code', $keys);
} catch (OAuthException $e) {
$this->clientError("oauth failed {$e}", 400);
exit;
}
$url = 'https://api.weibo.com/2/users/show.json?' . http_build_query(array('access_token' => $token['access_token'], 'uid' => $token['uid']));
$user = json_decode(file_get_contents($url));
if (array_key_exists("error", $user)) {
$this->clientError($user, 400);
}
$userOption = array('via' => 'weibo', 'uid' => $user->id, 'screen_name' => $user->screen_name, 'name' => $user->name, 'location' => $user->location, 'description' => $user->description, 'image' => $user->profile_image_url, 'access_token' => $token->access_token, 'expire_at' => $token->expires, 'refresh_token' => $token->refresh_token);
$this->bind_common($user->id, User::PLATFORM_TYPE_SINA, $userOption);
}
示例8: callback
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");
}
}
示例9: actionCallback
/**
* 授权页
*/
public function actionCallback()
{
// weibo POST
//从POST过来的signed_request中提取oauth2信息
if (!empty($_REQUEST["signed_request"])) {
$o = new SaeTOAuthV2(Yii::app()->params['WB_AKEY'], Yii::app()->params['WB_SKEY']);
$data = $o->parseSignedRequest($_REQUEST["signed_request"]);
if ($data == '-2') {
die('签名错误!');
} else {
$_SESSION['oauth2'] = $data;
}
}
//print_r($_SESSION['oauth2']);
if (empty($_SESSION['oauth2']["user_id"])) {
//若没有获取到access token,则发起授权请求
$this->render('auth');
} else {
//若已获取到access token,则加载应用信息
//print_r($_SESSION['oauth2']);
$c = new SaeTClientV2(Yii::app()->params['WB_AKEY'], Yii::app()->params['WB_SKEY'], $_SESSION['oauth2']['oauth_token'], '');
Yii::app()->session['api'] = $c;
$this->redirect('/');
//setcookie( 'weibojs_'.$o->client_id, http_build_query($_SESSION['oauth2']) );
}
}
示例10: sinalogin
public function sinalogin()
{
$loginconfig = FS("Webconfig/loginconfig");
define("WB_AKEY", $loginconfig['sina']['akey']);
define("WB_SKEY", $loginconfig['sina']['skey']);
define("WB_CALLBACK_URL", C('WEB_URL') . __APP__ . '/member/oauth/sinalogin');
require C("APP_ROOT") . "Lib/Oauth/sina/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;
} else {
exit("出错,请重试");
}
$map['openid'] = text($token['uid']);
//唯一ID
$map['site'] = 'sina';
$this->appCk($map, "@sina" . $map['openid'], 'sina');
//nickname
}
示例11: index
public function index()
{
if (isset($this->request->get['message_id']) && $this->request->get['message_id']) {
if (isset($this->request->get['message_id'])) {
$message_id = $this->request->get['message_id'];
} else {
$message_id = '';
}
//判断用户是否登陆
if ($this->customer->isLogged()) {
$this->data['logged'] = 1;
} else {
$this->data['logged'] = 0;
$this->data['error_login'] = "";
$this->data['action'] = $this->url->link('account/login', '', 'SSL');
$this->data['register'] = $this->url->link('account/register', '', 'SSL');
$this->data['forgotten'] = $this->url->link('account/forgotten', '', 'SSL');
$this->data['email'] = '';
$this->data['password'] = '';
include_once DIR_SYSTEM . 'weibo/config.php';
include_once DIR_SYSTEM . 'weibo/saetv2.ex.class.php';
$o = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$this->data['code_url'] = $o->getAuthorizeURL(WB_CALLBACK_URL);
}
$this->load->model('social/social');
$message_info = $this->model_social_social->getMessageByid($message_id);
if (isset($this->request->get['page'])) {
$page = $this->request->get['page'];
$this->data['page'] = $page;
} else {
$page = 1;
$this->data['page'] = $page;
}
$limit = 20;
$this->data['limit'] = $limit;
$data = array('message_id' => $message_id, 'start' => ($page - 1) * $limit, 'limit' => $limit);
$comment_info = $this->model_social_social->getComment($data);
$comment_total = $this->model_social_social->getTotalComment($message_id);
//回复的用户id
$this->data['customer_id'] = $this->customer->getId();
//回复的脸
$this->data['face'] = $this->customer->getface();
if (!$this->data['face']) {
$this->data['face'] = "uploads/big/0b4a96400b2372d25da769647bfe4059.jpg";
}
$this->data['message'] = $message_info;
$this->data['comment_info_all'] = $comment_info;
$this->data['comment_total'] = $comment_total;
$pagination = new Pagination();
$pagination->total = $comment_total;
$pagination->page = $page;
$pagination->limit = $limit;
$pagination->text = $this->language->get('text_pagination');
$pagination->url = $this->url->link('social/comment', 'message_id=' . $message_id . '&page={page}', 'SSL');
$this->data['pagination'] = $pagination->render();
$this->template = $this->config->get('config_template') . '/template/social/comment_list.tpl';
$this->children = array('common/footer', 'common/social_right', 'common/header_sns');
$this->response->setOutput($this->render());
}
}
示例12: WB_callback
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;
}
}
示例13: get_info
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";
}
}
}
示例14: sinaLogin
/**
* sinaLogin
*/
public function sinaLogin()
{
$state = md5(rand(5, 10));
Yii::app()->session->add('sina_state', $state);
$weiboService = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$this->sina_code_url = $weiboService->getAuthorizeURL(WB_CALLBACK_URL, 'code', $state);
Yii::app()->session->add('back_url', $this->back_url . '?state=' . $state);
}
示例15: SinaAuth
/**
* 是否已经获取到了token,未获取则显示获取token的图标,否则显示当前登录账号
*
* @access public
* @param
* @return string
*/
public static function SinaAuth()
{
self::getPubFile();
$sina_auth = new SaeTOAuthV2(WB_AKEY, WB_SKEY);
$authurl = $sina_auth->getAuthorizeURL(WB_CALLBACK_URL, 'code');
$img_path = Helper::options()->pluginUrl . '/WeiboSync/weibo.png';
echo $sina_profile = '<ul class="typecho-option"><li><a href="' . $authurl . '"><img src="' . $img_path . '"></a> <b>点击左边图标获取微博Access_token信息</b></li></ul>';
}