| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- /**
- * User: shish
- * Date: 2019/11/20
- * Time: 23:21
- */
- namespace common\components;
- use Lcobucci\JWT\Builder;
- use Lcobucci\JWT\Signer\Hmac\Sha256;
- use Lcobucci\JWT\Parser;
- use Lcobucci\JWT\ValidationData;
- use Yii;
- class token
- {
- public static function create($uid)
- {
- // $host = Yii::$app->request->getHostInfo();
- // $time = time();
- // $token = (new Builder())->issuedBy($host) // Configures the issuer (iss claim)
- // ->permittedFor($host) // Configures the audience (aud claim)
- // ->identifiedBy('5f1g23a12awP1', true) // Configures the id (jti claim), replicating as a header item
- // ->issuedAt($time) // Configures the time that the token was issue (iat claim)
- // ->canOnlyBeUsedAfter($time + 60) // Configures the time that the token can be used (nbf claim)
- // ->expiresAt($time + 3600) // Configures the expiration time of the token (exp claim)
- // ->withClaim('uid', $uid) // Configures a new claim, called "uid"
- // ->getToken(); // Retrieves the generated token
- // return $token;
- }
- public static function validate($token)
- {
- // $token = (new Parser())->parse((string)$token);
- // $signer = Sha256();
- // //签名不正确
- // if (!$token->verify($signer, '2019.1964')) {
- // return false;
- // }
- // $host = Yii::$app->request->getHostInfo();
- // $validationData = new ValidationData();
- // $validationData->setIssuer($host);
- // $validationData->setAudience($host);
- // $validationData->setId('sxs-4f1g23a12aa');//自字义标识
- //
- // return $token->validate($validationData);
- }
- }
|