function sina_get_credentials()
{
    include_once 'sinaoauth.inc.php';
    $c = new WeiboClient(SINA_AKEY, SINA_SKEY, $GLOBALS['user']['sinakey']['oauth_token'], $GLOBALS['user']['sinakey']['oauth_token_secret']);
    $me = $c->verify_credentials();
    return $me;
}
		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);
		}
Exemple #3
0
 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/");
     }
 }
Exemple #4
0
 function getUserInfo()
 {
     $c = new WeiboClient(ISession::get('apiKey'), ISession::get('apiSecret'), $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
     $ms = $c->home_timeline();
     $me = $c->verify_credentials();
     $userInfo = array();
     $userInfo['id'] = isset($me['id']) ? $me['id'] : '';
     $userInfo['name'] = isset($me['name']) ? $me['name'] : '';
     return $userInfo;
 }
Exemple #5
0
 /**
  * 
  * 网站的首页
  */
 public function index()
 {
     if ($this->weixiao->is_login()) {
         $data = array('user' => $this->weixiao->get_cur_user());
         //获得所有绑定的数据
         $bindings = $this->usermanager->get_binding_by_uid($this->weixiao->get_cur_user()->id);
         foreach ($bindings as $binding) {
             switch ($binding->sns_website) {
                 case UserManager::sns_website_sina:
                     $data['binding_sina'] = $binding;
                     //读sina的数据
                     $c = new WeiboClient(WB_AKEY, WB_SKEY, $binding->sns_oauth_token, $binding->sns_oauth_token_secret);
                     $me = $c->verify_credentials();
                     $data['sina'] = $me;
                     $friends = $c->friends_ids(null, 5000, $binding->sns_uid);
                     $data['friends_sina'] = $friends['ids'];
                     break;
                 case UserManager::sns_website_qq:
                     $data['binding_qq'] = $binding;
                     //读qq的数据
                     $qq = new QqConnect();
                     $me = $qq->get_user_info(QQ_APPID, QQ_APPKEY, $binding->sns_oauth_token, $binding->sns_oauth_token_secret, $binding->sns_uid);
                     $data['qq'] = $me;
                     break;
                 case UserManager::sns_website_tqq:
                     $data['binding_tqq'] = $binding;
                     //读t.qq的数据
                     $c = $this->snsfactory->getMBApiClient(MB_AKEY, MB_SKEY, $binding->sns_oauth_token, $binding->sns_oauth_token_secret);
                     //						$c = new MBApiClient( MB_AKEY , MB_SKEY , $binding->sns_oauth_token , $binding->sns_oauth_token_secret);
                     $me = $c->getUserInfo();
                     $me = $me['data'];
                     $data['tqq'] = $me;
                     $friends = $c->getMyfans(array('num' => 30, 'start' => 0, 'type' => 1, 'n' => ''));
                     $data['friends_tqq'] = $friends['data']['info'];
                     break;
                 case UserManager::sns_website_renren:
                     $data['binding_renren'] = $binding;
                     //读renren的数据
                     $renren = new RenrenConnect();
                     $me = $renren->get_user_info(RENREN_APPKEY, RENREN_APPSECRET, $binding->sns_oauth_token, $binding->sns_uid);
                     $data['renren'] = $me[0];
                     $friends = $renren->get_friends(RENREN_APPKEY, RENREN_APPSECRET, $binding->sns_oauth_token);
                     $data['friends_renren'] = $friends;
                     break;
             }
         }
         $this->load->view('index_login', $data);
     } else {
         $this->load->view('index_not_login');
     }
     //$this->load->view('main_view',  array('users'=>$this->db->get('users')));
 }
Exemple #6
0
 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);
     }
     */
 }
Exemple #7
0
 protected function getUserzeSinaInfo()
 {
     if ($_SESSION['last_key'] === false || $_SESSION['last_key'] === null) {
         return false;
         exit;
     }
     $c = $this->getConfig();
     include_once 'Public/Oauth/sinaWeiboOauth.php';
     $o = new WeiboClient($c['WB_AKEY'], $c['WB_SKEY'], $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
     $user_info = $o->verify_credentials();
     //dump($user_info);
     if (isset($user_info['id'])) {
         $_SESSION['sina'] = $user_info;
     } else {
         unset($_SESSION['sina']);
         unset($_SESSION['last_key']);
     }
     //dump($_SESSION['sina']);
 }
<?php

session_start();
include_once 'config.php';
include_once 'weibooauth.php';
$c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
$ms = $c->home_timeline();
// done
$me = $c->verify_credentials();
?>
<h2><?php 
echo $me['name'];
?>
 你好~ 要换头像么?</h2>
<form action="weibolist.php" >
<input type="text" name="avatar" style="width:300px" value="头像url" />
&nbsp;<input type="submit" />
</form>
<h2>发送新微博</h2>
<form action="weibolist.php" >
<input type="text" name="text" style="width:300px" />
&nbsp;<input type="submit" />
</form>

<h2>发送图片微博</h2>
<form action="weibolist.php" >
<input type="text" name="text" style="width:300px" value="文字内容" />
<input type="text" name="pic" style="width:300px" value="图片url" />
&nbsp;<input type="submit" />
</form>
<?php 
 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 = array();
                 $_SESSION['connectid'] = $me['id'];
                 $_SESSION['from'] = 'sina';
                 $connect_username = $me['name'];
                 //加载用户模块配置
                 $member_setting = getcache('member_setting');
                 if (!$member_setting['allowregister']) {
                     showmessage(L('deny_register'), 'index.php?m=member&c=index&a=login');
                 }
                 //获取用户siteid
                 $siteid = isset($_REQUEST['siteid']) && trim($_REQUEST['siteid']) ? intval($_REQUEST['siteid']) : 1;
                 //过滤非当前站点会员模型
                 $modellist = getcache('member_model', 'commons');
                 foreach ($modellist as $k => $v) {
                     if ($v['siteid'] != $siteid || $v['disabled']) {
                         unset($modellist[$k]);
                     }
                 }
                 if (empty($modellist)) {
                     showmessage(L('site_have_no_model') . L('deny_register'), HTTP_REFERER);
                 }
                 $modelid = 10;
                 //设定默认值
                 if (array_key_exists($modelid, $modellist)) {
                     //获取会员模型表单
                     require CACHE_MODEL_PATH . 'member_form.class.php';
                     $member_form = new member_form($modelid);
                     $this->db->set_model($modelid);
                     $forminfos = $forminfos_arr = $member_form->get();
                     //万能字段过滤
                     foreach ($forminfos as $field => $info) {
                         if ($info['isomnipotent']) {
                             unset($forminfos[$field]);
                         } else {
                             if ($info['formtype'] == 'omnipotent') {
                                 foreach ($forminfos_arr as $_fm => $_fm_value) {
                                     if ($_fm_value['isomnipotent']) {
                                         $info['form'] = str_replace('{' . $_fm . '}', $_fm_value['form'], $info['form']);
                                     }
                                 }
                                 $forminfos[$field]['form'] = $info['form'];
                             }
                         }
                     }
                     $formValidator = $member_form->formValidator;
                 }
                 include template('member', 'connect');
             }
         } else {
             showmessage(L('login_failure'), 'index.php?m=member&c=index&a=login');
         }
     } else {
         $o = new 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');
     }
 }
Exemple #10
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);
     }
 }
Exemple #11
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'])) {
				//检查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');
		}
	}
Exemple #12
0
 function sendtalk()
 {
     $weibo = D('Weibobind');
     $ctent = D('Content');
     $user = Action::$login_user;
     $contentid = mysql_insert_id();
     if ($contentid) {
         $content = $ctent->where("content_id='{$contentid}'")->find();
         $text = $content['content_body'];
         $media = $content['media_body'];
         $text = str_replace('&amp;', '&', $text);
         $text = ubbreplace($text);
         $media = ubbreplace($content['media_body']);
         $st = getsubstr($media, 0, 7, false);
         if ($st == 'http://' || $st == '/photo/') {
             if ($st == '/photo/') {
                 $media = __PUBLIC__ . '/attachments' . $media;
                 $media = str_replace('s_', '', $media);
             }
             $text = $text . $media;
         }
         $text = clean_html($text);
     }
     if ($text) {
         $bind = $weibo->where("uid='{$user['user_id']}'")->find();
         if ($bind['sina_uid'] && $bind['sina_token'] && $bind['sina_tsecret'] && $bind['sendtosina'] == 1) {
             $sinawb = new WeiboClient(WB_AKEY, WB_SKEY, $bind['sina_token'], $bind['sina_tsecret']);
             $me = $sinawb->verify_credentials();
             if ($me['id'] == $bind['sina_uid']) {
                 $rssina = $sinawb->update($text);
             }
         }
         if ($bind['qq_uid'] && $bind['qq_token'] && $bind['qq_tsecret'] && $bind['sendtoqq'] == 1) {
             include_once "qqweibo/api_client.php";
             $qqwb = new MBApiClient(MB_AKEY, MB_SKEY, $bind['qq_token'], $bind['qq_tsecret']);
             $me = $qqwb->getUserInfo();
             if ($me['data']['name'] == $bind['qq_uid']) {
                 $p = array('c' => $text, 'ip' => $_SERVER['REMOTE_ADDR'], 'j' => '', 'w' => '');
                 $rsqq = $qqwb->postOne($p);
             }
         }
     }
 }
Exemple #13
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');
     }
 }
 public function opscallback()
 {
     if (isset($_REQUEST['oauth_verifier'])) {
         //var_dump($_SESSION["app_key"]);
         $o = new WeiboOAuth($_SESSION['app_key'], $_SESSION['app_secret'], $_SESSION['keys']['oauth_token'], $_SESSION['keys']['oauth_token_secret']);
         //$o = new WeiboOAuth('11111','11111',$_SESSION['keys']['oauth_token'],$_SESSION['keys']['oauth_token_secret']);
         $last_key = $o->getAccessToken($_REQUEST['oauth_verifier']);
         if (empty($last_key['error_code'])) {
             //var_dump($last_key);
             $c = new WeiboClient($_SESSION['app_key'], $_SESSION['app_secret'], $last_key['oauth_token'], $last_key['oauth_token_secret']);
             //var_dump($c);
             $ms = $c->home_timeline();
             // done
             $me = $c->verify_credentials();
             //var_dump($me);
             $ot_info = array('operator_id' => 0, 'email' => $me['name'], 'account' => $me['id'], 'oauth_token' => $last_key['oauth_token'], 'oauth_token_secret' => $last_key['oauth_token_secret'], 'type' => 'weibo_op');
             $ever_list = $this->SynchroOperator->find('first', array('conditions' => array('SynchroOperator.account' => $me['id'], 'SynchroOperator.type' => 'weibo_op')));
             if (empty($ever_list)) {
                 $this->SynchroOperator->deleteAll(array('SynchroOperator.type' => 'weibo_op'));
                 $this->SynchroOperator->save($ot_info);
             } else {
                 $this->SynchroOperator->updateAll(array('SynchroOperator.oauth_token' => $last_key['oauth_token'], 'SynchroOperator.oauth_token_secret'), array('SynchroOperator.account' => $me['id']));
             }
             $app_foo = $this->Application->find('first', array('conditions' => array('Application.code' => 'APP-WEIBO'), 'fields' => array('Application.id')), false);
             $this->redirect('/applications/view/' . $app_foo['Application']['id']);
         }
     }
     $msg = $this->ld['sina_interface_abnormal'];
     echo '<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><script type="text/javascript">alert("' . $msg . '");	window.location.href="/pages/home"</script>';
     die;
 }
<?php

session_start();
if (isset($_SESSION['last_key'])) {
    $isLogin = "******";
} else {
    header('Location: index.php');
}
include_once 'config.php';
include_once 'weibooauth.php';
// 获取新浪微博账号信息
$c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
$msg = $c->verify_credentials();
if ($msg === false || $msg === null) {
    echo "Error occured";
    return false;
}
if (isset($msg['error_code']) && isset($msg['error'])) {
    echo 'Error_code: ' . $msg['error_code'] . ';  Error: ' . $msg['error'];
    return false;
}
//if (isset($msg['name'])){
//	echo($msg['name']);
//}
$SendToWeibo = new SaeTClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
?>



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
<html xmlns=" http://www.w3.org/1999/xhtml">
<?php

session_start();
if (isset($_SESSION['last_key'])) {
    $isLogin = "******";
} else {
    header('Location: index.php');
}
include_once 'config.php';
include_once 'weibooauth.php';
//include_once( 'saet.ex.class.php' );
// 获取新浪微博账号信息
$c = new WeiboClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
$msg = $c->verify_credentials();
if ($msg === false || $msg === null) {
    echo "Error occured";
    return false;
}
if (isset($msg['error_code']) && isset($msg['error'])) {
    echo 'Error_code: ' . $msg['error_code'] . ';  Error: ' . $msg['error'];
    return false;
}
//if (isset($msg['name'])){
//	echo($msg['name']);
//}
$SendToWeibo = new SaeTClient(WB_AKEY, WB_SKEY, $_SESSION['last_key']['oauth_token'], $_SESSION['last_key']['oauth_token_secret']);
?>