generateSign() public static method

Generate the signature for passed parameters.
public static generateSign ( array $params, string $secret, string $namespace = 'sign' ) : string
$params array Array of parameters to be signatured
$secret string Secret key for signature
$namespace string The parameter which will be excluded when calculate the signature
return string Signature of the parameters
コード例 #1
0
ファイル: Baidu.php プロジェクト: naliduo/ThinkSNS
 /**
  * Get currently logged in user's uid.
  * 
  * @return uint|false Return uid of the loggedin user, or return
  * false if user isn't loggedin.
  */
 public function getLoggedInUser()
 {
     // Get user from cached data or from access token
     $user = $this->getUser();
     // If there's bd_sig & bd_user parameter in query parameters,
     // it must be an inside web app(app on baidu) loading request,
     // then we must check whether the uid passed from baidu is the
     // same as we get from persistent data or from access token,
     // if it's not, we should clear all the persistent data and to
     // get an access token again.
     if (isset($_REQUEST['bd_sig']) && isset($_REQUEST['bd_user'])) {
         $params = array('bd_user' => $_REQUEST['bd_user']);
         $sig = BaiduUtils::generateSign($params, $this->clientSecret, 'bd_sig');
         if ($sig != $_REQUEST['bd_sig'] || $user['uid'] != $_REQUEST['bd_user']) {
             $this->store->remove('session');
             return false;
         }
     }
     return $user;
 }