<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>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                閉包請求看守器 實現基于 HTTP 請求的自定義身份驗證系統的最簡單方法是使用 Auth::viaRequest 方法。此方法允許你使用單個閉包快速定義身份驗證過程。 首先,請在 AuthServiceProvider 的 boot 方法中調用 Auth::viaRequest 方法。 VIASRequest 方法接受身份驗證驅動程序名稱作為其第一個參數。此名稱可以是描述你的自定義看守器的任何字符串。傳遞給方法的第二個參數應該是一個閉包,該閉包接收傳入的 HTTP 請求并返回用戶實例,或者,如果身份驗證失敗返回 null: ~~~ <?php namespace App\Providers; use App\Models\MemberList; use DragonCode\Support\Facades\Helpers\Str; use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class AuthServiceProvider extends ServiceProvider { /** * The model to policy mappings for the application. * * @var array<class-string, class-string> */ protected $policies = [ // ]; /** * Register any authentication / authorization services. */ public function boot(): void{ Auth::viaRequest('token', function (Request $request) { //客戶端發送的token if (!$request->hasHeader('Authorization') || empty($request->header('Authorization'))){ return null; }/*end if*/ $decoder = api_token_decoder(trim($request->header('Authorization'))); if (empty($decoder)){ return null; } if (!preg_match("/^([1|2]\d{6,8})(_)(\d{1,3})$/",$decoder, $decoder_array)){ return null; }/*end if*/ if (!isset($decoder_array[1]) || !isset($decoder_array[3]) || !is_numeric($decoder_array[1])){ return null; }/*end if*/ $user_id = (int) $decoder_array[1]; /*用戶ID*/ $encrypt = $decoder_array[3]; /*用戶在線密鑰*/ $member_info = MemberList::find($user_id); if (empty($member_info)){ return null; }/*end if*/ if ($member_info->encrypt != $encrypt){ return null; }/*end if*/ return $member_info; }); } } ~~~ 定義自定義身份驗證驅動程序后,你可以將其配置為`auth.php`配置文件的`guards`配置中的驅動程序: ~~~ 'guards' => [ 'web' => [ 'driver' => 'session', 'provider' => 'users', ], 'api' => [ 'driver' => 'token', 'provider' => 'users', ], ], ~~~ ### 報錯狀態 ~~~ <?php namespace App\Http\Middleware; use App\Exceptions\ApiException; use Illuminate\Auth\Middleware\Authenticate as Middleware; use Illuminate\Http\Request; class Authenticate extends Middleware { /** * Get the path the user should be redirected to when they are not authenticated. */ protected function redirectTo(Request $request): ?string{ if ($request->expectsJson()){ throw new ApiException('????????? ????? ?????? ???????? ?????!', 401); } abort(404); } protected function unauthenticated($request, array $guards) { $this->redirectTo($request); } } ~~~ ~~~ /*************************************************** 以下需要token *******************************************************************/ Route::middleware(['auth:api'])->group(function (){ } ~~~
                  <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>

                              哎呀哎呀视频在线观看