Exemplo n.º 1
0
 public static function tokenString($userId, $departmentId, $groupId, $created)
 {
     $tokenString = array();
     $tokenString['userId'] = $userId;
     $tokenString['departmentId'] = $departmentId;
     $tokenString['groupId'] = $groupId;
     $tokenString['created'] = $created;
     return strToHex(\Think\Crypt\Driver\Base64::encrypt(json_encode($tokenString), 'easonchan'));
 }
Exemplo n.º 2
0
 public static function verifyToken($token)
 {
     $tokenString = hexToStr($token);
     $jsonData = \Think\Crypt\Driver\Base64::decrypt($tokenString, 'easonchan');
     $array = json_decode($jsonData, true);
     if ($array == null) {
         return false;
     }
     $created = $array['created'];
     $expire = BoxTokenHelper::$expire;
     $now = time();
     if ($created + $expire < $now) {
         return false;
     }
     $info = new TokenInfo($array['userId'], $array['departmentId'], $array['groupId'], $array['created']);
     $array['created'] = time();
     $tokenString = strToHex(\Think\Crypt\Driver\Base64::encrypt(json_encode($array), 'easonchan'));
     return array('str' => $tokenString, 'info' => $info);
 }