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

                ??碼云GVP開源項目 12k star Uniapp+ElementUI 功能強大 支持多語言、二開方便! 廣告
                #### laravel-websockets 替代pusher 發送頻道消息 > https://beyondco.de/docs/laravel-websockets/basic-usage/pusher 首先按照文檔安裝好laravel-websocket,然后設置好替換puhser的配置即可。 其中自帶的接口是 `broadcasting/auth` > app\Providers\BroadcastServiceProvider.php ~~~ use Illuminate\Support\Facades\Broadcast; /** * Bootstrap any application services. * * @return void */ public function boot() { // 自己定義路由中間件 Broadcast::routes(['prefix'=>'api','middleware' => 'auth:api']); require base_path('routes/channels.php'); } ~~~ 這樣配置后默認的地址便是 `域名+api/broadcasting/auth` 其中auth使用的是jwt擴展 `composer require tymon/jwt-auth` 參數 :header頭需要加上 token | 參數名 | 值| | --- | --- | | channel_name | public_channle | | socket_id| 98834966.500888313| 加上token一個三個參數,訪問即可得到一個auth:簽名秘鑰 > {"auth":簽名秘鑰} 有了這個auth便可去訂閱那些需要登錄的頻道。前端使用laravel-echo 其中發送消息需要創建 event ~~~ namespace App\Events; use Illuminate\Broadcasting\Channel; use Illuminate\Broadcasting\InteractsWithSockets; use Illuminate\Broadcasting\PresenceChannel; use Illuminate\Broadcasting\PrivateChannel; use Illuminate\Contracts\Broadcasting\ShouldBroadcast; use Illuminate\Contracts\Broadcasting\ShouldBroadcastNow; use Illuminate\Foundation\Events\Dispatchable; use Illuminate\Queue\SerializesModels; use App\Models\User\User; class PublicMessages implements ShouldBroadcast { use Dispatchable, InteractsWithSockets, SerializesModels; public $message; // 消息 public function __construct( $message ) { $this->message = $message; } /** * 隊列名 * @return string */ public function broadcastQueue() { return 'message'; } /** * The event's broadcast name. * 一般都是配置的redis ,不是sync sync便是立即發送。redis使用隊列,在這里可以指定隊列名稱 * 需要開啟消費隊列,這樣才能收到消息 * @return string */ public function broadcastAs() { return 'message'; } public function broadcastOn() { return new Channel('public'); } /** * 用于擴展字段的 * Get the data to broadcast. * * @return array */ public function broadcastWith() { return [ 'message' => $this->message, ]; } } ~~~ #### 路由設置 ~~~ / 公共頻道 Broadcast::channel('public', function ($user) { // 公共頻道直接返回true即可 return true; }); ~~~ ~~~ // 用戶私有頻道 Broadcast::channel('private.{userId}', function ($user, $userId) { 因為加了登錄驗證的jwt,的中間件,他會去解析出用戶信息,賦給$user 這里第一個參數都是 $user實例對象,后面參數就是對應自己設置的{userId},在此對比是否一致,就能判斷是否是本人。詳情就看laravel廣播那一節手冊 return (int)$user->id === (int)$userId; }); ~~~ #### 發送消息 ~~~ broadcast(new PublicMessages('this is a messgae')); ~~~ 上面代碼是關于公共頻道的,私有頻道自己加上用戶參數即可 #### 廣播配置文件配置 config/broadcasting.php 如下 ~~~ 'connections' => [ 'pusher' => [ 'driver' => 'pusher', 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'app_id' => env('PUSHER_APP_ID'), 'options' => [ 'cluster' => env('PUSHER_APP_CLUSTER'), 'encrypted' => true, 'host' => '127.0.0.1', 'port' => 6001, 'scheme' => 'http' ], ] ], ~~~ #### config/websockets.php文件配置如下 ~~~ 'apps' => [ [ 'id' => env('PUSHER_APP_ID'), 'name' => env('APP_NAME'), 'key' => env('PUSHER_APP_KEY'), 'secret' => env('PUSHER_APP_SECRET'), 'enable_client_messages' => false, 'enable_statistics' => true, ] ], ~~~ #### .env中配置如下 > BROADCAST_DRIVER=pusher PUSHER_APP_ID=配置id PUSHER_APP_KEY=配置key PUSHER_APP_SECRET=配置秘鑰 #其中的id、key、secret 根據項目需求隨意配置即可,因為是用的websockets替代了pusher,如果是用的pusher提供原服務需要去pusher官網申請其中的id、key、secret 配置即可
                  <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>

                              哎呀哎呀视频在线观看