获取的token。
下载jwt插件.
composer require lcobucci/jwt
然后降级:不然不能使用。
composer require lcobucci/jwt=3.3.3
<?php
return [
'ALI_APPID'=>'',
'ALI_APPSECRET'=>'',
'ALI_SNAME'=>'',
'ALI_TCODE'=>'',
'API_KEY' =>'',
'API_HOST'=>'http://www.lampol.vip'
];
//下面的代码是获取token的代码.
function getToken($mobile){
//注意;common.php文件没有user概念
$signer = new Lcobucci\JWT\Signer\Hmac\Sha256();//加密算法
$time = time();
$key = new Lcobucci\JWT\Signer\Key(config('shop.API_KEY'));
$token = (new Lcobucci\JWT\Builder())->issuedBy('http://www.lampol.vip')
->identifiedBy('4f1g23a12aa', true)//身份验证
->issuedAt($time)//签发时间
->expiresAt($time + 60)//(这里才是对的!)过期时间,也就是说这个token什么时候会失效。当前时间+60秒后会失效
->withClaim('mobile', $mobile)
->getToken($signer, $key);//配置项
return $token;//返回token
}
public function token(){
$token = getToken('15588608866');
dump($token);//jwt对象。里面header数组里面有token
dump((string)$token);//token
}