首先,下载jwt的扩展
composer require lcobucci/jwt 3.3
一: 创建封装生成token的类
php artisan make:controller Api/TokenController
二 : 生成token
需要调用
use Lcobucci\JWT\Builder;
use Lcobucci\JWT\Signer\Hmac\Sha256;
use Lcobucci\JWT\Parser;
use Lcobucci\JWT\ValidationData;
//生成token
static public function createToken($uid=null){
$signer = new Sha256();//加密规则
$time = time();//当前时间
$token = (new Builder())
->issuedBy('teacher')//签发人
->canOnlyBeUsedBy