<?php
namespace App\Controllers;
use App\Controllers\BaseController;
use Firebase\JWT\JWT;
use Firebase\JWT\Key;
class User extends BaseController
{
public function exampleMethod()
{
$issuedAt = time();
$expirationTime = $issuedAt + 60; // jwt valid for 60 seconds from the issued time
$payload = array( // Any random data
'userid' => 'Test_UID',
'name' => 'Sankhnad Mishra',
'iat' => $issuedAt,
'exp' => $expirationTime
);
$key = 'A_JWT_SECRET'; // Any string
$alg = 'HS256'; // This is alg
$token = JWT::encode($payload, $key, $alg); // Encode payload as a JWT Token
$decodedToken = JWT::decode($token, new Key($key, 'HS256')); // Decode token to a payload
$response = [
'token' => $token,
'decodedToken' => $decodedToken
];
print_r($response);
}
}
您可以使用下面的示例代码 -
如果您在上面运行,那么您将得到以下响应 -
因此,只需根据您的要求从上面选择这些代码即可。