<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                1.安裝jwt: ~~~ Lcobucci\\JWT暫不能使用,故先使用firebase/php-jwt composer require firebase/php-jwt ~~~ 2.小知識 (1)api服務器的時間與業務系統所在的機器時間有些小偏差 第一種:把兩個服務器的時間同步成一致的 第二種:查看php-jwt的源碼提供了一個靜態變量$leeway,我們可以在解簽前JWT::$leeway+=15;解決問題 3.建立類庫 ~~~ <?php /** * Created by PhpStorm. * User: Administrator * Date: 2020/12/28 * Time: 16:58 */ namespace lib; use Firebase\JWT\JWT; class Jwt2{ public function access_token(){ $access= config('jwt.access'); $key=config('jwt.jti'); $token=JWT::encode($access,$key); return $token; } public function refresh_token(){ $access= config('jwt.refresh'); $key=config('jwt.jti'); $token=JWT::encode($access,$key); return $token; } public function verily_token($token,$type='role_access'){ $key=config('jwt.jti');//key要和簽發的時候一樣 try { // JWT::$leeway = 60;//當前時間減去60,把時間留點余地 $decoded = JWT::decode($token, $key, ['HS256']); //HS256方式,這里要和簽發的時候對應 $arr = (array)$decoded; if($arr['scopes']!==$type){ return 'token類型錯誤'; } return true; } catch(\Firebase\JWT\SignatureInvalidException $e) { //簽名不正確 return $e->getMessage(); }catch(\Firebase\JWT\BeforeValidException $e) { // 簽名在某個時間點之后才能用 return $e->getMessage(); }catch(\Firebase\JWT\ExpiredException $e) { // token過期 return $e->getMessage(); }catch(Exception $e) { //其他錯誤 return $e->getMessage(); } } } ~~~ 4.調用 ~~~ public function get_token(){ $jwt=new Jwt2(); $token['access_token']=$jwt->access_token(); $token['refresh_token']=$jwt->refresh_token(); Header("HTTP/1.1 201 Created"); return json($token); } public function check_token(){ $token=input('token'); $jwt=new Jwt2(); $check=$jwt->verily_token($token); var_dump($check); } public function new_token(){ $token=input('token'); $jwt=new Jwt2(); $check=$jwt->verily_token($token,'refresh_access'); if($check){ $jwt=new Jwt2(); $access_token=$jwt->access_token(); return $access_token; }else{ return $check; } } ~~~ 5.配置文件 ~~~ <?php /** * Created by PhpStorm. * User: Administrator * Date: 2020/12/29 * Time: 10:54 */ return [ "access"=>[ "iss"=>"http://tp6.xian666.cn", //jwt簽發者 "aud"=>"http://tp6.xian666.cn", //接收jwt的一方 "exp"=>time()+3600*2,// jwt的過期時間,過期時間必須要大于簽發時間 "iat"=>time(),// jwt的簽發時間 "nbf"=>time(),// 定義在什么時間之前,某個時間點后才能訪問 "scopes"=>"role_access"//token標識,請求接口的token //"sub"=>'', jwt所面向的用戶 ], "refresh"=>[ "iss"=>"http://tp6.xian666.cn", //jwt簽發者 "aud"=>"http://tp6.xian666.cn", //接收jwt的一方 "exp"=>time()+3600*24*7,// jwt的過期時間,過期時間必須要大于簽發時間 "iat"=>time(),// jwt的簽發時間 "nbf"=>time()+3600,// 定義在什么時間之前,某個時間點后才能訪問 "scopes"=>"refresh_access"//token標識,請求接口的token //"sub"=>'', jwt所面向的用戶 ], "jti"=>"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9",// jwt的唯一身份標識,主要用來作為一次性token。 ]; ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看