get() abstract public method

Get the variable value specified by the variable key name for current session user from the storage system.
abstract public get ( string $key, mix $default = false ) : mix
$key string Variable key name
$default mix Default value if the key couldn't be found
return mix Returns the value for the specified key if it exists, otherwise return $default value
コード例 #1
0
ファイル: Baidu.php プロジェクト: js-wei/BaiduOpenid
 /**
  * [getUserInfo 获取用户信息]
  * @return [type] [description]
  */
 public function getUserInfo()
 {
     // get authorization code from query parameters
     $code = $this->getCode();
     // check whether it is a CSRF attack request
     if ($code && $code != $this->store->get('code')) {
         p(1);
         die;
         $oauth2 = $this->getBaiduOAuth2Service();
         $session = $oauth2->getAccessTokenByAuthorizationCode($code);
         if ($session) {
             $this->store->set('code', $code);
             $this->setSession($session);
             $apiClient = new BaiduApiClient($this->clientId, $session['access_token']);
             $user = $apiClient->api('passport/users/getInfo');
             if ($user) {
                 $session = array_merge($session, $user);
                 $this->setSession($session);
             }
             return $session;
         }
         $this->store->removeAll();
         return false;
     }
     // as a fallback, just return whatever is in the storage
     $session = $this->store->get('session');
     $this->setSession($session);
     if ($session) {
         $apiClient = new BaiduApiClient($this->clientId, $session['access_token']);
         $user = $apiClient->api('passport/users/getInfo');
         $user['sex'] = $user['sex'] == 1 ? '男' : '女';
         $user['nikename'] = $user['username'];
         $user['head'] = 'http://tb.himg.baidu.com/sys/portraitn/item/' . $user['portrait'];
         // if ($user) {
         // 	$session = array_merge($session,$user);
         // 	$this->setSession($session);
         // }
     }
     return $user;
 }
コード例 #2
0
ファイル: Baidu.php プロジェクト: naliduo/ThinkSNS
 /**
  * Get session info from Baidu server or from the store in app server side.
  * 
  * @return array|false
  */
 protected function doGetSession()
 {
     // get authorization code from query parameters
     $code = $this->getCode();
     // check whether it is a CSRF attack request
     if ($code && $code != $this->store->get('code')) {
         $oauth2 = $this->getBaiduOAuth2Service();
         $session = $oauth2->getAccessTokenByAuthorizationCode($code);
         if ($session) {
             $this->store->set('code', $code);
             $this->setSession($session);
             $apiClient = new BaiduApiClient($this->clientId, $session['access_token']);
             $user = $apiClient->api('passport/users/getLoggedInUser');
             if ($user) {
                 $session = array_merge($session, $user);
                 $this->setSession($session);
             }
             return $session;
         }
         // code was bogus, so everything based on it should be invalidated.
         $this->store->removeAll();
         return false;
     }
     // as a fallback, just return whatever is in the storage
     $session = $this->store->get('session');
     $this->setSession($session);
     if ($session && !isset($session['uid'])) {
         $apiClient = new BaiduApiClient($this->clientId, $session['access_token']);
         $user = $apiClient->api('passport/users/getLoggedInUser');
         if ($user) {
             $session = array_merge($session, $user);
             $this->setSession($session);
         }
     }
     return $session;
 }