久久久久久久视色,久久电影免费精品,中文亚洲欧美乱码在线观看,在线免费播放AV片

<center id="vfaef"><input id="vfaef"><table id="vfaef"></table></input></center>

    <p id="vfaef"><kbd id="vfaef"></kbd></p>

    
    
    <pre id="vfaef"><u id="vfaef"></u></pre>

      <thead id="vfaef"><input id="vfaef"></input></thead>

    1. 站長(zhǎng)資訊網(wǎng)
      最全最豐富的資訊網(wǎng)站

      Laravel利用pusher推送消息的方法詳解

      Laravel利用pusher推送消息的方法詳解

      一.注冊(cè)pusher

      1.注冊(cè)

      https://pusher.com/

      2.獲取key,密匙,app_id等

      二.配置pusher

      1.安裝pusher

      composer require pusher/pusher-php-server

      2.配置config/broadcasting.php

      'default' => env('BROADCAST_DRIVER', 'pusher'), .... 'pusher' => [             'driver' => 'pusher',             'key' => env('PUSHER_KEY'),             'secret' => env('PUSHER_SECRET'),             'app_id' => env('PUSHER_APP_ID'),             'options' => [                 'cluster' => 'ap1',                 'encrypted' => true             ],         ], .....

      三.建立事件

      1.代碼如下:

      <?php   namespace AppEvents;   use AppEventsEvent; use IlluminateQueueSerializesModels; use IlluminateContractsBroadcastingShouldBroadcast;   class PusherEvent extends Event implements ShouldBroadcast {     use SerializesModels;       public $info;       /**      * PusherEvent constructor.      */     public function __construct($info)     {         $this->info = $info;     }       /**      * 指定廣播頻道(對(duì)應(yīng)前端的頻道)      * Get the channels the event should be broadcast on.      *      * @return array      */     public function broadcastOn()     {         return ['my-channel'];     }       /**      * 指定廣播事件(對(duì)應(yīng)前端的事件)      * @return string      */     public function broadcastAs()     {         return 'my-event';     }       /**      * 獲取廣播數(shù)據(jù),默認(rèn)是廣播的public屬性的數(shù)據(jù)      */     public function broadcastWith()     {         return ['info' => $this->info];     } }

      2.廣播事件,并不需要監(jiān)聽(tīng)器;廣播事件需要繼承接口ShouldBroadcast

      四.廣播

      1.觸發(fā)事件

      event(new AppEventsPusherEvent('測(cè)試'));

      2.前端代碼

      <!DOCTYPE html> <head>   <title>Pusher Test</title>   <script src="https://js.pusher.com/4.0/pusher.min.js"></script>   <script>       // Enable pusher logging - don't include this in production     Pusher.logToConsole = true;       var pusher = new Pusher('XXX', {       cluster: 'ap1',       encrypted: true     });       var channel = pusher.subscribe('my-channel');     channel.bind('my-event', function(data) {       alert(data.info);     });   </script> </head>

      ps:

      1.pusher使用curl向https://pusher.com提交數(shù)據(jù),所以你需要配置證書(shū);否則提交會(huì)失敗

      2.如果不配置證書(shū),則需要設(shè)置curl的CURLOPT_SSL_VERIFYPEERCURLOPT_SSL_VERIFYHOST

      vender/pusher/pusher-php-server/lib/Pusher.php中的trigger的

      curl_setopt($ch, CURLOPT_POSTFIELDS, $post_value);

      下面增加:

      curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

      贊(0)
      分享到: 更多 (0)
      ?
      網(wǎng)站地圖   滬ICP備18035694號(hào)-2    滬公網(wǎng)安備31011702889846號(hào)