1.在相关项目中下载部署php-jwt(下载地址:https://github.com/firebase/php-jwt)
自行封装加密解密方法:
//jwt加密
function jwtEncode($jmData=array()){
if (!is_array($jmData)) return array();
$jwtkey='df13Dtgdf#¥%3454Unv56';
include_once WEB_ROOT.'/packages/php-jwt/JWT.php';
$jwt = new Firebase\JWT\JWT();
$token = $jwt::encode($jmData, $jwtkey, 'HS256');
return $token;
}
//jwt解密
function jwtdecode($token){
$jwtkey='df13Dtgdf#¥%3454Unv56';
include_once WEB_ROOT.'/packages/php-jwt/JWT.php';
$jwt = new Firebase\JWT\JWT();
try{
$decoded = $jwt::decode($token, $jwtkey, array('HS256'));
$decodedArr = (array) $decoded;
return $decodedArr;
} catch (Exception $e) {