作者 lyh

gx

@@ -3,34 +3,23 @@ @@ -3,34 +3,23 @@
3 namespace App\Events; 3 namespace App\Events;
4 4
5 use Illuminate\Broadcasting\Channel; 5 use Illuminate\Broadcasting\Channel;
6 -use Illuminate\Broadcasting\InteractsWithSockets;  
7 -use Illuminate\Broadcasting\PresenceChannel;  
8 -use Illuminate\Broadcasting\PrivateChannel;  
9 use Illuminate\Contracts\Broadcasting\ShouldBroadcast; 6 use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
10 use Illuminate\Foundation\Events\Dispatchable; 7 use Illuminate\Foundation\Events\Dispatchable;
11 use Illuminate\Queue\SerializesModels; 8 use Illuminate\Queue\SerializesModels;
12 9
13 -class WebSocketMessageSent 10 +class WebSocketMessageSent implements ShouldBroadcast
14 { 11 {
15 - use Dispatchable, InteractsWithSockets, SerializesModels; 12 + use Dispatchable, SerializesModels;
16 13
17 - /**  
18 - * Create a new event instance.  
19 - *  
20 - * @return void  
21 - */  
22 - public function __construct() 14 + public $message;
  15 +
  16 + public function __construct($message)
23 { 17 {
24 - // 18 + $this->message = $message;
25 } 19 }
26 20
27 - /**  
28 - * Get the channels the event should broadcast on.  
29 - *  
30 - * @return \Illuminate\Broadcasting\Channel|array  
31 - */  
32 public function broadcastOn() 21 public function broadcastOn()
33 { 22 {
34 - return new PrivateChannel('channel-name'); 23 + return new Channel('websocket-channel');
35 } 24 }
36 } 25 }
@@ -10,6 +10,7 @@ @@ -10,6 +10,7 @@
10 namespace App\Http\Controllers\Bside; 10 namespace App\Http\Controllers\Bside;
11 11
12 use App\Enums\Common\Code; 12 use App\Enums\Common\Code;
  13 +use App\Events\WebSocketMessageSent;
13 use App\Helper\Common; 14 use App\Helper\Common;
14 use App\Helper\Translate; 15 use App\Helper\Translate;
15 use App\Helper\Wechat; 16 use App\Helper\Wechat;
@@ -18,6 +19,7 @@ use App\Models\Service\Service; @@ -18,6 +19,7 @@ use App\Models\Service\Service;
18 use App\Models\Sms\SmsLog; 19 use App\Models\Sms\SmsLog;
19 use App\Models\User\User as UserModel; 20 use App\Models\User\User as UserModel;
20 use App\Utils\EncryptUtils; 21 use App\Utils\EncryptUtils;
  22 +use BeyondCode\LaravelWebSockets\Dashboard\Http\Controllers\SendMessage;
21 use \Illuminate\Support\Facades\Cache; 23 use \Illuminate\Support\Facades\Cache;
22 use Mrgoon\AliSms\AliSms; 24 use Mrgoon\AliSms\AliSms;
23 25
@@ -144,6 +146,7 @@ class LoginController extends BaseController @@ -144,6 +146,7 @@ class LoginController extends BaseController
144 $message = file_get_contents("php://input"); 146 $message = file_get_contents("php://input");
145 $message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR); 147 $message = simplexml_load_string($message, 'SimpleXMLElement', LIBXML_NOCDATA | LIBXML_NOERROR);
146 @file_put_contents(storage_path('logs/lyh_error.log'), $message . PHP_EOL, FILE_APPEND); 148 @file_put_contents(storage_path('logs/lyh_error.log'), $message . PHP_EOL, FILE_APPEND);
  149 + event(new WebSocketMessageSent('New message from server'));
147 $this->response('success'); 150 $this->response('success');
148 } 151 }
149 152