【PHP】【Too few arguments to function Firebase\JWT\JWT::encode()。。。。。。。】

编程入门 行业动态 更新时间:2024-10-26 22:29:34

【PHP】【Too few arguments to <a href=https://www.elefans.com/category/jswz/34/1771284.html style=function Firebase\JWT\JWT::encode()。。。。。。。】"/>

【PHP】【Too few arguments to function Firebase\JWT\JWT::encode()。。。。。。。】

1.安装jwt

composer require firebase/php-jwt
use Firebase\JWT\JWT;public function hello($name = 'ThinkPHP5'){$secret_key = "YOUR_SECRET_KEY";$issuer_claim = "THE_ISSUER";$audience_claim = "THE_AUDIENCE";$issuedat_claim = time(); // issued at$notbefore_claim = $issuedat_claim + 10; //not before in seconds$expire_claim = $issuedat_claim + 60; // expire time in seconds$token = array("iss" => $issuer_claim,"aud" => $audience_claim,"iat" => $issuedat_claim,"nbf" => $notbefore_claim,"exp" => $expire_claim,"data" => array("user_id" => "1","user_name" => "John Doe",));$jwt = JWT::encode($token, $secret_key);echo $jwt;// return 'hello,' . $name;}

上面的

$jwt = JWT::encode($token, $secret_key);

改为

 $jwt = JWT::encode($token, $secret_key, "HS256");

2.jwt解析(“firebase/php-jwt”: “^6.4” 的版本)

use Firebase\JWT\JWT;
use Firebase\JWT\Key;$jwt = JWT::encode($payload, $key, 'HS256');
//解析
$decoded = JWT::decode($jwt, new Key($key, 'HS256'));

更多推荐

【PHP】【Too few arguments to function Firebase\JWT\JWT::encode()。。。。。。。】

本文发布于:2023-11-16 09:41:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616704.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:function   arguments   PHP   encode   JWT

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!