Exemple #1
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('验证失败,请检查用户名或者密码是否正确。并返回重新验证!');
     }
 }
Exemple #2
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);
     }
 }