重写后的标题为:keyOrKeyArray必须是Firebase\\JWT\\Key键的实例或Firebase\\JWT\\Key键的数组,在php ci4中
P粉680000555
P粉680000555 2023-11-07 16:57:25
0
1
559

{ "title": "UnexpectedValueException", "type": "UnexpectedValueException", “代码”:500, "message": "$keyOrKeyArray 必须是 FirebaseJWTKey 键的实例或 FirebaseJWTKey 键的数组", "文件": "E:varwwwhtmlprojectspansadminvendorfirebasephp-jwtsrcJWT.php", “行”:416,

P粉680000555
P粉680000555

全部回复(1)
P粉914731066

您可以使用下面的示例代码 -

<?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);
    }
}

如果您在上面运行,那么您将得到以下响应 -

{
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyaWQiOiJUZXN0X1VJRCIsIm5hbWUiOiJTYW5raG5hZCBNaXNocmEiLCJpYXQiOjE2NDU4MTU0OTUsImV4cCI6MTY0NTgxNTU1NX0.0CwT9quW8-teyob3ObRU5KQBfQYWamCSTVCrAk9UX-o",
    "decodedToken": {
        "userid": "Test_UID",
        "name": "Sankhnad Mishra",
        "iat": 1645815495,
        "exp": 1645815555
    }
}

因此,只需根据您的要求从上面选择这些代码即可。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板