PHP code example of bonza / jwt

1. Go to this page and download the library: Download bonza/jwt library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bonza / jwt example snippets


$header = [
    'alg' => 'sha256',//算法
    'typ' => 'JWT',
];
$payload = [
    "iss" => "https://example.cn",//issuer 签发人
    "aud" => "https://example.cn",//audience 受众
    "iat" => time(),//Issued At 签发时间
    "sub" => 'self sign',//subject 主题
    "nbf" => time(),//Not Before 生效时间
    "exp" => time()+3600,//过期时间
    "jti" => 'exp'.date('YmdHis').random_int(1000,9999),//JWT ID
];

$key = 'jwt-key';

$token = JWTHash256::encode($header,$payload,$key);