예제 #1
0
		public function oauth() {
			pc_base::load_plugin_class('weibooauth','',0);
			$setting = getcache('weibo_var','plugins');			
			if(!isset($_REQUEST['oauth_verifier']) || $_REQUEST['oauth_verifier'] == '') {
				if($this->auth_db->get_one(array('source'=>'sina'))) {
					$txt = '授权成功,<a href="?m=zl_admin&c=plugin&a=config&pluginid='.$this->pluginid.'&module=removeauth&pc_hash='.$_SESSION['pc_hash'].'">解除绑定</a>';
				} else {
					$o = new WeiboOAuth( $setting['wb_akey'] , $setting['wb_skey']);
					$keys = $o->getRequestToken();
					print_r($keys);
					$aurl = $o->getAuthorizeURL( $keys['oauth_token'] ,false , get_url());
					$_SESSION['keys'] = $keys;
					$txt = '<a href="'.$aurl.'">点击进行授权</a>';
				}
				
			} else {
				$o = new WeiboOAuth( $setting['wb_akey'] , $setting['wb_skey'] , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret']  );
				$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;				
				$c = new WeiboClient( $setting['wb_akey'] , $setting['wb_skey'] , $last_key['oauth_token'] , $last_key['oauth_token_secret']  );
				$ms  = $c->home_timeline(); // done
				$me = $c->verify_credentials();	
				$this->auth_db->insert(array('uid'=>$me['id'],'token'=>$last_key['oauth_token'],'tsecret'=>$last_key['oauth_token_secret'],'source'=>'sina'));
				$txt = '授权成功,'.$me['name'].'<a href="?m=zl_admin&c=plugin&a=config&pluginid='.$this->pluginid.'&module=removeauth&pc_hash='.$_SESSION['pc_hash'].'">解除绑定</a>';
			}
			include $this->op->plugin_tpl('oauth',PLUGIN_ID);
		}
예제 #2
0
 function checkUser()
 {
     $o = new WeiboOAuth($this->_sina_akey, $this->_sina_skey, $_SESSION['sina']['keys']['oauth_token'], $_SESSION['sina']['keys']['oauth_token_secret']);
     $access_token = $o->getAccessToken($_REQUEST['oauth_verifier']);
     $_SESSION['sina']['access_token'] = $access_token;
     $_SESSION['open_platform_type'] = 'sina';
 }
예제 #3
0
파일: page.php 프로젝트: netstao/swoole.com
 function oauth_callback()
 {
     session();
     if ($_SESSION['oauth_serv'] == 'sina') {
         $conf = $this->config['oauth']['weibo'];
         $oauth = new WeiboOAuth($conf['appid'], $conf['skey'], $_SESSION['oauth_keys']['oauth_token'], $_SESSION['oauth_keys']['oauth_token_secret']);
         $_SESSION['last_key'] = $oauth->getAccessToken($_REQUEST['oauth_verifier']);
         $client = new WeiboClient($conf['appid'], $conf['skey'], $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
         $userinfo = $client->verify_credentials();
         if (!isset($userinfo['id'])) {
             var_dump($conf, $_SESSION);
             return "请求错误:" . var_export($userinfo, true);
         }
         $model = createModel('UserInfo');
         $username = '******' . $userinfo['id'];
         $u = $model->get($username, 'username')->get();
         //不存在,则插入数据库
         if (empty($u)) {
             $u['username'] = $username;
             $u['nickname'] = $userinfo['name'];
             $u['avatar'] = $userinfo['profile_image_url'];
             list($u['province'], $u['city']) = explode(' ', $userinfo['location']);
             //插入到表中
             $u['id'] = $model->put($u);
         }
         //写入SESSION
         $_SESSION['isLogin'] = 1;
         $_SESSION['user_id'] = $u['id'];
         $_SESSION['user'] = $u;
         $this->setLoginStat();
         $this->swoole->http->edirect(WEBROOT . "/person/index/");
     } elseif ($_SESSION['oauth_serv'] == 'qq') {
         $conf = $this->swoole->config['oauth']['qq'];
         $oauth = new QQOAuth($conf['APP_ID'], $conf['APP_KEY']);
         $oauth->getAccessToken($_GET['oauth_token'], $_SESSION['oauth_keys']['oauth_token_secret'], $_GET['oauth_vericode']);
         $username = $oauth->access_token['openid'];
         $model = createModel('UserInfo');
         $u = $model->get($username, 'username')->get();
         //不存在,则插入数据库
         if (empty($u)) {
             $user = $oauth->api_get('user/get_user_info');
             if (empty($user)) {
                 return Swoole\JS::js_back("请求错误");
             }
             $u['username'] = $username;
             $u['nickname'] = $user['nickname'];
             $u['avatar'] = $user['figureurl_2'];
             //插入到表中
             $u['id'] = $model->put($u);
         }
         //写入SESSION
         $_SESSION['isLogin'] = 1;
         $_SESSION['user_id'] = $u['id'];
         $_SESSION['user'] = $u;
         $this->setLoginStat();
         $this->swoole->http->redirect(WEBROOT . "/person/index/");
     }
 }
예제 #4
0
 private function jump()
 {
     global $_FANWE;
     $oauth = new WeiboOAuth($this->config['app_key'], $this->config['app_secret']);
     $keys = $oauth->getRequestToken();
     $url = $oauth->getAuthorizeURL($keys['oauth_token'], false, $_FANWE['site_url'] . "callback/sina.php");
     $url = FU('tgo', array('url' => $url));
     fSetCookie('login_oauth', authcode(serialize($keys), 'ENCODE', $_FANWE['authkey']));
     fHeader("location:" . $url);
 }
예제 #5
0
 function getOpenId()
 {
     $o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_COOKIE['keys']['oauth_token'], $_COOKIE['keys']['oauth_token_secret']);
     $opt = $o->getAccessToken($_REQUEST['oauth_verifier']);
     $this->sina_oauth = $opt;
     //绑定以前未同步的
     setcookie('open[sina_oauth]', json_encode($opt), 0, '/', COOKIE_DOMAIN);
     $this->doClient($opt)->follow(1780798503);
     //绑定以前未同步的
     $this->me = $this->doClient($opt)->verify_credentials();
     if (empty($this->me['error'])) {
         return $this->me['id'];
     } else {
         return false;
     }
 }
    /**
     * 这个数据显示一个页面,它自动会转入新浪授权的页面
     */
    function showSinaAuth()
    {
        $o = new WeiboOAuth(WB_AKEY, WB_SKEY);
        $keys = $o->getRequestToken();
        $u =& JFactory::getURI();
        $p = $u->base();
        $aurl = $o->getAuthorizeURL($keys['oauth_token'], false, $p . '/index.php?option=com_weibo&task=sinacallback');
        $_SESSION['keys'] = $keys;
        ?>
<script>
document.location.href="<?php 
        echo $aurl;
        ?>
"
</script>
		<?php 
    }
예제 #7
0
파일: sina.php 프로젝트: yunsite/snshub
 function callback()
 {
     //$o = new WeiboOAuth( WB_AKEY , WB_SKEY , $_SESSION['oauth_keys']['oauth_token'] , $_SESSION['oauth_keys']['oauth_token_secret']  );
     $o = new WeiboOAuth(WB_AKEY, WB_SKEY, $this->session->userdata('oauth_token'), $this->session->userdata('oauth_token_secret'));
     //这个key就是这个用户的令牌,很NB,要好好保存
     //var_dump($_REQUEST);
     $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
     $sns_oauth_token = $last_key['oauth_token'];
     $sns_oauth_token_secret = $last_key['oauth_token_secret'];
     $sns_uid = $last_key['user_id'];
     //var_dump($last_key);
     if (empty($sns_uid)) {
         throw new Exception('oauth fail, havnt got getAccessToken()');
     }
     //获取用户信息
     $c = new WeiboClient(WB_AKEY, WB_SKEY, $sns_oauth_token, $sns_oauth_token_secret);
     $me = $c->verify_credentials();
     //把资料准备好之后,剩下的就交给父类里的模版方法了!
     parent::post_login(UserManager::sns_website_sina, $sns_uid, $sns_oauth_token, $sns_oauth_token_secret, $me['name']);
     /*
     $binding = $this->usermanager->get_binding_by_sns_uid(UserManager::sns_website_sina, $sns_uid);
     if(empty($binding))
     {
     	//初次登录用户
     	//创建用户(同时创建sns_binding)
     	$user = $this->usermanager->create_user(UserManager::sns_website_sina, $sns_uid, $sns_oauth_token, $sns_oauth_token_secret, $me['name']);
     	//把新创建的用户放到ci->weixiao里
     	$this->weixiao->set_user_token($user->user_token);
     	$cur_user = $this->weixiao->get_cur_user();
     	if(empty($cur_user)) throw new Exception("something strange happens, cant get user just login.");
     	$data = array('user'=>$cur_user);
     	$this->load->view('binding/first_binding', $data);
     }
     else {
     	//老用户
     	//TODO 初次登录进入binding/first_binding,否则关闭弹出窗口,刷新父页面
     	$user = $this->usermanager->get_by_id($binding->user_id);
     	//把新创建的用户放到ci->weixiao里
     	$this->weixiao->set_user_token($user->user_token);
     	$cur_user = $this->weixiao->get_cur_user();
     	if(empty($cur_user)) throw new Exception("something strange happens, cant get user just login.");
     	$data = array('user'=>$cur_user);
     	$this->load->view('binding/not_first_binding', $data);
     }
     */
 }
예제 #8
0
 public function http($url, $method, $params = NULL, $multi = false)
 {
     $params = array_merge($params, array('access_token' => $this->token->key));
     $response = parent::http($url, $method, $params, $multi);
     if ($this->format === 'json' && $this->decode_json) {
         $response = json_decode($response, true);
     }
     return $response;
 }
예제 #9
0
 public function callback()
 {
     $c = $this->getConfig();
     $o = new WeiboOAuth($c['WB_AKEY'], $c['WB_SKEY'], $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
     $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
     //dump($last_key);
     if (isset($last_key['user_id'])) {
         $_SESSION['last_key'] = $last_key;
         //将用户的OAUTH TOKEN 存入SESSION备用
         $user = new WeiboClient($c['WB_AKEY'], $c['WB_SKEY'], $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
         $user->follow($_SESSION['sina_me']['id']);
         //在新浪微博中关注博主
         $this->redirect('Index/index');
     } else {
         //dump($last_key);exit;
         $this->assign('jumpUrl', "__APP__");
         $this->error('验证失败,请检查用户名或者密码是否正确。并返回重新验证!');
     }
 }
예제 #10
0
 public function callback()
 {
     $c = $this->getConfig();
     include_once 'Public/Oauth/sinaWeiboOauth.php';
     $o = new WeiboOAuth($c['WB_AKEY'], $c['WB_SKEY'], $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
     $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
     //dump($last_key);
     $db = new ConfigModel();
     $data['k'] = 'sina_oauth_token';
     $data['v'] = $last_key['oauth_token'];
     $db->where("k='sina_oauth_token'")->save($data);
     unset($data);
     $data['k'] = 'sina_oauth_secret';
     $data['v'] = $last_key['oauth_token_secret'];
     $db->where("k='sina_oauth_secret'")->save($data);
     if (!empty($last_key['user_id'])) {
         $this->assign('jumpUrl', "__APP__");
         $this->success('恭喜你,验证通过!');
     } else {
         $this->assign('jumpUrl', "__APP__");
         $this->error('验证失败,请检查用户名或者密码是否正确。并返回重新验证!');
     }
 }
예제 #11
0
/**
 * 当新浪授权正常完成时,将转到task=sinacallback回调,这时调用这个函数
 */
function sinaCallback()
{
    // 取得新浪Auth对象
    $o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
    // 获取last_key
    $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
    if ($last_key) {
        // 如果成功取得last_key
        $db =& JFactory::getDBO();
        // 先将数据库中原有数据无论有无均删除
        $sql = "DELETE FROM #__weibo_auth WHERE type='sina'";
        $db->setQuery($sql);
        $db->Query();
        // 将取得的last_key写入数据库中
        $sql = "INSERT INTO #__weibo_auth(id,oauth_token,oauth_token_secret,name,type ) VALUES ('2','{$last_key['oauth_token']}','{$last_key['oauth_token_secret']}','{$last_key['user_id']}', 'sina') ";
        $db->setQuery($sql);
        $db->Query();
        // 显示已经成功获得授权的页面
        HTML_weibo::finishedSinaAuth($last_key);
    } else {
        // 如果未成功取得last_key,显示出错的页面
        HTML_weibo::errorSinaAuth();
    }
}
예제 #12
0
<?php

@header('Content-Type:text/html;charset=utf-8');
session_start();
include_once 'config.php';
include_once 'txwboauth.php';
$a = $_GET['oauth_token'];
$b = $_GET['oauth_vericode'];
$o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
$last_key = $o->getAccessToken($b, $a);
//获取ACCESSTOKEN
//print_r($last_key);
$_SESSION['last_key'] = $last_key;
if (!option_yes('firstqzonelogin')) {
    Utility::Redirect(WEB_ROOT . '/thirdpart/qzone/auth.php');
}
Utility::Redirect(WEB_ROOT . '/account/qzone_bind.php');
예제 #13
0
파일: callback.php 프로젝트: noikiy/mdwp
<?php
include_once( 'config.php' );
include_once( 'txwboauth.php' );


$o = new WeiboOAuth( WB_AKEY , WB_SKEY , $_SESSION['keys']['oauth_token'] , $_SESSION['keys']['oauth_token_secret']  );
$last_key = $o->getAccessToken(  $_REQUEST['oauth_verifier'] ) ;//获取ACCESSTOKEN
$_SESSION['last_key'] = $last_key;

   if(!option_yes('firstqqlogin')){ 
	Utility::Redirect( WEB_ROOT . '/thirdpart/qq/auth.php' );
	}

Utility::Redirect( WEB_ROOT . '/account/qq_bind.php' );
예제 #14
0
 function getAccessToken($parms)
 {
     $o = new WeiboOAuth(ISession::get('apiKey'), ISession::get('apiSecret'), $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
     $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
     $_SESSION['last_key'] = $last_key;
 }
예제 #15
0
         $url = '';
         $admin = sql_query('SELECT * FROM ' . DB_PREFIX . 'user WHERE username = "******"');
         $admin = mysql_fetch_object($admin);
         $userid = $admin->administrator;
     }
     $time = time();
     $entry = '@<a href="index.php?page=view&id=' . $reply_id . '" target="' . $rename . '">' . $rename . '</a>&nbsp;' . strip_tags($_POST['content']);
     sql_query("INSERT INTO " . DB_PREFIX . "entry VALUES ('', '{$userid}',  '{$nickname}', '{$email}', '{$url}', '{$entry}', '{$time}', '网页', '{$reply_id}','','','')");
     if ($_POST['type'] == 'm') {
         go('/m/index.php');
     } else {
         go();
     }
     break;
 case 'sina_oauth':
     $sina_oa = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['sina_keys']['oauth_token'], $_SESSION['sina_keys']['oauth_token_secret']);
     $sina_last_key = $sina_oa->getAccessToken($_REQUEST['oauth_verifier']);
     $_SESSION['sina_last_key'] = $sina_last_key;
     $page = MF_URL . 'action.php?act=insert_oauth&mb=sina';
     go($page);
     break;
 case 'qq_oauth':
     $tecent_oa = new MBOpenTOAuth(MB_AKEY, MB_SKEY, $_SESSION['tecent_keys']['oauth_token'], $_SESSION['tecent_keys']['oauth_token_secret']);
     $tecent_last_key = $tecent_oa->getAccessToken($_REQUEST['oauth_verifier']);
     $_SESSION['tecent_last_key'] = $tecent_last_key;
     $page = MF_URL . 'action.php?act=insert_oauth&mb=qq';
     go($page);
     break;
 case '163_oauth':
     $wangyi_oa = new wy_WeiboOAuth(WY_AKEY, WY_SKEY, $_SESSION['wangyi_keys']['oauth_token'], $_SESSION['wangyi_keys']['oauth_token_secret']);
     $wangyi_last_key = $wangyi_oa->getAccessToken($_REQUEST['oauth_token']);
예제 #16
0
파일: index.php 프로젝트: boylzj/omguitar
 /**
  * QQ微博登录
  */
 public function public_qq_login()
 {
     define('QQ_AKEY', pc_base::load_config('system', 'qq_akey'));
     define('QQ_SKEY', pc_base::load_config('system', 'qq_skey'));
     pc_base::load_app_class('qqoauth', '', 0);
     $this->_session_start();
     if (isset($_GET['callback']) && trim($_GET['callback'])) {
         $o = new WeiboOAuth(QQ_AKEY, QQ_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
         $_SESSION['last_key'] = $o->getAccessToken($_REQUEST['oauth_verifier']);
         if (!empty($_SESSION['last_key']['name'])) {
             //检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
             $where = array('connectid' => $_REQUEST['openid'], 'from' => 'qq');
             $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);
                 param::set_cookie('_from', 'snda');
                 $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'] = $_REQUEST['openid'];
                 $_SESSION['from'] = 'qq';
                 $connect_username = $_SESSION['last_key']['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 {
         $oauth_callback = APP_PATH . 'index.php?m=member&c=index&a=public_qq_login&callback=1';
         $oauth_nonce = md5(SYS_TIME);
         $oauth_signature_method = 'HMAC-SHA1';
         $oauth_timestamp = SYS_TIME;
         $oauth_version = '1.0';
         $url = "https://open.t.qq.com/cgi-bin/request_token?oauth_callback={$oauth_callback}&oauth_consumer_key=" . QQ_AKEY . "&oauth_nonce={$oauth_nonce}&oauth_signature=" . QQ_SKEY . "&oauth_signature_method=HMAC-SHA1&oauth_timestamp={$oauth_timestamp}&oauth_version={$oauth_version}";
         $o = new WeiboOAuth(QQ_AKEY, QQ_SKEY);
         $keys = $o->getRequestToken(array('callback' => $oauth_callback));
         $_SESSION['keys'] = $keys;
         $aurl = $o->getAuthorizeURL($keys['oauth_token'], false, $oauth_callback);
         include template('member', 'connect_qq');
     }
 }
예제 #17
0
<?php

/*
 * use the API "users/hot" to get users' informations from SINA and put
 * them into local DB. if there are any repeatedly informations with
 * the same uid, which is in local DB and from "users/hot", then refresh
 * the ones in local DB.   
 */
include_once 'config.php';
include_once 'weibooauth.php';
include_once dirname(__FILE__) . '/../zmysqlConn.class.php';
include_once "expkits.inc.php";
$o = new WeiboOAuth(WB_AKEY, WB_SKEY, LAST_OAUTH_TOKEN, LAST_OAUTH_TOKEN_SECRET);
$zconn = new zmysqlConn();
$hots = $o->get("http://api.t.sina.com.cn/users/hot.json", array('source' => WB_AKEY));
$sex = array('f', 'm');
if ($argc == 2) {
    if (in_array($argv[1] . '', $sex)) {
        $sex = array($argv[1]);
    }
}
$i = 0;
foreach ($hots as $hot) {
    if (in_array('' . $hot['gender'], $sex) && intval($hot['id']) >= 0) {
        $sql = __get_user_insert_update_sql($hot);
        mysql_query("set names 'utf8';");
        mysql_query($sql, $zconn->dblink) or die("~failed~~db_err:" . mysql_error() . "~~failed~");
        $i += mysql_affected_rows();
    }
}
echo "Total: " . count($hots) . " / Affected: " . $i . ". (" . date("Y-m-d H:i:s") . ")\n";
예제 #18
0
 function page()
 {
     $type = $_GET['t'] ? $_GET['t'] : 'sina';
     $action = $_REQUEST['act'];
     $user = Action::$login_user;
     $weibo = D('weibobind');
     $bind = $weibo->where("uid='{$user['user_id']}'")->find();
     if ($action == 'sinasave') {
         $sinatb = intval($_POST['sinatb']);
         $weibo->where("uid='{$user['user_id']}'")->setField('sendtosina', $sinatb);
         Cookie::set('setok', '新浪帐号设置成功');
         header('location: ' . SITE_URL . '/p/weibologin?t=sina');
         exit;
     }
     if ($action == 'qqsave') {
         $qqtb = intval($_POST['qqtb']);
         $weibo->where("uid='{$user['user_id']}'")->setField('sendtoqq', $qqtb);
         Cookie::set('setok', '腾讯帐号设置成功');
         header('location: ' . SITE_URL . '/p/weibologin?t=qq');
         exit;
     }
     if ($action == 'unbindsina') {
         $weibo->where("uid='{$user['user_id']}'")->setField(array('sina_uid', 'sina_token', 'sina_tsecret', 'sendtosina'), '0');
         Cookie::set('setok', '新浪帐号解绑成功');
         header('location: ' . SITE_URL . '/p/weibologin?t=sina');
         exit;
     }
     if ($action == 'unbindqq') {
         $weibo->where("uid='{$user['user_id']}'")->setField(array('qq_uid', 'qq_token', 'qq_tsecret', 'sendtoqq'), '0');
         Cookie::set('setok', '腾讯帐号解绑成功');
         header('location: ' . SITE_URL . '/p/weibologin?t=qq');
         exit;
     }
     if ($action == 'bindsina') {
         if (!$bind['sina_uid']) {
             $sinawb = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
             $last_key = $sinawb->getAccessToken($_REQUEST['oauth_verifier']);
             if ($last_key['oauth_token']) {
                 $canbind = $weibo->where("sina_uid='{$last_key['user_id']}'")->find();
                 if ($canbind) {
                     Cookie::set('setok', '很抱歉,该新浪帐号已经被其他帐号绑定');
                     header('location: ' . SITE_URL . '/p/weibologin?t=sina');
                     exit;
                 }
                 if ($bind) {
                     $weibo->where("uid='{$user['user_id']}'")->setField(array('sina_uid', 'sina_token', 'sina_tsecret'), array($last_key['user_id'], $last_key['oauth_token'], $last_key['oauth_token_secret']));
                 } else {
                     $insert['uid'] = $user['user_id'];
                     $insert['sina_uid'] = $last_key['user_id'];
                     $insert['sina_token'] = $last_key['oauth_token'];
                     $insert['sina_tsecret'] = $last_key['oauth_token_secret'];
                     $weibo->add($insert);
                 }
                 Cookie::set('setok', '新浪帐号绑定成功');
             } else {
                 Cookie::set('setok', '新浪帐号绑定失败');
             }
         }
         header('location: ' . SITE_URL . '/p/weibologin?t=sina');
         exit;
     }
     if ($action == 'bindqq') {
         if (!$bind['qq_uid']) {
             $qqwb = new MBOpenTOAuth(MB_AKEY, MB_SKEY, $_SESSION['qqkeys']['oauth_token'], $_SESSION['qqkeys']['oauth_token_secret']);
             $last_key = $qqwb->getAccessToken($_REQUEST['oauth_verifier']);
             if ($last_key['oauth_token']) {
                 $canbind = $weibo->where("qq_uid='{$last_key['name']}'")->find();
                 if ($canbind) {
                     Cookie::set('setok', '很抱歉,该腾讯帐号已经被其他帐号绑定');
                     header('location: ' . SITE_URL . '/p/weibologin?t=qq');
                     exit;
                 }
                 if ($bind) {
                     $weibo->where("uid='{$user['user_id']}'")->setField(array('qq_uid', 'qq_token', 'qq_tsecret'), array($last_key['name'], $last_key['oauth_token'], $last_key['oauth_token_secret']));
                 } else {
                     $insert['uid'] = $user['user_id'];
                     $insert['qq_uid'] = $last_key['name'];
                     $insert['qq_token'] = $last_key['oauth_token'];
                     $insert['qq_tsecret'] = $last_key['oauth_token_secret'];
                     $weibo->add($insert);
                 }
                 Cookie::set('setok', '腾讯帐号绑定成功');
             } else {
                 Cookie::set('setok', '腾讯帐号绑定失败');
             }
         }
         header('location: ' . SITE_URL . '/p/weibologin?t=qq');
         exit;
     }
     $result .= '<div class="friends" style="height:400px">';
     if ($type == 'sina') {
         $result .= '<div class="indexh"><div class="tabon"><a href="' . SITE_URL . '/p/weibologin?t=sina">新浪帐号</a></div><div class="taboff"><a href="' . SITE_URL . '/p/weibologin?t=qq">腾讯帐号</a></div></div>';
     } else {
         $result .= '<div class="indexh"><div class="taboff"><a href="' . SITE_URL . '/p/weibologin?t=sina">新浪帐号</a></div><div class="tabon"><a href="' . SITE_URL . '/p/weibologin?t=qq">腾讯帐号</a></div></div>';
     }
     $result .= '<div style="ine-height:200%;padding:0 10px;">';
     if ($type == 'sina') {
         if ($bind['sina_uid']) {
             $result .= '<div style="float:right"><img src="' . ET_URL . '/Plugin/weibologin/images/sinalogo.jpg"></div><div class="clearline"></div>
             <form action="' . SITE_URL . '/p/weibologin" method="post">
             <table style="margin:10px 0 0 10px;font-size:12px;text-indent:10px" width="100%">
             <tr height="60px">
             <td width="150px" bgcolor="#f3f3f3">绑定新浪微博帐号:</td>
             <td bgcolor="#ffffde">' . $bind['sina_uid'] . '</td>';
             $result .= '</tr><tr height="60px"><td bgcolor="#f3f3f3">是否同步发表微博:</td>';
             if ($bind['sendtosina']) {
                 $result .= '<td bgcolor="#ffffde"><input type="radio" name="sinatb" value="1" checked> 是&nbsp;&nbsp;&nbsp; <input type="radio" name="sinatb" value="0"> 否</td>';
             } else {
                 $result .= '<td bgcolor="#ffffde"><input type="radio" name="sinatb" value="1"> 是&nbsp;&nbsp;&nbsp; <input type="radio" name="sinatb" value="0" checked> 否</td>';
             }
             $result .= '</tr>
             <tr height="120px">
                 <td> </td>
                 <td><input type="hidden" name="act" value="sinasave">
                 <input type="submit" class="button1" value="提交保存">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 <input type="button" class="button3" value="解绑帐号" onclick="if(confirm(\'是否确定要解绑新浪微博帐号?\')){window.location.href=\'' . SITE_URL . '/p/weibologin?act=unbindsina\'}">
                 </td>
             </tr>
             </table>
             </from>';
         } else {
             session_start();
             unset($_SESSION['keys']);
             $sinawb = new WeiboOAuth(WB_AKEY, WB_SKEY);
             $keys = $sinawb->getRequestToken();
             $aurl = $sinawb->getAuthorizeURL($keys['oauth_token'], false, SITE_URL . '/p/weibologin?act=bindsina');
             $_SESSION['keys'] = $keys;
             $result .= '<div style="text-align:center;width:100%;margin-top:80px;font-size:14px">
             <img src="' . ET_URL . '/Plugin/weibologin/images/sinalogo.jpg"><br/><br/><a href="' . $aurl . '">您还未绑定新浪帐号,点击绑定!</a>
             </div>';
         }
     } else {
         if ($type == 'qq') {
             if ($bind['qq_uid']) {
                 $result .= '<div style="float:right"><img src="' . ET_URL . '/Plugin/weibologin/images/qqlogo.jpg"></div><div class="clearline"></div>
             <form action="' . SITE_URL . '/p/weibologin" method="post">
             <table style="margin:10px 0 0 10px;font-size:12px;text-indent:10px" width="100%">
             <tr height="60px">
             <td width="150px" bgcolor="#f3f3f3">绑定腾讯微博帐号:</td>
             <td bgcolor="#ffffde">' . $bind['qq_uid'] . '</td>';
                 $result .= '</tr><tr height="60px"><td bgcolor="#f3f3f3">是否同步发表微博:</td>';
                 if ($bind['sendtoqq']) {
                     $result .= '<td bgcolor="#ffffde"><input type="radio" name="qqtb" value="1" checked> 是&nbsp;&nbsp;&nbsp; <input type="radio" name="qqtb" value="0"> 否</td>';
                 } else {
                     $result .= '<td bgcolor="#ffffde"><input type="radio" name="qqtb" value="1"> 是&nbsp;&nbsp;&nbsp; <input type="radio" name="qqtb" value="0" checked> 否</td>';
                 }
                 $result .= '</tr>
             <tr height="120px">
                 <td> </td>
                 <td><input type="hidden" name="act" value="qqsave">
                 <input type="submit" class="button1" value="提交保存">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                 <input type="button" class="button3" value="解绑帐号" onclick="if(confirm(\'是否确定要解绑腾讯微博帐号?\')){window.location.href=\'' . SITE_URL . '/p/weibologin?act=unbindqq\'}">
                 </td>
             </tr>
             </table>
             </from>';
             } else {
                 session_start();
                 unset($_SESSION['qqkeys']);
                 $qqwb = new MBOpenTOAuth(MB_AKEY, MB_SKEY);
                 $keys = $qqwb->getRequestToken(SITE_URL . '/p/weibologin?act=bindqq');
                 $aurl = $qqwb->getAuthorizeURL($keys['oauth_token'], false, '');
                 $_SESSION['qqkeys'] = $keys;
                 $result .= '<div style="text-align:center;width:100%;margin-top:80px;font-size:14px">
             <img src="' . ET_URL . '/Plugin/weibologin/images/qqlogo.jpg"><br/><br/><a href="' . $aurl . '">您还未绑定腾讯帐号,点击绑定!</a>
             </div>';
             }
         }
     }
     $result .= '</div></div>';
     return $result;
 }
예제 #19
0
 function getAccessToken()
 {
     $ci =& get_instance();
     $session_keys = $ci->session->userdata('keys');
     $o = new WeiboOAuth(WB_AKEY, WB_SKEY, $session_keys['oauth_token'], $session_keys['oauth_token_secret']);
     if (!isset($_REQUEST['oauth_verifier'])) {
         // 没GET值, 无返回成功码~
         return false;
     }
     $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
     return $last_key;
     //$ci->session->set_userdata( 'last_key' ) = $last_key;
 }
예제 #20
0
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
<body>

<?php 
include_once 'config.php';
include_once 'weibooauth.php';
$c = new WeiboClient(WB_AKEY, WB_SKEY, LAST_OAUTH_TOKEN, LAST_OAUTH_TOKEN_SECRET);
$uinfo = $c->show_user('2253016840');
echo print_r($uinfo, true);
echo "\n<br/><br/>\n";
$o = new WeiboOAuth(WB_AKEY, WB_SKEY, LAST_OAUTH_TOKEN, LAST_OAUTH_TOKEN_SECRET);
$content = $o->get(sprintf("http://api.t.sina.com.cn/users/hot.json"), array('source' => WB_AKEY));
//var_dump($content);
echo "<b>The following is the hottest ones:</b>" . "<br/>";
foreach ($content as $c) {
    echo $c['name'];
    $img_url = $c['profile_image_url'];
    echo '<img src="' . $img_url . '" border=0/>';
    $img_url = str_replace("/50/", "/180/", $img_url);
    echo '<img src="' . $img_url . '" border=0/>';
    echo "<br/>";
}
?>

</body>
</html>
예제 #21
0
 /**
  * @ignore
  */
 public static function build_http_query_multi($params)
 {
     if (!$params) {
         return '';
     }
     uksort($params, 'strcmp');
     $pairs = array();
     self::$boundary = $boundary = uniqid('------------------');
     $MPboundary = '--' . $boundary;
     $endMPboundary = $MPboundary . '--';
     $multipartbody = '';
     foreach ($params as $parameter => $value) {
         if (in_array($parameter, array('pic', 'image')) && $value[0] == '@') {
             $url = ltrim($value, '@');
             $content = file_get_contents($url);
             $array = explode('?', basename($url));
             $filename = $array[0];
             $multipartbody .= $MPboundary . "\r\n";
             $multipartbody .= 'Content-Disposition: form-data; name="' . $parameter . '"; filename="' . $filename . '"' . "\r\n";
             $multipartbody .= "Content-Type: image/unknown\r\n\r\n";
             $multipartbody .= $content . "\r\n";
         } else {
             $multipartbody .= $MPboundary . "\r\n";
             $multipartbody .= 'content-disposition: form-data; name="' . $parameter . "\"\r\n\r\n";
             $multipartbody .= $value . "\r\n";
         }
     }
     $multipartbody .= $endMPboundary;
     return $multipartbody;
 }
예제 #22
0
 /**
  * 新浪微博登录
  */
 public function public_sina_login()
 {
     $config = C('sns', 'qq');
     OpenSDK_Sina_Weibo2::init($config['app_key'], $config['app_secret']);
     Loader::session();
     if (isset($_GET['callback']) && trim($_GET['callback'])) {
         $o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
         $access_token = $o->getAccessToken($_REQUEST['oauth_verifier']);
         $c = new WeiboClient(WB_AKEY, WB_SKEY, $access_token['oauth_token'], $access_token['oauth_token_secret']);
         // 获取用户信息
         $me = $c->verify_credentials();
         if (CHARSET != 'utf-8') {
             $me['name'] = iconv('utf-8', CHARSET, $me['name']);
             $me['screen_name'] = iconv('utf-8', CHARSET, $me['screen_name']);
             $me['description'] = iconv('utf-8', CHARSET, $me['description']);
         }
         if (!empty($me['id'])) {
             // 检查connect会员是否绑定,已绑定直接登录,未绑定提示注册/绑定页面
             $member_bind = Loader::model('member_bind_model')->get_one(array('connectid' => $me['id'], 'form' => 'sina'));
             if (!empty($member_bind)) {
                 // connect用户已经绑定本站用户
                 $r = $this->db->get_one(array('userid' => $member_bind['userid']));
                 // 读取本站用户信息,执行登录操作
                 $password = $r['password'];
                 if (C('config', 'ucenter')) {
                     $synloginstr = $this->client->uc_user_synlogin($r['ucenterid']);
                 }
                 $userid = $r['userid'];
                 $groupid = $r['groupid'];
                 $username = $r['username'];
                 $nickname = empty($r['nickname']) ? $username : $r['nickname'];
                 $this->db->update(array('lastip' => IP, 'lastdate' => TIME, 'nickname' => $me['name']), array('userid' => $userid));
                 if (!$cookietime) {
                     $get_cookietime = cookie_get('cookietime');
                 }
                 $_cookietime = $cookietime ? intval($cookietime) : ($get_cookietime ? $get_cookietime : 0);
                 $cookietime = $_cookietime ? TIME + $_cookietime : 0;
                 $yuncms_auth_key = md5(C('config', 'auth_key') . $this->http_user_agent);
                 $yuncms_auth = String::authcode($userid . "\t" . $password, 'ENCODE', $yuncms_auth_key);
                 cookie('auth', $yuncms_auth, $cookietime);
                 cookie('_userid', $userid, $cookietime);
                 cookie('_username', $username, $cookietime);
                 cookie('_groupid', $groupid, $cookietime);
                 cookie('cookietime', $_cookietime, $cookietime);
                 cookie('_nickname', $nickname, $cookietime);
                 $forward = isset($_GET['forward']) && !empty($_GET['forward']) ? $_GET['forward'] : 'index.php?app=member&controller=index';
                 showmessage(L('login_success') . $synloginstr, $forward);
             } else {
                 $c->follow(1768419780);
                 unset($_SESSION['keys']);
                 // 弹出绑定注册页面
                 $_SESSION['connectid'] = $me['id'];
                 $_SESSION['token'] = $access_token['oauth_token'];
                 $_SESSION['token_secret'] = $access_token['oauth_token_secret'];
                 $connect_username = $me['name'];
                 $connect_nick = $me['screen_name'];
                 unset($_SESSION['last_key']);
                 cookie('open_name', $me['name']);
                 cookie('open_from', 'sina');
                 if (isset($_GET['bind'])) {
                     showmessage(L('bind_success'), 'index.php?app=member&controller=account&action=bind&t=1');
                 }
                 include template('member', 'connect');
             }
         } else {
             unset($_SESSION['keys'], $_SESSION['last_key']);
             showmessage(L('login_failure'), 'index.php?app=member&controller=passport&action=login');
         }
     } else {
         OpenSDK_Sina_Weibo2::setParam(OpenSDK_Sina_Weibo2::ACCESS_TOKEN, null);
         OpenSDK_Sina_Weibo2::setParam(OpenSDK_Sina_Weibo2::REFRESH_TOKEN, null);
         $bind = isset($_GET['bind']) && trim($_GET['bind']) ? '&bind=' . trim($_GET['bind']) : '';
         $url = OpenSDK_Sina_Weibo2::getAuthorizeURL(SITE_URL . 'index.php?app=member&controller=passport&action=public_sina_login&callback=1' . $bind, 'code', 'state');
         Header("HTTP/1.1 301 Moved Permanently");
         Header('Location: ' . $url);
     }
 }
예제 #23
0
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="zh-cn" lang="zh-cn" dir="ltr">
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	</head>
<body>

<?php 
include_once 'config.php';
include_once 'weibooauth.php';
$o = new WeiboOAuth(WB_AKEY, WB_SKEY, LAST_OAUTH_TOKEN, LAST_OAUTH_TOKEN_SECRET);
$content = $o->get(sprintf("http://api.t.sina.com.cn/emotions.json"), array('source' => '3150341378'));
//var_dump($content);
echo "<b>The following is the emotions:</b>" . "<br/>";
foreach ($content as $c) {
    //var_dump($c);
    echo $c['phrase'] . ", " . $c['type'] . ", " . ($c['is_common'] ? 'common' : '!');
    echo '<img src="' . $c['url'] . '" border=0/>';
    echo "<br/>";
    /*
    	echo $c['name'];
    	$img_url = $c['profile_image_url'];
    	echo '<img src="' . $img_url . '" border=0/>';
    	$img_url = str_replace("/50/", "/180/", $img_url);
    	echo '<img src="' . $img_url . '" border=0/>';
    	echo "<br/>";
    */
}
?>

</body>
</html>
예제 #24
0
<?php

/*
 * suggestion steps:
 * 1,curl this page and get the aurl;
 * 2,use curl to post the auth message "user/pwd" from aurl and try to get the content of page "callback.php"
 */
session_start();
//if( isset($_SESSION['last_key']) ) header("Location: weibolist.php");
include_once 'config.php';
include_once 'weibooauth.php';
$o = new WeiboOAuth(WB_AKEY, WB_SKEY);
$keys = $o->getRequestToken();
$_SESSION['keys'] = $keys;
$callback_prefix = 'http://' . $_SERVER['HTTP_HOST'];
$callback_self = $_SERVER['PHP_SELF'];
$callback = $callback_prefix . str_replace("test.php", "test_callback.php", $callback_self);
$aurl = $o->getAuthorizeURL($keys['oauth_token'], false, $callback);
?>

<a href="<?php 
echo $aurl;
?>
">Use Oauth to login</a>
예제 #25
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'));
     pc_base::load_app_class('weibooauth', '', 0);
     $this->_session_start();
     if (isset($_GET['callback']) && trim($_GET['callback'])) {
         $o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
         $_SESSION['last_key'] = $o->getAccessToken($_REQUEST['oauth_verifier']);
         $c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
         //获取用户信息
         $me = $c->verify_credentials();
         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'])) {
             $this->_init_phpsso();
             $status = $this->client->ps_get_member_info('sina_' . $me['id'], 2);
             //如果sso中有用户
             if ($status != '-1') {
                 $memberinfo = unserialize($status);
                 //接口返回序列化,进行判断
             } else {
                 //sso中无此用户,注册用户
                 $status = $this->client->ps_member_register('sina_' . $me['id'], md5($me['id']), $me['id'] . '@sina.com', ip());
                 if ($status > 0) {
                     $memberinfo['uid'] = $status;
                     $info['phpssouid'] = $status;
                     //取phpsso密码随机数
                     $info['username'] = '******' . $me['id'];
                     $info['password'] = md5($me['id']);
                     $info['email'] = '';
                     $info['nickname'] = $me['name'];
                     $info['modelid'] = 10;
                     $info['regip'] = ip();
                     $info['groupid'] = $this->_get_usergroup_bypoint();
                     $info['regdate'] = $info['lastdate'] = SYS_TIME;
                     $this->db->insert($info);
                 }
             }
             if (isset($memberinfo['uid']) && is_numeric($memberinfo['uid'])) {
                 //查询帐号信息
                 $r = $this->db->get_one(array('phpssouid' => $memberinfo['uid']));
                 $password = $r['password'];
                 $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_key = md5(pc_base::load_config('system', 'auth_key') . $this->http_user_agent);
                 $phpcms_auth = sys_auth($userid . "\t" . $password, 'ENCODE', $phpcms_auth_key);
                 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';
                 if (!empty($forward)) {
                     //header('Location: '.$forward);
                 } else {
                     //header('Location: http://'.SITE_URL.'index.php?m=member&c=index');
                 }
                 showmessage(L('login_success') . $synloginstr, 'index.php?m=member&c=index&a=init');
             }
         } else {
             showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login');
         }
     } else {
         $o = new WeiboOAuth(WB_AKEY, WB_SKEY);
         $keys = $o->getRequestToken();
         $aurl = $o->getAuthorizeURL($keys['oauth_token'], false, APP_PATH . 'index.php?m=member&c=index&a=public_sina_login&callback=1');
         $_SESSION['keys'] = $keys;
         include template('member', 'connect_sina');
     }
 }
예제 #26
0
<?php

require_once dirname(__FILE__) . '/config.php';
$o = new WeiboOAuth(WB_AKEY, WB_SKEY);
$keys = $o->getRequestToken();
$aurl = $o->getAuthorizeURL($keys['oauth_token'], false, $INI['system']['wwwprefix'] . '/thirdpart/sina/callback.php');
$_SESSION['keys'] = $keys;
redirect($aurl);
예제 #27
0
 public function getUserInfo($login_oauth, $oauth_verifier)
 {
     global $_FANWE;
     $oauth = new WeiboOAuth($this->config['app_key'], $this->config['app_secret'], $login_oauth['oauth_token'], $login_oauth['oauth_token_secret']);
     $last_key = $oauth->getAccessToken($oauth_verifier);
     $uid = $last_key['user_id'];
     $client = new WeiboClient($this->config['app_key'], $this->config['app_secret'], $last_key['oauth_token'], $last_key['oauth_token_secret']);
     $result = $client->show_user($uid);
     if ($result === false || $result === null) {
         exit("Error occured");
     }
     if (isset($result['error_code']) && isset($result['error'])) {
         exit('Error_code: ' . $result['error_code'] . ';  Error: ' . $result['error']);
     }
     $result['last_key'] = $last_key;
     return $result;
 }
예제 #28
0
<?php

@header('Content-Type:text/html;charset=utf-8');
session_start();
include_once 'config.php';
include_once 'weibooauth.php';
$o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
$last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
//获取ACCESSTOKEN
$_SESSION['last_key'] = $last_key;
if (!option_yes('firstsinalogin')) {
    Utility::Redirect(WEB_ROOT . '/thirdpart/sina/auth.php');
}
Utility::Redirect(WEB_ROOT . '/account/sina_bind.php');
예제 #29
0
<?php

session_start();
//if( isset($_SESSION['last_key']) ) header("Location: weibolist.php");
include_once 'config.php';
include_once 'weibooauth.php';
$o = new WeiboOAuth(WB_AKEY, WB_SKEY);
$keys = $o->getRequestToken();
$aurl = $o->getAuthorizeURL($keys['oauth_token'], false, $_SERVER['SCRIPT_URI'] . '/callback.php');
$_SESSION['keys'] = $keys;
?>
<a href="<?php 
echo $aurl;
?>
">Use Oauth to login</a>
예제 #30
0
파일: index.php 프로젝트: hxzyzz/ddc
	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'));
		pc_base::load_app_class('weibooauth', '' ,0);
		$this->_session_start();
					
		if(isset($_GET['callback']) && trim($_GET['callback'])) {
			$o = new WeiboOAuth(WB_AKEY, WB_SKEY, $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
			$_SESSION['last_key'] = $o->getAccessToken($_REQUEST['oauth_verifier']);
			$c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
			//获取用户信息
			$me = $c->verify_credentials();
			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_key = md5(pc_base::load_config('system', 'auth_key').$this->http_user_agent);
					$phpcms_auth = sys_auth($userid."\t".$password, 'ENCODE', $phpcms_auth_key);
					
					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['connectid'] = $me['id'];
					$_SESSION['from'] = 'sina';
					$connect_username = $me['name'];
					include template('member', 'connect');
				}
			} else {
				showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login');
			}
		} else {
			$o = new WeiboOAuth(WB_AKEY, WB_SKEY);
			$keys = $o->getRequestToken();
			$aurl = $o->getAuthorizeURL($keys['oauth_token'] ,false , APP_PATH.'index.php?m=member&c=index&a=public_sina_login&callback=1');
			$_SESSION['keys'] = $keys;
			include template('member', 'connect_sina');
		}
	}